Skip to content

Instantly share code, notes, and snippets.

@Mekapiku
Last active December 19, 2016 13:30
Show Gist options
  • Save Mekapiku/937a761cd2b17e3b1e254dc25c2c95ab to your computer and use it in GitHub Desktop.
Save Mekapiku/937a761cd2b17e3b1e254dc25c2c95ab to your computer and use it in GitHub Desktop.
Narrative Clip の moment を上手いこと gif動画 にしてくれるやつ
import os, requests, shutil, json
api_result = {}
session = requests.Session()
# get access_token
url = "https://narrativeapp.com/oauth2/token/"
email = "Your Email Address"
password = "Your Password"
params = {"grant_type":"password","client_id":"osx","email": email, "password":password}
auth = json.loads(session.post(url, params).text)
session.headers.update({"Authorization": "Bearer " + str(auth["access_token"])})
# access moment api
r = session.get("https://narrativeapp.com/api/v2/moments/")
assert r.status_code == 200
ret = json.loads(r.text)
# get all moment photos url
moments = ret["results"]
for m in moments:
api_result[m["uuid"]] = []
r = session.get(m["photos_url"])
assert r.status_code == 200
moment_photos = json.loads(r.text)
for p in moment_photos["results"]:
api_result[m["uuid"]].append(p["renders"]["g1_smartphone"]["url"])
# download photos
for k, v in api_result.items():
os.mkdir(k)
for i, img in enumerate(v):
res = requests.get(img, stream=True)
with open(k + "/" + "{0:03d}".format(i) + ".jpg", "wb") as fp:
shutil.copyfileobj(res.raw, fp)
# make gif animation
for k in api_result.keys():
os.system("convert -layers optimize -loop 0 -delay 40 %s/*.jpg %s/anim.gif" % (k, k))
print "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment