psaegert's picture
Upload 201 files
2c34d2f
#!/usr/bin/env python3
################################################################################
# File: generate_readme.py
# Version: 0.4
# Purpose: Creates the README.md file for this repo
# Authors: Michael Altfield <michael@michaelaltfield.net>
# Created: 2023-06-06
# Updated: 2023-08-04
################################################################################
################################################################################
# IMPORTS #
################################################################################
import json, csv, numpy, datetime, warnings
import pandas as pd
################################################################################
# SETTINGS #
################################################################################
LEMMY_STATS_CRAWLER_FILENAME = 'lemmy-stats-crawler.json'
LEMMY_STATS_CRAWLER_FILEPATH = 'lemmy-stats-crawler/' + LEMMY_STATS_CRAWLER_FILENAME
UPTIME_FILENAME = 'uptime.json'
AGE_FILENAME = 'age.json'
OUT_CSV = 'awesome-lemmy-instances.csv'
################################################################################
# FUNCTIONS #
################################################################################
# do some checks on text that we get back from the instance's API because it
# might break markdown or do something nasty
def sanitize_text( text ):
# markdown table columns are delimited by pipes
text = text.replace( '|', '' )
# newlines
text = text.replace( "\r", '' )
text = text.replace( "\n", '' )
# commas fuck with our CSV file; replace it with this homoglyph (0x201A)
text = text.replace( ",", '‚' )
return text
################################################################################
# MAIN BODY #
################################################################################
# catch runtime warnings from numpy on 'nan' errors when calculating averages
warnings.filterwarnings("error")
##################
# CHECK SETTINGS #
##############