Skip to content

Instantly share code, notes, and snippets.

@AaronMT
Created December 17, 2011 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AaronMT/1491223 to your computer and use it in GitHub Desktop.
Save AaronMT/1491223 to your computer and use it in GitHub Desktop.
alexa_pull_to_google_spreadsheet
#!/usr/bin/python
__author__ = 'aaron.train@gmail.com'
import sys
import getopt
import alexa
import gdata.spreadsheet.service
class top_site:
def __init__(self, email, password, top_list):
self.gd_client = gdata.spreadsheet.service.SpreadsheetsService()
self.gd_client.email = email
self.gd_client.password = password
self.gd_client.ProgrammaticLogin()
self.top_list = top_list
self.curr_key = "xxx"
self.curr_wksht_id = "od6"
def Run(self):
self._fetchListing()
self._CellsUpdateAction()
def _fetchListing(self):
self.top_list = alexa.top_list(int(self.top_list))
def _CellsUpdateAction(self):
query = gdata.spreadsheet.service.CellQuery()
query['min-col'] = '1'
query['max-col'] = '1'
query['min-row'] = '2'
feed = self.gd_client.GetCellsFeed(self.curr_key, wksht_id=self.curr_wksht_id, query=query)
batchRequest = gdata.spreadsheet.SpreadsheetsCellsFeed()
for index, item in enumerate(self.top_list):
feed.entry[index].cell.inputValue = item[1]
batchRequest.AddUpdate(feed.entry[index])
updated = self.gd_client.ExecuteBatch(batchRequest, feed.GetBatchLink().href)
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], "", ["user=", "pw=", "sites="])
except getopt.error, msg:
print 'python alexa_pull.py --user [username] --pw [password] --sites [sites] '
sys.exit(2)
user = ""
password = ""
top_list = ""
for o, a in opts:
if o == "--user":
user = a
if o == "--pw":
password = a
if o == "--sites":
top_list = a
if user == "" or password == "":
print 'python alexa_pull.py --user [username] --pw [password] --sites [sites] '
sys.exit(2)
n = top_site(user, password, top_list)
n.Run()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment