Skip to content

Instantly share code, notes, and snippets.

@novel
Last active December 16, 2015 11:49
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 novel/5429964 to your computer and use it in GitHub Desktop.
Save novel/5429964 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
import urllib
import json
URL = "http://beta-api.formspring.me/answered/list/%s"
def formspring_fetch(account, iteration=1, before=None):
url = URL % account
if before:
url += "?before=%s" % before
response = urllib.urlopen(url)
response_data = response.read()
json_data = json.loads(response_data)
if 0 == len(json_data['response']):
print "Done!"
return
output_filename = "%.3d.json" % iteration
with open(output_filename, 'w') as output_fd:
print "Writing data to", output_filename
output_fd.write(response_data)
before = json_data['response'][-1]['id']
iteration += 1
formspring_fetch(account, iteration, before)
if "__main__" == __name__:
if 2 != len(sys.argv):
print >> sys.stderr, "Usage: %s account" % sys.argv[0]
sys.exit(1)
account = sys.argv[1]
formspring_fetch(account)
#!/usr/bin/env python
import sys
import json
import locale
system_encoding = locale.getpreferredencoding()
def load_data(files):
responses = []
for file in files:
with open(file) as fd:
responses += json.loads(fd.read())['response']
return responses
def data_to_html(data):
print "<html><body><div>"
for response in data:
print ("<p><i>%(question)s @ %(time)s</i></p><p>%(answer)s</p>" %
response).encode(system_encoding)
print "</div></body></html>"
if "__main__" == __name__:
if 2 > len(sys.argv):
print >> sys.stderr, "Usage: %s file1 ... fileN" % sys.argv[0]
sys.exit(1)
files = sys.argv[1:]
data = load_data(files)
data_to_html(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment