Skip to content

Instantly share code, notes, and snippets.

@Fooftilly
Last active September 30, 2023 16:03
Show Gist options
  • Save Fooftilly/aceee612f317b8035a76d6025951dbcb to your computer and use it in GitHub Desktop.
Save Fooftilly/aceee612f317b8035a76d6025951dbcb to your computer and use it in GitHub Desktop.
Retrive stats by username. Run warrior-reddit-stats.py username to get your stats.
import requests
import json
import argparse
import logging
from datetime import datetime
def get_downloader_stats(username):
# The URL of the JSON data
url = 'https://legacy-api.arpa.li/reddit/stats.json'
# Sending a GET request to download the JSON data
response = requests.get(url)
# Getting the current timestamp
timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
# Checking if the request was successful
if response.status_code == 200:
# Parsing the JSON data
data = json.loads(response.text)
# Checking if the specified username exists in the downloader_bytes and downloader_count dictionaries
if username in data['downloader_bytes'] and username in data['downloader_count']:
# Extracting the "downloader_bytes" and "downloader_count" for the specified username
downloader_bytes = data['downloader_bytes'][username]
downloader_count = data['downloader_count'][username]
# Converting bytes to GB (1 Byte = 1 / (1024 * 1024 * 1024) GB)
downloader_bytes_gb = downloader_bytes / (1024 * 1024 * 1024)
log_message = f'{timestamp}: {username} has downloaded {downloader_count} items, totaling {downloader_bytes_gb:.2f} GB.'
print(log_message)
logging.info(log_message)
else:
log_message = f'{timestamp}: {username} not found in the downloader bytes/count data.'
print(log_message)
logging.warning(log_message)
else:
log_message = f'{timestamp}: Failed to download the JSON data.'
print(log_message)
logging.error(log_message)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Get download stats for a specified Reddit downloader.')
parser.add_argument('username', type=str, help='The username of the downloader.')
args = parser.parse_args()
# Configuring the logging module to write log messages to a file
logging.basicConfig(filename='stats_reddit', level=logging.INFO, format='%(message)s')
get_downloader_stats(args.username)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment