Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. from matplotlib.patches import Rectangle
  3. from collections import Counter
  4. import datetime as td
  5.  
  6.  
  7. # In case anyone wants to try this themselves:
  8. # Download your facebook zipped facebook history.
  9. # There you'll find a file named fiends.html
  10. # Format the paragraph with "added friends" / "deleted friends" to look like
  11. """
  12. Firstname Lastname (yyyy-mm-dd)
  13. Firstname Lastname (yyyy-mm-dd)
  14. Firstname Lastname (yyyy-mm-dd)
  15. Firstname Lastname (yyyy-mm-dd)
  16. """
  17. # that should be pretty straight fwd. just replace the </li><li> with a
  18. # newline
  19.  
  20. # now save it in same folder as this scirpt:
  21. # - ppl_added.txt
  22. # - ppl_removed.txt
  23. # run with >python3 main.py
  24.  
  25. def month_to_num(m):
  26. return{
  27. 'January' : 1,
  28. 'February' : 2,
  29. 'March' : 3,
  30. 'April' : 4,
  31. 'May' : 5,
  32. 'June' : 6,
  33. 'July' : 7,
  34. 'August' : 8,
  35. 'September' : 9,
  36. 'October' : 10,
  37. 'November' : 11,
  38. 'December' : 12
  39. }[m]
  40.  
  41.  
  42. def get_dates_from_file(filename):
  43. added=[]
  44. with open(filename, 'r') as f:
  45. for s in f:
  46. date = (s[s.find("(")+1:s.find(")")]).split()
  47. month = month_to_num(date[1])
  48. added.append(td.date(int(date[2]), int(month), int(date[0])))
  49. return added
  50.  
  51.  
  52. added_file = 'ppl_added.txt'
  53. removed_file = 'ppl_removed.txt'
  54.  
  55. added = get_dates_from_file(added_file)
  56. removed = get_dates_from_file(removed_file)
  57.  
  58.  
  59. plt.hist(removed, bins=7*4, alpha=0.6, align='mid', color='red', label='removed')
  60. plt.hist(added, bins=7*4, alpha=0.3, align='mid', color='blue', label='added')
  61. plt.title("Friends added/removed on facebook")
  62. plt.ylabel("# friends")
  63. plt.xlabel("Year")
  64. plt.legend(loc='upper right')
  65.  
  66. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement