Spaces:
Sleeping
Sleeping
Tobaisfire
commited on
Commit
•
4510d1f
1
Parent(s):
534b95c
All done
Browse files- .gitattributes +1 -0
- chromedriver.exe +3 -0
- coor.py +139 -0
- requirements.txt +3 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
chromedriver.exe filter=lfs diff=lfs merge=lfs -text
|
chromedriver.exe
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f1abea20acda7d68184003a299f7840caa68f8d81842677c047b1947df708ae8
|
3 |
+
size 16863232
|
coor.py
ADDED
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
from seleniumwire import webdriver
|
4 |
+
from selenium.webdriver.common.by import By
|
5 |
+
from selenium.webdriver.chrome.service import Service
|
6 |
+
import time
|
7 |
+
import shutil
|
8 |
+
|
9 |
+
chrome_options = webdriver.ChromeOptions()
|
10 |
+
chrome_options.add_argument('--headless')
|
11 |
+
chrome_options.add_argument('--disable-gpu')
|
12 |
+
chrome_options.add_argument('--no-sandbox')
|
13 |
+
chrome_options.add_argument('--ignore-certificate-errors-spki-list')
|
14 |
+
chrome_options.add_argument('--ignore-ssl-errors')
|
15 |
+
chrome_options.add_argument('log-level=3')
|
16 |
+
|
17 |
+
# CHROMEDRIVER_PATH = 'chromedriver.exe'
|
18 |
+
|
19 |
+
def get_chromedriver_path():
|
20 |
+
return shutil.which('chromedriver')
|
21 |
+
|
22 |
+
|
23 |
+
service = Service(executable_path=get_chromedriver_path())
|
24 |
+
|
25 |
+
driver = webdriver.Chrome(service=service, options=chrome_options)
|
26 |
+
def get_address(search_term):
|
27 |
+
lat, lon = [], []
|
28 |
+
try:
|
29 |
+
print('HIT.......')
|
30 |
+
driver.get("https://www.google.com/maps")
|
31 |
+
time.sleep(3)
|
32 |
+
|
33 |
+
driver.find_element(By.ID, "searchboxinput").send_keys(search_term)
|
34 |
+
driver.find_element(By.ID, "searchbox-searchbutton").click()
|
35 |
+
|
36 |
+
time.sleep(4)
|
37 |
+
url = driver.current_url
|
38 |
+
|
39 |
+
if '!3d' in url:
|
40 |
+
print('--------------------------coor-----------------------------------')
|
41 |
+
url = url.split('!3d')[1]
|
42 |
+
url = url.split('!4d')
|
43 |
+
lat.append(url[0])
|
44 |
+
lon.append(url[1].split('!')[0])
|
45 |
+
|
46 |
+
return lat[0], lon[0]
|
47 |
+
else:
|
48 |
+
time.sleep(0.25)
|
49 |
+
f2 = driver.find_elements(By.XPATH, '//a')[1:]
|
50 |
+
if f2:
|
51 |
+
for k in f2:
|
52 |
+
if k.get_attribute('aria-label') is None:
|
53 |
+
continue
|
54 |
+
|
55 |
+
if search_term in k.get_attribute('aria-label'):
|
56 |
+
print('-------------------jump------------------------------')
|
57 |
+
k.click()
|
58 |
+
time.sleep(2.5)
|
59 |
+
url = driver.current_url
|
60 |
+
if '!3d' in url:
|
61 |
+
url = url.split('!3d')[1]
|
62 |
+
url = url.split('!4d')
|
63 |
+
lat.append(url[0])
|
64 |
+
lon.append(url[1].split('!')[0])
|
65 |
+
|
66 |
+
break
|
67 |
+
else:
|
68 |
+
print('------------------------none--------------------------')
|
69 |
+
lat.append('0')
|
70 |
+
lon.append('0')
|
71 |
+
|
72 |
+
break
|
73 |
+
return lat[0], lon[0]
|
74 |
+
else:
|
75 |
+
print('------------------------fatal none--------------------------')
|
76 |
+
lat.append('0')
|
77 |
+
lon.append('0')
|
78 |
+
|
79 |
+
time.sleep(0.6)
|
80 |
+
return lat[0], lon[0]
|
81 |
+
except Exception as e:
|
82 |
+
# print("5 error")
|
83 |
+
return e
|
84 |
+
|
85 |
+
|
86 |
+
def main():
|
87 |
+
st.title("Address Finder")
|
88 |
+
|
89 |
+
uploaded_file = st.file_uploader("Choose a CSV file", type=["csv"])
|
90 |
+
if uploaded_file is not None:
|
91 |
+
df = pd.read_csv(uploaded_file)
|
92 |
+
st.write("Process Started wait till progress Bar Start ! Note: 0 is Mutliple Location Error" )
|
93 |
+
|
94 |
+
latitudes, longitudes = [], []
|
95 |
+
add = df['address'].to_list()
|
96 |
+
|
97 |
+
# Create progress bar
|
98 |
+
progress_bar = st.progress(0)
|
99 |
+
progress_text = st.empty()
|
100 |
+
processed_data = []
|
101 |
+
|
102 |
+
for row in range(len(add)):
|
103 |
+
try:
|
104 |
+
|
105 |
+
result = get_address(add[row])
|
106 |
+
print('HIT Over....')
|
107 |
+
if type(result) == str:
|
108 |
+
st.error(f'{result}')
|
109 |
+
break
|
110 |
+
|
111 |
+
latitudes.append(float(result[0]))
|
112 |
+
longitudes.append(float(result[1]))
|
113 |
+
|
114 |
+
# Update progress bar
|
115 |
+
progress_value = (row + 1) / len(df['address'])
|
116 |
+
progress_bar.progress(progress_value)
|
117 |
+
progress_text.text(f"Progress: {int(progress_value * 100)}%")
|
118 |
+
|
119 |
+
# Add to processed_data
|
120 |
+
processed_data.append({'Address': add[row], 'latitudes': result[0], 'Longitudes': result[1]})
|
121 |
+
|
122 |
+
# Display df2 on the side
|
123 |
+
st.sidebar.title("Processed Data (df2)")
|
124 |
+
st.sidebar.write(pd.DataFrame(processed_data))
|
125 |
+
|
126 |
+
except Exception as e:
|
127 |
+
st.error(f'Error processing row {row + 1}: {str(e)}')
|
128 |
+
break
|
129 |
+
|
130 |
+
# Create df2 DataFrame
|
131 |
+
df2 = pd.DataFrame(processed_data)
|
132 |
+
|
133 |
+
st.success("Processing completed!")
|
134 |
+
st.write("Final Processed Data:")
|
135 |
+
st.write(df2)
|
136 |
+
|
137 |
+
|
138 |
+
if __name__ == '__main__':
|
139 |
+
main()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
selenium-wire
|
2 |
+
pandas
|
3 |
+
streamlit
|