def update_feed_references(request): FEED_REFS_URL = "http://www.gtfs-data-exchange.com/api/agencies" # grab feed references and load into json feed_refs_json = json.loads(fetch_url(FEED_REFS_URL).content)['data'] # replace feed references in a transaction old_references = FeedReference.all().fetch(1000) db.run_in_transaction(replace_feed_references, old_references, feed_refs_json) # redirect to a page for viewing all your new feed references return redirect_to("feed_references")
def get_spreadsheet(key, worksheetId): """ gets helpfully formatted data from a google spreadsheet """ jsondata = json.loads( fetch_url("http://spreadsheets.google.com/feeds/list/%s/%s/public/values?alt=json" % (key, worksheetId)).content ) for entry in jsondata["feed"]["entry"]: updated_str = entry["updated"]["$t"] updated = datetime.strptime(updated_str[: updated_str.index(".")], "%Y-%m-%dT%H:%M:%S") data = dict([(k[4:], v["$t"]) for k, v in entry.items() if "gsx$" in k]) yield {"updated": updated, "data": data}
def get_spreadsheet(key, worksheetId): """ gets helpfully formatted data from a google spreadsheet """ jsondata = json.loads( fetch_url( "http://spreadsheets.google.com/feeds/list/%s/%s/public/values?alt=json" % (key, worksheetId)).content) for entry in jsondata["feed"]["entry"]: updated_str = entry['updated']['$t'] updated = datetime.strptime(updated_str[:updated_str.index(".")], "%Y-%m-%dT%H:%M:%S") data = dict([(k[4:], v['$t']) for k, v in entry.items() if "gsx$" in k]) yield {'updated': updated, 'data': data}
def update_feed_references(request): try: FEED_REFS_URL = "http://www.gtfs-data-exchange.com/api/agencies" # grab feed references and load into json feed_refs_json = json.loads( fetch_url( FEED_REFS_URL ).content )['data'] # replace feed references in a transaction old_references = FeedReference.all().fetch(1000) replace_feed_references( old_references, feed_refs_json ) send_to_contact( "Cron job ran successfully", "Cron job ran successfully at %s"%time.time(), "*****@*****.**" ) # redirect to a page for viewing all your new feed references return redirect_to("admin_feed_references") except Exception, e: send_to_contact( "Cron job messed up", "The Update Feeds cron job messed up: %s at %s"%(e, time.time()), "*****@*****.**" )
def update_feed_references(request): try: FEED_REFS_URL = "http://gtfs-data-exchange.appspot.com/api/agencies" # grab feed references and load into json feed_refs_json = json.loads( fetch_url( FEED_REFS_URL ).content )['data'] if request.GET.get( "add" ) != "false": # add new references update_references( feed_refs_json ) if request.GET.get( "sync" ) != "false": # set the official flag on every agency that's official sync_agency_date_added() send_to_contact( "Cron job ran successfully", "Cron job ran successfully at %s"%time.time(), "*****@*****.**" ) # redirect to a page for viewing all your new feed references return HttpResponse("success") except Exception, e: send_to_contact( "Cron job messed up", "The Update Feeds cron job messed up: %s at %s"%(e, time.time()), "*****@*****.**" ) raise