Skip to content

Instantly share code, notes, and snippets.

@f-ilic
Last active August 23, 2017 15:59
Show Gist options
  • Save f-ilic/a5e99ca20b499e2ed478a77452887e70 to your computer and use it in GitHub Desktop.
Save f-ilic/a5e99ca20b499e2ed478a77452887e70 to your computer and use it in GitHub Desktop.
fb friend addition/removal plot
import matplotlib.pyplot as plt
import datetime as td
# In case anyone wants to try this themselves:
# Download your facebook zipped facebook history.
# There you'll find a file named fiends.html
# Format the paragraph with "added friends" / "deleted friends" to look like
# replacing </li><li> with newline
"""
Firstname Lastname (yyyy-mm-dd)
Firstname Lastname (yyyy-mm-dd)
Firstname Lastname (yyyy-mm-dd)
Firstname Lastname (yyyy-mm-dd)
"""
# and save as
# - ppl_added.txt
# - ppl_removed.txt
def month_to_num(m):
return{
'January' : 1,
'February' : 2,
'March' : 3,
'April' : 4,
'May' : 5,
'June' : 6,
'July' : 7,
'August' : 8,
'September' : 9,
'October' : 10,
'November' : 11,
'December' : 12
}[m]
def get_dates_from_file(filename):
added=[]
with open(filename, 'r') as f:
for s in f:
date = (s[s.find("(")+1:s.find(")")]).split()
month = month_to_num(date[1])
added.append(td.date(int(date[2]), int(month), int(date[0])))
return added
added_file = 'ppl_added.txt'
removed_file = 'ppl_removed.txt'
added = get_dates_from_file(added_file)
removed = get_dates_from_file(removed_file)
plt.hist(removed, bins=7*4, alpha=0.6, align='mid', color='red', label='removed')
plt.hist(added, bins=7*4, alpha=0.3, align='mid', color='blue', label='added')
plt.title("Friends added/removed on facebook")
plt.ylabel("# friends")
plt.xlabel("Year")
plt.legend(loc='upper right')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment