11"""Imports""" 
22import  logging 
33import  os .path 
4+ import  platform 
45import  re 
56import  zipfile 
6- import  multiprocessing 
7- from  gunicorn .app .base  import  BaseApplication 
87from  flask  import  Flask , render_template , request , redirect , url_for , session 
98from  flask_paginate  import  Pagination 
109from  werkzeug .utils  import  secure_filename 
2726# Upload folder 
2827UPLOAD_FOLDER  =  os .path .join (os .getcwd (), 'uploads' )
2928# Current version 
30- CURRENT_VERSION  =  'v2.0 .0' 
29+ CURRENT_VERSION  =  'v2.1 .0' 
3130# Update needed 
3231UPDATE_NEEDED  =  bool (update_needed (CURRENT_VERSION , get_latest_version ()))
3332
@@ -36,13 +35,14 @@ def create_upload_dir():
3635    """ 
3736    Create the upload directory if it does not exist. 
3837    """ 
39-     try :
40-         os .makedirs (UPLOAD_FOLDER )
41-         logging .info ("Directory %s created successfully." , {UPLOAD_FOLDER })
42-     except  FileExistsError :
43-         logging .info ("Directory %s already exists." , {UPLOAD_FOLDER })
44-     except  OSError  as  exc :
45-         logging .error ("Error creating directory: %s" , {exc })
38+     if  not  os .path .exists (UPLOAD_FOLDER ):
39+         try :
40+             os .makedirs (UPLOAD_FOLDER )
41+             logging .info ("Directory %s created successfully." , UPLOAD_FOLDER )
42+         except  OSError  as  exc :
43+             logging .error ("Error creating directory: %s" , exc )
44+     else :
45+         logging .info ("Directory %s already exists." , UPLOAD_FOLDER )
4646
4747
4848def  parse_usernames (html_source ):
@@ -172,56 +172,63 @@ def unfollowers():
172172                           per_page = per_page ,
173173                           pagination = pagination , )
174174
175+ if  platform .system () !=  "Windows" :
176+     from  gunicorn .app .base  import  BaseApplication 
177+     import  multiprocessing 
175178
176- class  InstaUnFollowers (BaseApplication ):
177-     """ 
178-     This class extends the `gunicorn.app.base.BaseApplication` class and 
179-     provides custom implementation for the `load_config` and `load` methods. 
180- 
181-     Attributes: 
182-         options (dict): Options for the application. 
183-         application (obj): The application object. 
184- 
185-     Args: 
186-         application (obj): The application object. 
187-         options (dict, optional): Options for the Gunicorn server. 
188- 
189-     Note: 
190-         'init' and 'load' methods are implemented by WSGIApplication. 
191-     """ 
192- 
193-     # pylint: disable=abstract-method 
194-     def  __init__ (self , application , options = None ):
195-         self .options  =  options  or  {}
196-         self .application  =  application 
197-         super ().__init__ ()
198- 
199-     def  load_config (self ):
179+     class  InstaUnFollowers (BaseApplication ):
200180        """ 
201-         Load the configuration for the Gunicorn server. 
181+         This class extends the `gunicorn.app.base.BaseApplication` class and 
182+         provides custom implementation for the `load_config` and `load` methods. 
202183
203-         This method sets the Gunicorn server configuration values based on the provided options. 
204-         """ 
205-         config  =  {key : value  for  key , value  in  self .options .items ()
206-                   if  key  in  self .cfg .settings  and  value  is  not None }
207-         for  key , value  in  config .items ():
208-             self .cfg .set (key .lower (), value )
184+         Attributes: 
185+             options (dict): Options for the application. 
186+             application (obj): The application object. 
209187
210-     def   load ( self ) :
211-         """ 
212-         Load  the application . 
188+         Args : 
189+             application (obj): The application object.  
190+             options (dict, optional): Options for  the Gunicorn server . 
213191
214-         Returns : 
215-             obj: The application object . 
192+         Note : 
193+             'init' and 'load' methods are implemented by WSGIApplication . 
216194        """ 
217-         return  self .application 
218- 
219195
220- if  __name__  ==  '__main__' :
221-     create_upload_dir ()
222-     gunicorn_options  =  {
223-         'bind' : '0.0.0.0:5000' ,
224-         'workers' : (multiprocessing .cpu_count () *  2 ) +  1 ,
225-         'timeout' : 500 ,
226-     }
227-     InstaUnFollowers (app , gunicorn_options ).run ()
196+         # pylint: disable=abstract-method 
197+         def  __init__ (self , application , options = None ):
198+             self .options  =  options  or  {}
199+             self .application  =  application 
200+             super ().__init__ ()
201+ 
202+         def  load_config (self ):
203+             """ 
204+             Load the configuration for the Gunicorn server. 
205+ 
206+             This method sets the Gunicorn server configuration values based on the provided options. 
207+             """ 
208+             config  =  {key : value  for  key , value  in  self .options .items ()
209+                       if  key  in  self .cfg .settings  and  value  is  not None }
210+             for  key , value  in  config .items ():
211+                 self .cfg .set (key .lower (), value )
212+ 
213+         def  load (self ):
214+             """ 
215+             Load the application. 
216+ 
217+             Returns: 
218+                 obj: The application object. 
219+             """ 
220+             return  self .application 
221+ 
222+ 
223+     if  __name__  ==  '__main__' :
224+         create_upload_dir ()
225+         gunicorn_options  =  {
226+             'bind' : '0.0.0.0:5000' ,
227+             'workers' : (multiprocessing .cpu_count () *  2 ) +  1 ,
228+             'timeout' : 500 ,
229+         }
230+         InstaUnFollowers (app , gunicorn_options ).run ()
231+ else :
232+     if  __name__  ==  '__main__' :
233+         create_upload_dir ()
234+         app .run (debug = True , host = "0.0.0.0" , port = 5000 )
0 commit comments