Skip to content

Commit c5f86d6

Browse files
authored
Merge pull request #18 from Zubdata/updating
upgrading to 2.0.0
2 parents fdd8570 + 852dd24 commit c5f86d6

File tree

9 files changed

+273
-312
lines changed

9 files changed

+273
-312
lines changed

Google map scraper/scraper/__init__.py

Whitespace-only changes.

Google map scraper/scraper/datasaver.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55

66
import pandas as pd
7+
from .settings import OUTPUT_PATH
78
import os
89

910

1011
class DataSaver:
11-
def __init__(self, selectedpath, outputformat, messageshowfunc) -> None:
12-
self.selectedPath = selectedpath
12+
def __init__(self, outputformat, messageshowfunc) -> None:
1313
self.outputFormat = outputformat
1414
self.messageShowFunc = messageshowfunc
1515

@@ -35,21 +35,20 @@ def save(self, datalist):
3535
elif self.outputFormat == "json":
3636
extension = ".json"
3737

38-
joinedPath = self.selectedPath + filename + extension
38+
joinedPath = OUTPUT_PATH + filename + extension
3939

4040
if os.path.exists(joinedPath):
4141
index = 1
4242
while True:
4343
filename = f"/gms output{index}"
4444

45-
joinedPath = self.selectedPath + filename + extension
45+
joinedPath = OUTPUT_PATH + filename + extension
4646

4747
if os.path.exists(joinedPath):
4848
index += 1
4949

5050
else:
5151
break
52-
5352
if self.outputFormat == "excel":
5453
dataFrame.to_excel(joinedPath, index=False)
5554
elif self.outputFormat == "csv":

Google map scraper/scraper/frontend.py

Lines changed: 22 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
11
"""
22
This module contain the code for frontend
33
"""
4-
5-
import sys
64
import tkinter as tk
7-
from tkinter import ttk, filedialog, WORD
8-
from scraper import Backend
9-
import os
5+
from tkinter import ttk, WORD
6+
from scraper.scraper import Backend
107
import threading
11-
import json
8+
129

1310

1411
class Frontend(Backend):
1512
def __init__(self):
16-
self.settingsPath = self.pathmaker("settings/outputpath.json")
17-
1813
"""Initializing frontend layout"""
1914

2015
self.root = tk.Tk()
21-
icon = tk.PhotoImage(file=self.pathmaker("images/GMS.png"))
16+
icon = tk.PhotoImage(file="Google map scraper\images\GMS.png")
2217

2318
self.root.iconphoto(True, icon)
2419
self.root.geometry("850x650")
@@ -32,7 +27,7 @@ def __init__(self):
3227
background=[("active", "white")],
3328
)
3429

35-
bgimage = tk.PhotoImage(file=self.pathmaker("images/Home.png"))
30+
bgimage = tk.PhotoImage(file="Google map scraper\images\Home.png")
3631

3732
self.imglabel = tk.Label(self.root, image=bgimage)
3833
self.imglabel.place(x=0, y=0, relwidth=1, relheight=1)
@@ -90,22 +85,12 @@ def __init__(self):
9085
)
9186
self.show_text.place(x=295, y=440)
9287

93-
"""For reset settings button"""
94-
self.resetSettingsButton = ttk.Button(
95-
self.root,
96-
text="Reset settings",
97-
width=15,
98-
command=self.resetsettings,
99-
style="my.TButton",
100-
)
101-
self.resetSettingsButton.place(x=20, y=590)
102-
10388
"""For healdess checkbox"""
10489

105-
self.healdessCheckBoxVar=tk.IntVar()
106-
self.healdessCheckBox= tk.Checkbutton(self.root,text="Headless mode",variable=self.healdessCheckBoxVar)
107-
self.healdessCheckBox.place(x=700,y=45)
108-
90+
self.healdessCheckBoxVar = tk.IntVar()
91+
self.healdessCheckBox = tk.Checkbutton(
92+
self.root, text="Headless mode", variable=self.healdessCheckBoxVar)
93+
self.healdessCheckBox.place(x=700, y=45)
10994

