ideotop
ideotop

Reputation: 184

Webscraping Google tasks via Google Calendar

As gmail and the task api is not available everywhere (eg: some companies block gmail but not calendar), is there a way to scrap google task through the calendar web interface ?

I did a userscript like the one below, but I find it too brittle :

// List of div to hide
idlist = [
    'gbar',
    'logo-container',
    ...
];

// Hiding by id
function displayNone(idlist) {
    for each (id in idlist) {
        document.getElementById(id).style.display = 'none';
    }
}

Upvotes: 0

Views: 849

Answers (2)

Hanxue
Hanxue

Reputation: 12766

The Google Tasks API is now available. You can get a list of your tasks via a HTTP query, result returned in JSON. There is a step by step example on how to write a Google Tasks webapp on Google App Engine at

http://code.google.com/appengine/articles/python/getting_started_with_tasks_api.html

The sample webapp looks like this:

from google.appengine.dist import use_library
use_library('django', '1.2')
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import run_wsgi_app
from apiclient.discovery import build
import httplib2
from oauth2client.appengine import OAuth2Decorator
import settings

decorator = OAuth2Decorator(client_id=settings.CLIENT_ID,
                            client_secret=settings.CLIENT_SECRET,
                            scope=settings.SCOPE,
                            user_agent='mytasks')


class MainHandler(webapp.RequestHandler):

  @decorator.oauth_aware
  def get(self):
    if decorator.has_credentials():
      service = build('tasks', 'v1', http=decorator.http())
      result = service.tasks().list(tasklist='@default').execute()
      tasks = result.get('items', [])
      for task in tasks:
        task['title_short'] = truncate(task['title'], 26)
      self.response.out.write(template.render('templates/index.html',
                                              {'tasks': tasks}))
    else:
      url = decorator.authorize_url()
      self.response.out.write(template.render('templates/index.html',
                                              {'tasks': [],
                                               'authorize_url': url}))


def truncate(string, length):
  return string[:length] + '...' if len(string) > length else string

application = webapp.WSGIApplication([('/', MainHandler)], debug=True)


def main():
  run_wsgi_app(application)

Note that first you need to enable Google Tasks API at the API Console https://code.google.com/apis/console/b/0/?pli=1

Upvotes: 1

boothinator
boothinator

Reputation: 121

I would suggest parsing the Atom feed of the calendars you wish to see. You can get the feeds of individual calendars by selecting the Options Gear > Calendar Settings, then choosing the Calendars tab, and selecting the calendar you want. From the Calendar Details screen, you can get an Atom (XML) feed, an iCal feed, or an HTML/Javascript calendar.

Upvotes: 0

Related Questions