Exemple #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
Exemple #2
0
 def _createApiClient(self, authenticate=False):
     if self.mocked:
         api = ApiClient(app_id=self.app_id, app_token=self.app_token)
         api._urlopener = self.opener
     else:
         api = cached_client
     if authenticate:
         api.authenticate(self.user_email, self.password)
     return api
Exemple #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
Exemple #4
0
 def __init__(self, methodName='runTest'):
     self.mocked = True
     if not self.mocked:
         global cached_client
         config = get_config()
         self.user_email = config.get('config', 'username')
         self.password = config.get('config', 'password')
         self.app_id = config.get('application', 'id')
         self.app_token = config.get('application', 'token')
         if not cached_client:
             cached_client = ApiClient(app_id=self.app_id,
                                       app_token=self.app_token)
     super(PoodleDoTest, self).__init__(methodName)
Exemple #5
0
from ConfigParser import SafeConfigParser, NoSectionError, NoOptionError

__author__ = 'andriod'

import re

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'))