Skip to content

Instantly share code, notes, and snippets.

Last active March 6, 2018 00:54
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Transform Facebook JSON exports to MF2 JSON
#!/usr/bin/env python
./transform <path-to-facebook-export.json>
This will transform everything using granary and then place
individual files into a directory called "mf2."
You can generate a full export from Facebook using this project:
Happy freedom from Facebook :)
import json
import sys
import os
from granary import microformats2, facebook
from granary.facebook import Facebook
facebook = Facebook()
if __name__ == '__main__':
posts = json.loads(open(sys.argv[1], 'r').read())
os.system('mkdir -p mf2')
for post in posts:
mf2 = microformats2.object_to_json(facebook.post_to_object(post))
mf2_json = json.dumps(mf2, indent=2)
with open('mf2/%s.json' % mf2['properties']['published'][0], 'wb') as mf2_file:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment