💾 Archived View for makeworld.space › gus-graph › script.py captured on 2023-01-29 at 16:00:44.
⬅️ Previous capture (2021-12-03)
-=-=-=-=-=-=-
#!/usr/bin/python3 # This script is under the MIT license. # https://mit-license.org/ # It was written by makeworld, in July 2020, and is under his copyright. # Last updated: 2020-09-04 # It is designed to be run daily, using cron or something similar. # Install gusmobile with this command: # pip3 install --user git+https://git.sr.ht/\~natpen/gusmobile@np/gus-hack#egg=gusmobile # The --user part is optional. import sys from datetime import date import gusmobile as gm import matplotlib.pyplot as plt from matplotlib.dates import DayLocator res = gm.fetch("gemini://gus.guru/statistics/historical/overall") if res is None or res.status != "20": print("GUS did not return status 20, aborting.") sys.exit(1) lines = res.content.splitlines()[11:] # Skip straight to content if lines[0] != "2020-05-09 | 3014 | 26": print("GUS page content has changed, code must be updated.") sys.exit(1) dates = [] page_counts = [] domain_counts = [] for line in lines: if line.count("|") != 2: # Not a table line anymore, data has stopped break # cells = [date, page count, domain count] cells = [x.strip() for x in line.split("|")] dates.append(date.fromisoformat(cells[0])) page_counts.append(int(cells[1])) domain_counts.append(int(cells[2])) fig, ax1 = plt.subplots() color = "orange" ax1.set_xlabel("Date") ax1.set_ylabel('# of pages', color=color) ax1.plot(dates, page_counts, label="# of pages", color=color) ax1.tick_params(axis='y', labelcolor=color) ax2 = ax1.twinx() # instantiate a second axes that shares the same x-axis color = "blue" ax2.set_ylabel('# of domains', color=color) ax2.tick_params(axis='y', labelcolor=color) ax2.plot(dates, domain_counts, label="# of domains", color=color) # Date formatting fig.autofmt_xdate() ax1.xaxis.set_minor_locator(DayLocator()) # Output fig.set_size_inches(16, 8) fig.legend() fig.tight_layout() plt.title("GUS Gemini Domain and Page Statistics Over Time") plt.savefig("graph.png", dpi=100, bbox_inches='tight')