Skip to content

Instantly share code, notes, and snippets.

@vitorio
Last active April 29, 2018 23:19
Show Gist options
  • Save vitorio/1909d198184616d78f882de178611b36 to your computer and use it in GitHub Desktop.
Save vitorio/1909d198184616d78f882de178611b36 to your computer and use it in GitHub Desktop.
Given a Storify username, write the static HTML export URLs for each public story to stdout
#!/usr/bin/python
try:
import simplejson as json
except:
import json
import requests
import math
import sys
import os
if len(sys.argv) != 2:
sys.stderr.write('usage: python dump-storify-static-urls.py <storify_screen_name>\n')
sys.exit(2)
STORIFY_USER = sys.argv[1]
API_URL = 'https://api.storify.com/v1'
STORIFY_API_KEY = ''
STORIFY_PAGINATION = 50
ENDPOINT = "{0}/{1}/{2}?api_key={3}".format(API_URL, 'users', STORIFY_USER, STORIFY_API_KEY)
try:
USER_JSON = requests.get(ENDPOINT).json()
except:
sys.exit('request failure on username\n')
NUM_STORIES = USER_JSON['content']['stats']['stories']
STORY_PAGES = int(math.ceil(NUM_STORIES / STORIFY_PAGINATION)) + 1
STORIES = list()
for page in range(0, STORY_PAGES):
endpoint = "{0}/{1}/{2}?api_key={3}&per_page={4}&page={5}".format(API_URL, 'stories', STORIFY_USER, STORIFY_API_KEY, STORIFY_PAGINATION, page)
try:
stories_json = requests.get(endpoint).json()
except:
sys.exit('request failure on stories\n')
STORIES.extend(stories_json['content']['stories'])
for story in STORIES:
print '{}{}'.format(story['permalink'], '.html')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment