from bs4 import BeautifulSoup
from collections import defaultdict
from datetime import datetime
import matplotlib.pyplot as plt
import argparse
def main(filename):
with open(filename) as file:
soup = BeautifulSoup(file, "html.parser")
counts = defaultdict(int)
timeline_rows = soup.find_all(class_="timelineRow")
for timeline_row in timeline_rows:
year = int(timeline_row.find(class_="yearBox").get_text(strip=True))
date_string = timeline_row.find(class_="monthDay").get_text(strip=True)
full_date_string = f"{date_string} {year}"
date = datetime.strptime(full_date_string, "%B %d %Y")
formatted_date = date.strftime("%Y-%m-%d")
counts[formatted_date] += 1
data_points = sorted([(date, count) for date, count in counts.items()])
dates = [datetime.strptime(date_str, "%Y-%m-%d") for date_str, _ in data_points]
cumulative_amounts = [data_points[0][1]]
for _, amount in data_points[1:]:
cumulative_amounts.append(cumulative_amounts[-1] + amount)
plt.plot(dates, cumulative_amounts, marker="o")
plt.xlabel("Date")
plt.ylabel("Number of total edits up to that day")
plt.title("Cumulative amount of layout edits over 1 year")
plt.xticks(rotation=45)
plt.show()
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Plots cumulative editing frequencies for an Oryx layout.")
parser.add_argument("-f", "--filename", help="Name of the HTML file", default="Oryx_ The ZSA Keyboard Configurator.html")
args = parser.parse_args()
main(args.filename)