コード例 #1
0
ファイル: cli.py プロジェクト: xmpx000/poodledo
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
コード例 #2
0
ファイル: todo.py プロジェクト: iandennismiller/gthnk
    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
コード例 #3
0
ファイル: test_poodledo.py プロジェクト: xmpx000/poodledo
 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
コード例 #4
0
ファイル: test_poodledo.py プロジェクト: fly4us/poodledo
 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
コード例 #5
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
コード例 #6
0
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():
    pomTasks = get_pom_tasks()
    assignedNumbers = set(taskRegex.match(task.title).group(1) for task in pomTasks if taskRegex.match(task.title))
    #print assignedNumbers
    #Remove the already assigned numbers
    taskNumbers = set(str(x) for x in xrange(1, 8))
コード例 #7
0
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():
コード例 #8
0
        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
                client.deleteTask(task.id)