Spaces:
Sleeping
Sleeping
Update clients.py
Browse files- clients.py +30 -0
clients.py
CHANGED
@@ -10,6 +10,35 @@ import streamlit as st
|
|
10 |
import pandas as pd
|
11 |
import requests
|
12 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
|
15 |
host=os.getenv("backend")
|
@@ -92,6 +121,7 @@ def CompanySpecificClient(email_receiver):
|
|
92 |
df = df.dropna().loc[~(df == '').all(axis=1)]
|
93 |
|
94 |
df = df.dropna().loc[~(df == '').all(axis=1)]
|
|
|
95 |
st.write(df)
|
96 |
# Convert DataFrame to CSV for transmission
|
97 |
csv = df.to_csv(index=False)
|
|
|
10 |
import pandas as pd
|
11 |
import requests
|
12 |
import os
|
13 |
+
import pandas as pd
|
14 |
+
|
15 |
+
def add_https_to_urls(df, column_name):
|
16 |
+
"""
|
17 |
+
Adds 'https://' to URLs in the specified column of a DataFrame if they don't already start with a valid protocol.
|
18 |
+
Corrects URLs starting with 'http:/' or 'https:/'.
|
19 |
+
Handles missing values, trims whitespace, and is case-insensitive.
|
20 |
+
|
21 |
+
Parameters:
|
22 |
+
df (pandas.DataFrame): The DataFrame containing the URLs.
|
23 |
+
column_name (str): The name of the column with URLs.
|
24 |
+
"""
|
25 |
+
# Define a helper function to add or correct protocols
|
26 |
+
def correct_protocol(url):
|
27 |
+
if pd.isna(url) or url.strip() == '':
|
28 |
+
return url # Return as is if the URL is NaN or empty
|
29 |
+
url = url.strip() # Trim whitespace
|
30 |
+
lower_url = url.lower()
|
31 |
+
if lower_url.startswith('http:/') and not lower_url.startswith('http://'):
|
32 |
+
return 'http://' + url[6:]
|
33 |
+
elif lower_url.startswith('https:/') and not lower_url.startswith('https://'):
|
34 |
+
return 'https://' + url[7:]
|
35 |
+
elif not lower_url.startswith(('http://', 'https://')):
|
36 |
+
return 'https://' + url
|
37 |
+
return url
|
38 |
+
|
39 |
+
# Apply the helper function to the specified column
|
40 |
+
df[column_name] = df[column_name].apply(correct_protocol)
|
41 |
+
return df
|
42 |
|
43 |
|
44 |
host=os.getenv("backend")
|
|
|
121 |
df = df.dropna().loc[~(df == '').all(axis=1)]
|
122 |
|
123 |
df = df.dropna().loc[~(df == '').all(axis=1)]
|
124 |
+
df=add_https_to_urls(df, 'Website')
|
125 |
st.write(df)
|
126 |
# Convert DataFrame to CSV for transmission
|
127 |
csv = df.to_csv(index=False)
|