11095
self.__replacingtext(
11196
"Welcome to Google Maps Scraper!\n\nLet's start scraping..."
@@ -115,24 +100,11 @@ def __replacingtext(self, text):
115100
"""This function will insert the text in text showing box"""
116101

117102
self.show_text.config(state="normal")
118-
# self.messageShowBox.delete(index1=1.0,index2=tkinter.END)
119103
self.show_text.insert(tk.END, "• " + text)
120104
self.show_text.insert(tk.END, "\n\n")
121105
self.show_text.see(tk.END)
122106
self.show_text.config(state="disabled")
123107

124-
def pathmaker(self, relativepath):
125-
"""Get absolute path to resurce, for deployment of this application
126-
using PyInstaller"""
127-
128-
try:
129-
# PyInstaller creates a temp folder and stores path in _MEIPASS
130-
base_path = sys._MEIPASS
131-
except Exception as p:
132-
base_path = os.path.abspath(".")
133-
134-
return os.path.join(base_path, relativepath)
135-
136108
def getinput(self):
137109
self.searchQuery = self.search_box.get()
138110
self.outputFormatValue = self.outputFormatButton.get()
@@ -146,21 +118,15 @@ def getinput(self):
146118
self.__replacingtext(text="Oops! You did not select output format")
147119

148120
else:
149-
self.askingfolderpath()
150-
151-
if len(self.outputfolderpath) == 0:
152-
self.__replacingtext(
153-
"You did not select any folder\nKindly submit again and select one folder where files will be stored"
154-
)
155-
else:
156-
self.submit_button.config(state="disabled")
121+
self.submit_button.config(state="disabled")
157122

158-
self.searchQuery = self.searchQuery.lower()
159-
self.outputFormatValue = self.outputFormatValue.lower()
160-
self.headlessMode=self.healdessCheckBoxVar.get()
123+
self.searchQuery = self.searchQuery.lower()
124+
self.outputFormatValue = self.outputFormatValue.lower()
125+
self.headlessMode = self.healdessCheckBoxVar.get()
161126

162-
self.threadToStartBackend = threading.Thread(target=self.startscraping)
163-
self.threadToStartBackend.start()
127+
self.threadToStartBackend = threading.Thread(
128+
target=self.startscraping)
129+
self.threadToStartBackend.start()
164130

165131
def closingbrowser(self):
166132
"""It will close the browser when the app is closed"""
@@ -176,7 +142,6 @@ def startscraping(self):
176142
self.searchQuery,
177143
self.outputFormatValue,
178144
self.messageshowing,
179-
self.outputfolderpath,
180145
healdessmode=self.headlessMode
181146
)
182147

@@ -190,13 +155,13 @@ def messageshowing(
190155
custom=False,
191156
value=None,
192157
noresultfound=False,
193-
exception = None
158+
exception=None
194159
):
195160

196161
if interruptionerror:
197162
self.__replacingtext("Interruption in browser is absorved")
198163
if exception:
199-
self.__replacingtext("Error is: "+ exception)
164+
self.__replacingtext("Error is: " + exception)
200165

201166
self.submit_button.config(state="normal")
202167
try:
@@ -215,7 +180,7 @@ def messageshowing(
215180
self.threadToStartBackend.join()
216181
except:
217182
pass
218-
183+
219184
elif noresultfound:
220185
self.submit_button.config(state="normal")
221186
try:
@@ -224,40 +189,11 @@ def messageshowing(
224189
except:
225190
pass
226191

227-
self.__replacingtext("We are sorry but, No results found for your search query on googel maps....")
228-
229-
elif custom:
230-
self.__replacingtext(text=value)
231-
232-
def askingfolderpath(self):
233-
with open(self.settingsPath, "r") as f:
234-
self.outputfolderpath = json.load(f)["path"]
235-
236-
if len(self.outputfolderpath) == 0:
237192
self.__replacingtext(
238-
"Kindly select a folder where scraped data will be saved"
239-
)
240-
self.outputfolderpath = filedialog.askdirectory()
241-
242-
with open(self.settingsPath, "w") as f:
243-
json.dump({"path": self.outputfolderpath}, f)
193+
"We are sorry but, No results found for your search query on googel maps....")
244194

245-
elif os.path.exists(self.outputfolderpath):
246-
pass
247-
else:
248-
self.__replacingtext(
249-
"The folder you selected is no longer present.\nSo select new folder"
250-
)
251-
252-
self.outputfolderpath = filedialog.askdirectory()
253-
with open(self.settingsPath, "w") as f:
254-
json.dump({"path": self.outputfolderpath}, f)
255-
256-
self.__replacingtext("")
257-
258-
def resetsettings(self):
259-
with open(self.settingsPath, "w") as f:
260-
json.dump({"path": ""}, f)
195+
elif custom:
196+
self.__replacingtext(text=value)
261197

262198

263199
if __name__ == "__main__":

0 commit comments

Comments
 (0)