def init_account_selection(self): manager = AccountManager() # Use the remembered account if there's one if manager.get_default(): self._create_engine(manager.get_default()) else: self._show_accounts(switch=False)
def main(self): """Start the Account Selector""" manager = AccountManager() # Use the remembered account if there's one if manager.get_default(): self._create_engine(manager.get_default()) else: self._show_accounts(switch=False)
def _show_accounts(self, switch=True, forget=False): manager = AccountManager() if forget: manager.set_default(None) accountsel = AccountsWindow(manager, transient_for=self) accountsel.connect('account-open', self._on_account_open) accountsel.connect('account-cancel', self._on_account_cancel, switch) accountsel.connect('destroy', self._on_modal_destroy) accountsel.present() self._modals.append(accountsel)
def do_switch_account(self, loop=None, data=None): manager = AccountManager() if self.engine is None: if manager.get_default(): self.start(manager.get_default()) else: self.dialog = AccountDialog(self.mainloop, manager, False) urwid.connect_signal(self.dialog, 'done', self.start) else: self.dialog = AccountDialog(self.mainloop, manager, True) urwid.connect_signal(self.dialog, 'done', self.do_reload_engine)
def do_switch_account(self, loop=None, data=None): manager = AccountManager() if self.engine is None: if manager.get_default(): self.start(manager.get_default()) else: self.dialog = AccountDialog(self.mainloop, manager, False) urwid.connect_signal(self.dialog, 'done', self.start) else: self.dialog = AccountDialog(self.mainloop, manager, True) urwid.connect_signal(self.dialog, 'done', self.do_reload_engine)
def _show_accounts(self, switch=True, forget=False): manager = AccountManager() if forget: manager.set_default(None) def _on_accountsel_cancel(accounts_window): Gtk.main_quit() accountsel = AccountsWindow(manager, transient_for=self) accountsel.connect('account-open', self._on_account_open) if not switch: accountsel.connect('account-cancel', _on_accountsel_cancel)
def __init__(self, accountnum=1): """ Defaults to the first account. """ self.watch = Watcher() self.accs = dict(AccountManager().get_accounts()) self.engine = Engine(self.accs.get(accountnum)) self.engine.start() self.tList = list(self.engine.get_list()) with open(self.watch.WATCH_FILE, 'r') as watch_file: self.adList = list(json.load(watch_file)) watch_file.close() self._sort_lists()
def _on_account_open(self, accounts_window, account_num, remember): manager = AccountManager() account = manager.get_account(account_num) if remember: manager.set_default(account_num) else: manager.set_default(None) # Reload the engine if already started, # start it otherwise if self._engine and self._engine.loaded: self._main_view.load_account_mediatype(account, None, None) else: self._create_engine(account)
def _on_account_cancel(self, _accounts_window, switch): manager = AccountManager() if not switch or not manager.get_accounts(): self._quit()
def forget_account(self): manager = AccountManager() manager.set_default(None)
def forget_account(self): manager = AccountManager() manager.set_default(None)
import os from trackma.accounts import AccountManager from trackma import utils from envparse import env username = env.str('ACCOUNT_USERNAME') password = env.str('ACCOUNT_PASSWORD') api = env.str('ACCOUNT_API') manager = AccountManager() if len(manager.get_accounts()) == 0: print("No accounts found, adding account...") manager.add_account(username, password, api) manager.set_default(1) else: account_exists = False for num, account in manager.get_accounts(): if account["username"] == username and account["api"] == api: account_exists = True if account["password"] != password: print("Account password mismatch, updating...") manager.edit_account(num, username, password, api) if manager.get_default() != manager.get_account(num): print("Setting account as default") manager.set_default(num) break if not account_exists: print ("Could not find account, adding account...") manager.add_account(username, password, api) manager.set_default(len(manager.get_accounts()))