From 30a0c2a2739fe9545f70fcd1fa00bcb2d6d8ff9a Mon Sep 17 00:00:00 2001 From: Antonia Date: Wed, 27 Jul 2022 23:41:18 +0200 Subject: [PATCH] pass 'random' as argument to post a random comic that has not been published before --- noseears.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/noseears.py b/noseears.py index 2fde6c1..061fc1e 100644 --- a/noseears.py +++ b/noseears.py @@ -27,6 +27,8 @@ from bs4 import BeautifulSoup import os from mastodon import Mastodon import re +import random + instance = "https://botsin.space" baseurl = "https://wuzzy.neocities.org" @@ -36,7 +38,12 @@ seendir = os.path.join(datadir, "seen") if len(sys.argv) > 1 : - page = request.urlopen(baseurl+"/comic/"+sys.argv[1]) + n = sys.argv[1] + if sys.argv[1] == "random" : + # try posting a random comic + l = max([int(re.sub("[^0-9]", "", i)) for i in os.listdir(seendir)]) + n = str(random.randint(1, l)) + page = request.urlopen(baseurl+"/comic/"+n) else: page = request.urlopen(baseurl)