8 class gdocs_renderer(renderer.debuggable_abstaining_renderer):
9 """A renderer to fetches and munge docs from drive.google.com"""
11 query = 'title="Grocery (go/grocery)" OR title="Costco List (go/costco)"'
13 def __init__(self, name_to_timeout_dict, oauth):
14 super(gdocs_renderer, self).__init__(name_to_timeout_dict, False)
16 self.client = self.oauth.docs_service()
18 def debug_prefix(self):
21 def periodic_render(self, key):
28 param['pageToken'] = page_token
29 param['q'] = self.query
30 print "QUERY: %s" % param['q']
32 files = self.client.files().list(**param).execute()
33 result.extend(files['items'])
34 page_token = files.get('nextPageToken')
38 print("********* TRYING TO REFRESH GDOCS CLIENT *********")
39 self.oauth.refresh_token()
40 self.client = self.oauth.docs_service()
43 def boost_font_size(matchobj):
44 x = int(matchobj.group(1))
47 return "font-size:%dpt" % (x)
52 self.debug_print("%s (%s)\n" % (f['title'], f['id']))
54 url = f['exportLinks']['text/html']
56 print "Fetching %s..." % url
57 resp, contents = self.client._http.request(url)
60 if resp.status == 200:
62 contents = re.sub('<body class="..">', '', contents)
63 contents = contents.replace('</body>', '')
64 contents = re.sub('font-size:([0-9]+)pt', boost_font_size, contents)
65 f = file_writer.file_writer('%s_2_3600.html' % title)
66 now = datetime.datetime.now()
69 <!-- Last updated at %s -->
71 <DIV STYLE="-webkit-column-count: 2; -moz-column-count: 2; column-count: 2;">
73 </DIV>""" % (title, now, contents))
76 self.debug_print("error: %s" % resp)
81 #oauth = gdata_oauth.OAuth(secrets.google_client_id,
82 # secrets.google_client_secret)
83 #x = gdocs_renderer({"Testing", 12345},
85 #x.periodic_render("Test")