def get_cached_client(): """Gets an authorized TelegramClient, performing the authorization process if it's the first time""" global cached_client if not cached_client: print('Loading client...') settings = load_settings() cached_client = TelegramClient(session_user_id=settings.get('session_name', 'anonymous'), api_id=settings['api_id'], api_hash=settings['api_hash']) cached_client.connect() # Then, ensure we're authorized and have access if not cached_client.is_user_authorized(): # Import the login window locally to avoid cyclic dependencies from gui.windows import LoginWindow print('First run, client not authorized. Sending code request.') cached_client.send_code_request(str(settings['user_phone'])) start_app(LoginWindow, client=cached_client, phone=settings['user_phone']) del LoginWindow print('Client loaded and authorized.') return cached_client
def get_cached_client(): """Gets an authorized TelegramClient, performing the authorization process if it's the first time""" global cached_client if not cached_client: print('Loading client...') settings = load_settings() cached_client = TelegramClient(session_user_id=settings.get( 'session_name', 'anonymous'), api_id=settings['api_id'], api_hash=settings['api_hash']) cached_client.connect() # Then, ensure we're authorized and have access if not cached_client.is_user_authorized(): # Import the login window locally to avoid cyclic dependencies from gui.windows import LoginWindow print('First run, client not authorized. Sending code request.') cached_client.send_code_request(str(settings['user_phone'])) start_app(LoginWindow, client=cached_client, phone=settings['user_phone']) del LoginWindow print('Client loaded and authorized.') return cached_client
def go_back(self): """Goes back to the previous (select dialog) window""" self.master.destroy() # Import the window here to avoid cyclic dependencies from gui.windows import SelectDialogWindow start_app(SelectDialogWindow)
def on_next(self, event=None): """Gets fired after the Next button is clicked""" # Ensure the user has selected an entity selection = self.conversation_list.curselection() if selection: index = selection[0] value = self.conversation_list.get(index) # Search for the matching entity (user or chat) # TODO Note that this will NOT work if they have the exact same name! for entity in self.entities: display = sanitize_string(get_display_name(entity)) if value == display: self.master.destroy() # Import the window here to avoid cyclic dependencies from gui.windows import BackupWindow start_app(BackupWindow, entity=entity)
from gui import start_app from gui.windows import SelectDialogWindow from utils import get_cached_client if __name__ == "__main__": # Since this is the first time, it will be loaded and cached get_cached_client() start_app(SelectDialogWindow)
from gui import start_app from gui.windows import SelectDialogWindow from utils import get_cached_client if __name__ == '__main__': # Since this is the first time, it will be loaded and cached get_cached_client() start_app(SelectDialogWindow)