网页通过Google日历抓取Google任务

时间:2010-04-01 21:52:27

标签: javascript jquery google-calendar-api web-scraping

由于gmail和任务api无处可用(例如:某些公司阻止gmail而不是日历),有没有办法通过日历网络界面废弃谷歌任务?

我做了一个类似下面的用户脚本,但我发现它太脆了:

// 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';
    }
}

2 个答案:

答案 0 :(得分:1)

Google Tasks API现已推出。您可以通过HTTP查询获取任务列表,结果以JSON格式返回。有关如何在Google App Engine上编写Google Tasks Web应用程序的分步示例

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

示例webapp如下所示:

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)

请注意,首先您需要在API控制台https://code.google.com/apis/console/b/0/?pli=1

启用Google Tasks API

答案 1 :(得分:0)

我建议解析您希望看到的日历的Atom提要。您可以通过选择选项齿轮>获取各个日历的供稿。 “日历设置”,然后选择“日历”选项卡,并选择所需的日历。在“日历详细信息”屏幕中,您可以获取Atom(XML)订阅源,iCal订阅源或HTML / Javascript日历。