Exemplo n.º 1
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.º 2
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.º 3
0
    def retrieve(self):
        """
        retrieve HotList tasks
        """

        #parse arguments
        loglevel = 'WARNING'
        parser = argparse.ArgumentParser(
            description='Notify toodledo tasks with Growl for windows.')
        parser.add_argument('--log', dest='loglevel', default='WARNING',
                            help='level of logging (default: WARNING)')
        args = parser.parse_args()

        #parse config
        current_dir = os.path.dirname(os.path.abspath(__file__))
        config_file = os.path.join(current_dir, 'toodledo2growl.cnf')
        config = ConfigParser.SafeConfigParser()
        config.read([config_file])

        # config logging
        numeric_level = getattr(logging, args.loglevel.upper(), None)
        if not isinstance(numeric_level, int):
            raise ValueError('Invalid log level: %s' % loglevel)
        logging.basicConfig(level=numeric_level)

        # create Toodledo Client
        app_id = config.get('credential', 'app_id')
        app_token = config.get('credential', 'app_token')
        logging.debug(': '.join(['Client app_id', app_id]))
        logging.debug(': '.join(['Client app_token', app_token]))
        api = ApiClient(app_id=app_id, app_token=app_token)
        logging.info('created Toodledo Client')

        # Toodledo Authentication
        email = config.get('credential', 'email')
        password = config.get('credential', 'password')
        logging.debug(': '.join(['Auth email', email]))
        logging.debug(': '.join(['Auth password', password]))
        api.authenticate(email, password)
        logging.info('Auth Toodledo')

        # Get AccountInfo
        account_info = api.getAccountInfo()
        logging.debug(': '.join(['AccountInfo', str(account_info)]))

        # Get Task list from Toodledo
        task_list = api.getTasks(fields="duedate,star,priority,parent")
        logging.info(': '.join(['Got task list', str(len(task_list))]))

        for task in self._HotlistFilter(account_info, task_list):
            if task.parent != 0:
                parent = api.getTask(task.parent)
                task.title = parent.title  + '.' + task.title
            yield task
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():
    return  [task for task in client.getTasks(cache=True, fields='tag') if not task.completed and "pom" in task.tag]

def update_task_numbers():
Exemplo n.º 5
0
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 [