Last active
March 6, 2018 00:54
-
-
Save cleverdevil/f33530706d6e8dacd13a8bd8e8c15dba to your computer and use it in GitHub Desktop.
Transform Facebook JSON exports to MF2 JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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