Skip to content

Instantly share code, notes, and snippets.

@palrogg
Created January 29, 2020 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save palrogg/ebe74275c51488a156d74402327a9f7a to your computer and use it in GitHub Desktop.
Save palrogg/ebe74275c51488a156d74402327a9f7a to your computer and use it in GitHub Desktop.
A few lines to make your_off-facebook_activity.json easier to read
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# requirements: pandas, xlrd
import pandas as pd
import json
with open('your_off-facebook_activity.json', encoding='utf-8') as f:
data = json.load(f)
# unnest data
rows = []
for provider in data['off_facebook_activity']:
for item in provider['events']:
item['name'] = provider['name']
rows.append(item)
# Unix timestamp to date and time
df = pd.DataFrame(rows)
df['date'] = pd.to_datetime(df['timestamp'], unit='s')
# Save to Excel using xlrd
df[['name', 'type', 'date', 'timestamp', 'id']].to_excel('events.xlsx', index=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment