def __init__(self, log, settings): self.log = log self.settings = settings # log.debug("App Class Initializing") # Setup home_dir and temp_dir self.home_dir = os.path.expanduser("~") tempfile.tempdir = self.home_dir self.temp_dir = tempfile.TemporaryDirectory() # log.debug('temp_dir: %s', self.temp_dir) # Initialize Frame self.frame = Urwid.Frame( Urwid.Filler(W.get_text('body', 'Loading...Please Wait', 'center'))) # Initialize MainLoop self.loop = Urwid.MainLoop(self.frame, self.settings.display['palette'], unhandled_input=self.unhandled_input, handle_mouse=False) self.errors = 0 self.state = State(self, self.log) self.menus = Menus(self) self.views = Views(self) self.actions = Actions(self) self.views.activate(self, {'view': 'home'}) self.action_pipes = []
def __init__(self, settings): L.debug("App Class Initializing") self.settings = settings self.frame = U.Frame( U.Filler(W.get_text('body', 'Loading...Please Wait', 'center'))) self.loop = U.MainLoop(self.frame, self.settings.display['palette'], unhandled_input=self.unhandled_input, handle_mouse=False) self.state = State(self) self.views = Views(self) self.menus = Menus(self)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) log.debug( f'--------------------------- Starting {self.BOT_NAME} v{self.VERSION} --------------------------' ) self.expander = TeamExpander() self.tower_data = TowerOfDoomData(self.my_emojis) self.prefix = models.Prefix(CONFIG.get('default_prefix')) self.language = models.Language(CONFIG.get('default_language')) self.subscriptions = models.Subscriptions() self.views = Views(emojis={})
def __init__(self): """ """ self.fields = ( "product_name_fr", "code", "categories", "nutriscore_grade", "url", "brands", "stores", ) self.data_clean = {} self.views = Views() self.open_json()
class App(object): """App Class is a container for the state, views, menu, loop, and frame classes""" def __init__(self, settings): L.debug("App Class Initializing") self.settings = settings self.frame = U.Frame( U.Filler(W.get_text('body', 'Loading...Please Wait', 'center'))) self.loop = U.MainLoop(self.frame, self.settings.display['palette'], unhandled_input=self.unhandled_input, handle_mouse=False) self.state = State(self) self.views = Views(self) self.menus = Menus(self) def exit(self, *args): """Exits the applications Raises: U.ExitMainLoop: Exits the application """ L.debug("Args: %s", args) raise U.ExitMainLoop() def unhandled_input(self, key): """Manages input that is not handled by a specific widget Arguments: key {str} -- the str/char representation of the key pressed """ if isinstance(key, str): # raw = loop.screen.get_input(raw_keys=True) # debug('raw: %s', raw) if key in 'ctrl e': self.views.activate(self, 'Quit') if key in 'tab': if self.frame.focus_position == 'footer': self.frame.focus_position = 'body' else: if self.settings.display['menu_enabled']: self.frame.focus_position = 'footer' if 'end' in key: self.state.go_forward() if 'home' in key: self.state.go_back()
def __init__(self): self.URL = "https://fr.openfoodfacts.org/cgi/search.pl" self.HEADERS = {"User-Agent": "OC-P5 - GNU/Windows - Version 0.1"} self.PARAMS = { "search_simple": 1, "action": "process", "json": 1, "tagtype_0": "countries", "tag_contains_0": "contains", "tag_0": "france", "page_size": 40, "page": 1, "sort_by": "unique_scans_n", } self.views = Views()
class UpdateViews(object): def __init__(self, table, commited_index, base_url): self.views = Views(table, commited_index) self.url = base_url def doGet(self, asset_id): method = 'GET' body = '' if asset_id is not None: uri = urlparse(self.url + asset_id) h = httplib2.Http() try: response, content = h.request(uri.geturl(), method, body) except socket.error as err: print "error" if response['status'] == '200': return content elif response['status'] == '404': return content def update(self, t=1): items = self.views.query_uncommited() for item in items: print item print self.doGet(item['asset_id']) sleep(t)
def add_library(self, library_id, update=False): try: FullSync(self, library_id, update=update) except Exception as error: LOG.exception(error) return False Views().get_nodes() return True
class Extract: """ Extract data from OpenFoodFacts. """ def __init__(self): self.URL = "https://fr.openfoodfacts.org/cgi/search.pl" self.HEADERS = {"User-Agent": "OC-P5 - GNU/Windows - Version 0.1"} self.PARAMS = { "search_simple": 1, "action": "process", "json": 1, "tagtype_0": "countries", "tag_contains_0": "contains", "tag_0": "france", "page_size": 40, "page": 1, "sort_by": "unique_scans_n", } self.views = Views() def extract(self): """ I extract product from OpenFoodFacts """ try: request = requests.get( url=self.URL, params=self.PARAMS, headers=self.HEADERS ) products = request.json() with open("thesubstitute/off_data_extract.json", "w") as f: json.dump(products, f) self.views.display_text( f""" REUSSITE de l'Extraction : {len(products['products'])} produits ont été téléchargés dans le fichier off_data_extract.json.""" ) except Exception as error: self.view.display_text_error("ECHEC : les produits ne sont pas téléchargés.", f"Type de l'erreur : {error}")
def __init__(self, config): self.db_client = DBClient(host=config['db_host'], port=config['db_port']) self.db_client.register_table('ads') self.db_client.select_table('ads') template_path = os.path.join(os.path.dirname(__file__), 'templates') self.jinja_env = Environment(loader=FileSystemLoader(template_path), autoescape=True) self.views = Views(app_renderer=self.render_template) self.url_map = Map([ Rule('/', endpoint='ad_list_view'), Rule('/ad/<ad_id>/', endpoint='ad_detail_view'), Rule('/ad/create/', endpoint='ad_create_view'), ])
def menu(): texts = Texts() passenger = Passenger() dao = BusDao() if os.path.exists(dao.path): dao.set_passenger(passenger, texts) choice = "" while choice != "0": views = Views(texts) choice = multipy_input(texts.show_menutext()) if choice == "1": passenger.set_bus_lines(multipy_input(texts.busline_input_text)) elif choice == "2": views.show_near_lines(passenger, dao) elif choice == "3": views.show_bus_lines(passenger, dao) elif choice == "4": passenger.bus_lines_del(multipy_input(texts.busline_input_text)) elif choice == "5": views.show_near(passenger, dao) elif choice == "6": passenger.show_bus_lines() elif choice == "7": views.open_map(passenger, dao, (multipy_input(texts.busid_input_text))) elif choice == "8": views.show_by_id(passenger, dao, (multipy_input(texts.busid_input_text))) elif choice == "9": views.show_fastests(passenger, dao) elif choice == "10": views.show_all(passenger, dao) elif choice == "11": views.open_map_manually(multipy_input(texts.latitude_input_text), multipy_input(texts.longitude_input_text)) elif choice == "12": try: passenger.set_latitude(multipy_input(texts.latitude_input_text)) passenger.set_longitude(multipy_input(texts.longitude_input_text)) except: print("=(") elif choice == "13": try: passenger.maxdistance = multipy_input(texts.max_distance_intext) except: print("=(") elif choice == "14": try: passenger.minspeed = multipy_input(texts.min_speed_text) except: print("=(") elif choice == "97": print("%s %s" % (texts.language_text, texts.language)) passenger.show(texts.passenger_text) elif choice == "98": dao.write_user_config(passenger, texts) elif choice == "99": texts.language = multipy_input(texts.lang_chtext) print(texts.language) else: if choice != "0": print("\n=(\n") else: print("\n=)\n")