Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- from matplotlib.patches import Rectangle
- from collections import Counter
- 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
- """
- Firstname Lastname (yyyy-mm-dd)
- Firstname Lastname (yyyy-mm-dd)
- Firstname Lastname (yyyy-mm-dd)
- Firstname Lastname (yyyy-mm-dd)
- """
- # that should be pretty straight fwd. just replace the </li><li> with a
- # newline
- # now save it in same folder as this scirpt:
- # - ppl_added.txt
- # - ppl_removed.txt
- # run with >python3 main.py
- 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()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement