fork download
  1. from bs4 import BeautifulSoup
  2. from collections import defaultdict
  3. from datetime import datetime
  4. import matplotlib.pyplot as plt
  5. import argparse
  6.  
  7.  
  8. def main(filename):
  9. with open(filename) as file:
  10. soup = BeautifulSoup(file, "html.parser")
  11.  
  12. counts = defaultdict(int)
  13. timeline_rows = soup.find_all(class_="timelineRow")
  14.  
  15. for timeline_row in timeline_rows:
  16. year = int(timeline_row.find(class_="yearBox").get_text(strip=True))
  17. date_string = timeline_row.find(class_="monthDay").get_text(strip=True)
  18. full_date_string = f"{date_string} {year}"
  19. date = datetime.strptime(full_date_string, "%B %d %Y")
  20. formatted_date = date.strftime("%Y-%m-%d")
  21. counts[formatted_date] += 1
  22.  
  23. data_points = sorted([(date, count) for date, count in counts.items()])
  24. dates = [datetime.strptime(date_str, "%Y-%m-%d") for date_str, _ in data_points]
  25.  
  26. cumulative_amounts = [data_points[0][1]]
  27. for _, amount in data_points[1:]:
  28. cumulative_amounts.append(cumulative_amounts[-1] + amount)
  29.  
  30. plt.plot(dates, cumulative_amounts, marker="o")
  31. plt.xlabel("Date")
  32. plt.ylabel("Number of total edits up to that day")
  33. plt.title("Cumulative amount of layout edits over 1 year")
  34. plt.xticks(rotation=45)
  35. plt.show()
  36.  
  37.  
  38. if __name__ == "__main__":
  39. parser = argparse.ArgumentParser(description="Plots cumulative editing frequencies for an Oryx layout.")
  40. parser.add_argument("-f", "--filename", help="Name of the HTML file", default="Oryx_ The ZSA Keyboard Configurator.html")
  41. args = parser.parse_args()
  42. main(args.filename)
  43.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python2.7/py_compile.py", line 117, in compile
    raise py_exc
py_compile.PyCompileError:   File "prog.py", line 18
    full_date_string = f"{date_string} {year}"
                                             ^
SyntaxError: invalid syntax

stdout
Standard output is empty