Skip to content

Instantly share code, notes, and snippets.

@cleverdevil
Last active March 6, 2018 00:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cleverdevil/f33530706d6e8dacd13a8bd8e8c15dba to your computer and use it in GitHub Desktop.
Save cleverdevil/f33530706d6e8dacd13a8bd8e8c15dba to your computer and use it in GitHub Desktop.
Transform Facebook JSON exports to MF2 JSON
#!/usr/bin/env python
'''
Usage:
./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:
https://github.com/danburzo/fb-export
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:
mf2_file.write(mf2_json)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment