Advertisement
delucks

Modified gdata_puller module for Dtella

Feb 19th, 2013
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.65 KB | None | 0 0
  1. """
  2. Dtella - Google Spreadsheets Puller Module
  3. Copyright (C) 2008  Dtella Labs (http://dtella.org)
  4. Copyright (C) 2008  Paul Marks (http://pmarks.net)
  5.  
  6. $Id: pull_gdata.py 497 2008-03-04 05:14:53Z feisley $
  7.  
  8. This program is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU General Public License
  10. as published by the Free Software Foundation; either version 2
  11. of the License, or (at your option) any later version.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program; if not, write to the Free Software
  20. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  21. """
  22.  
  23. from twisted.internet import reactor
  24. from twisted.internet.threads import deferToThread
  25. import requests
  26.  
  27. PAGE_TEMPLATE = ("https://docs.google.com/spreadsheet/ccc?key="
  28.                  "%s&output=csv")
  29.  
  30. class GDataPuller(object):
  31.  
  32.     # Tell our py2exe script to let XML/SSL be included.
  33.     needs_xml = True
  34.     needs_ssl = True
  35.  
  36.     def __init__(self, sheet_key):
  37.         self.sheet_key = sheet_key
  38.  
  39.     def startText(self):
  40.         return "Requesting config data from Google Spreadsheet..."
  41.  
  42.     def query(self):
  43.  
  44.         def f(url):
  45.             return requests.get(url).content
  46.  
  47.         d = deferToThread(f, PAGE_TEMPLATE % self.sheet_key)
  48.  
  49.         def cb(result):
  50.             return result.split('\n')
  51.  
  52.         d.addCallback(cb)
  53.         return d
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement