Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Dtella - Google Spreadsheets Puller Module
- Copyright (C) 2008 Dtella Labs (http://dtella.org)
- Copyright (C) 2008 Paul Marks (http://pmarks.net)
- $Id: pull_gdata.py 497 2008-03-04 05:14:53Z feisley $
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- """
- from twisted.internet import reactor
- from twisted.internet.threads import deferToThread
- import requests
- PAGE_TEMPLATE = ("https://docs.google.com/spreadsheet/ccc?key="
- "%s&output=csv")
- class GDataPuller(object):
- # Tell our py2exe script to let XML/SSL be included.
- needs_xml = True
- needs_ssl = True
- def __init__(self, sheet_key):
- self.sheet_key = sheet_key
- def startText(self):
- return "Requesting config data from Google Spreadsheet..."
- def query(self):
- def f(url):
- return requests.get(url).content
- d = deferToThread(f, PAGE_TEMPLATE % self.sheet_key)
- def cb(result):
- return result.split('\n')
- d.addCallback(cb)
- return d
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement