-
-
Save rcmdnk/b9d8e5ce51e0b041ae9d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#Copyright (c) 2013 rcmdnk | |
import os | |
import sys | |
import httplib2 | |
from oauth2client.file import Storage | |
from oauth2client.tools import run | |
from oauth2client.client import OAuth2WebServerFlow | |
from apiclient.discovery import build | |
def main(uselist='',items=''): | |
# Authentaation | |
storage = Storage(os.path.expanduser('~/.gtask_oauth')) | |
credentials = storage.get() | |
if credentials is None or credentials.invalid: | |
credentials = run( | |
OAuth2WebServerFlow( | |
client_id='326384869607-9c57sseqij1vpes16ect83irq490pn8c.apps.googleusercontent.com', | |
client_secret='h0vi7XXzU3DRJyEa2aYFPRcm', | |
scope=[ | |
'https://www.googleapis.com/auth/tasks', | |
'https://www.googleapis.com/auth/tasks.readonly'], | |
user_agent='gtaskslist/1.0',), | |
storage) | |
http = httplib2.Http() | |
http = credentials.authorize(http) | |
service = build('tasks', 'v1', http=http) | |
# Get task lists | |
tasklists = service.tasklists().list().execute() | |
for tl in tasklists['items']: | |
# Check list name | |
if uselist != '' and tl['title'] != uselist: | |
continue | |
# Get tasks | |
tasks = service.tasks().list(tasklist=tl['id']).execute() | |
for t in tasks['items']: | |
ttitle = t['title'] | |
if ttitle == '': | |
continue | |
useflag = 0 | |
if len(items) == 0 or items[0] == '': | |
useflag = 1 | |
else: | |
for i in items: | |
if ttitle.find(i) != -1: | |
useflag = 1 | |
break | |
if useflag == 1: | |
print ttitle.encode('utf_8') | |
if __name__ == '__main__': | |
# Get command line options | |
from optparse import OptionParser | |
usage = '''usage: %prog [-opts] arg1 arg2 | |
If arg1 arg2... are given, only tasks which include | |
these words (ORed) will be listed (combined with -i) | |
If you have not installed google-api-python-client, follow: | |
https://developers.google.com/api-client-library/python/start/installation | |
''' | |
parser = OptionParser(usage) | |
parser.add_option('-l', '--list', action='store', | |
dest='uselist', default='', | |
help='If \'USELIST\' is not an empty, tasks will be searched for only from the given list. [default: %default]') | |
parser.add_option('-i', '--item', action='store', | |
dest='item', default='', | |
help='If \'ITEM\' is not an empty, only tasks which contains given item are listed up. Multiple words can be given by using \',\' as a separator. [default: %default]') | |
(opts, args) = parser.parse_args() | |
# Set parameters | |
uselist = opts.uselist | |
items = opts.item.split(',') | |
for i in args: | |
items.append(i) | |
# Run main function | |
main(uselist, items) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment