11"""
22This module contain the code for frontend
33"""
4-
5- import sys
64import 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
107import threading
11- import json
8+
129
1310
1411class 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 \n Let'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\n Kindly 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.\n So 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
263199if __name__ == "__main__" :
0 commit comments