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 _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 #4
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
Exemple #5
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 #6
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
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'))

    if not config.has_section('session-cache'):
        config.add_section('session-cache')
Exemple #8
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'))
        print
        print cash_flow_monthly(ledger, False)

    if "daily_balance" in opt.reports:
        report = daily_balance(ledger, opt.filter, opt.format)
        if opt.format == "csv":
            open("daily_balance.csv","w").write(report)
        else:
            print report

elif opt.command == "update-todos":
    user_email = config.get('toodledo', 'username')
    password = config.get('toodledo', 'password')
    app_id = config.get('toodledo', 'id')
    app_token = config.get('toodledo', 'token')
    client = ApiClient(app_id=app_id, app_token=app_token)#, cache_xml=True)
    client.authenticate(user_email, password)
    #        config.set('cache','user_token',str(cached_client._key))
    #        store_config(config)

    for member in sorted(ledger.member_list(), key=lambda member: member[2]):
        member_id, name, plan, last_payment, last_bank_id, last_bank_acct, start, end = member
        start, end = decode(start), decode(end)
        #        if end < datetime.now():
        #            plan = "Expired " + plan
        taskName = name + " dues reminder"
        task = None
        try:
            task = client.getTask(taskName)
            while task.completed:
                print "Deleting Completed reminder: %s "%taskName