Skip to content

Instantly share code, notes, and snippets.

@SteveHere
Created October 28, 2025 05:23
Show Gist options
  • Save SteveHere/d3ff15fc93ba82b8e5390fb8dab09dcc to your computer and use it in GitHub Desktop.
Save SteveHere/d3ff15fc93ba82b8e5390fb8dab09dcc to your computer and use it in GitHub Desktop.
Dead simple subreddit subscriber count retriever
from typing import Callable
from time import sleep
from datetime import datetime
from urllib.request import urlopen
import json
def strict_input(print_str: str, input_check: Callable[[str], bool]) -> str:
while True:
temp = input(print_str)
try:
if input_check(temp):
return temp
print(f"Incorrect input.")
except Exception as e:
print(f"Cannot parse {temp}: {e}")
def main():
try:
subreddit = strict_input("Enter the subreddit's name: ", lambda s: len(s) > 0)
full_url = f"https://old.reddit.com/r/{subreddit}/about.json"
print(f"Sub count for r/{subreddit}")
while True:
try:
response = urlopen(full_url).read()
json_resp = json.loads(response)
print(f"""{datetime.now()} --> {json_resp["data"]["subscribers"]}""")
except Exception as e:
print(f"Error --> {e}")
# Subscriber counts for subreddits don't change very often
# Once per minute is more than enough
sleep(60)
except KeyboardInterrupt:
print("Exiting script")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment