Exemplo n.º 1
0
def do_login(config=None):
    client = ApiClient()
    if not config:
        config = get_config()
    try:
        client.application_id = config.get('application', 'id')
        client.application_token = config.get('application', 'token')

    except (NoSectionError, NoOptionError):
        raise PoodledoError("Application ID or token not specified in %s.\nGenerate such at 'https://api.toodledo.com/2/account/doc_register.php?si=1'. Dying." % CONFIGFILE)

    try:
        client._key = config.get('session', 'key')
        client.getAccountInfo()

    except (NoSectionError, NoOptionError, ToodledoError):
        # cached session key either wasn't there or wasn't good; get a new one and cache it
        client._key = None
        (username, password) = read_or_get_creds(config)

        try:
            client.authenticate(username, password)
        except ToodledoError as e:
            print("No login credentials were successful; please try again.")
            raise e

        if not config.has_section('session'):
            config.add_section('session')
        config.set('session', 'key', client.key)
        store_config(config)

    return client
Exemplo n.º 2
0
    def do_login(self, credential_file):
        client = ApiClient()
        with open(os.path.expanduser(credential_file), "r") as f:
            auth = json.load(f)

        try:
            client.application_id = "dash"
            client.application_token = auth['app_token'].encode('rot13')
        except KeyError:
            raise PoodledoError("Application ID or token not specified in configuration")

        try:
            client._key = auth['session_key']
            client.getAccountInfo()
        except (ToodledoError, KeyError):
            # cached session key either wasn't there or wasn't good; get a new one and cache it
            client._key = None

            try:
                client.authenticate(auth['username'], auth['password'].encode('rot13'))
            except ToodledoError as e:
                print("No login credentials were successful; please try again.")
                raise e

            auth['session_key'] = client.key
            with open(os.path.expanduser(credential_file), "w") as f:
                json.dump(auth, f, indent=4)

        return client
Exemplo n.º 3
0
from poodledo.apiclient import ApiClient, PoodledoError, ToodledoError


taskRegex = re.compile(r'\[(\d)\].*')

config = SafeConfigParser()

config.read(["pom.cur","pom.cfg"])

client = ApiClient(app_id=config.get('toodledo', 'id'),app_token=config.get('toodledo', 'token'))

def save_current_config():
    config.write(open("pom.cur", "wt"))

try:
    client._key = config.get('session-cache', 'key')
    client.getAccountInfo()
    print "Using Cached Token"
except (NoSectionError, NoOptionError, ToodledoError):
    print "Establishing new token"
    client._key = None
    client.authenticate(config.get('toodledo', 'username'),config.get('toodledo', 'password'))

    if not config.has_section('session-cache'):
        config.add_section('session-cache')
    config.set('session-cache', 'key', client.key)
    save_current_config()

def get_pom_tasks():
    return  [task for task in client.getTasks(cache=True, fields='tag') if not task.completed and "pom" in task.tag]
Exemplo n.º 4
0
taskRegex = re.compile(r'\[(\d)\].*')

config = SafeConfigParser()

config.read(["pom.cur", "pom.cfg"])

client = ApiClient(app_id=config.get('toodledo', 'id'),
                   app_token=config.get('toodledo', 'token'))


def save_current_config():
    config.write(open("pom.cur", "wt"))


try:
    client._key = config.get('session-cache', 'key')
    client.getAccountInfo()
    print "Using Cached Token"
except (NoSectionError, NoOptionError, ToodledoError):
    print "Establishing new token"
    client._key = None
    client.authenticate(config.get('toodledo', 'username'),
                        config.get('toodledo', 'password'))

    if not config.has_section('session-cache'):
        config.add_section('session-cache')
    config.set('session-cache', 'key', client.key)
    save_current_config()


def get_pom_tasks():