From 02cbd69a31cdefb608d0fe925cd4328788d0bbee Mon Sep 17 00:00:00 2001 From: m33m33 <m33@tok715.net> Date: Wed, 10 Mar 2021 13:59:05 +0100 Subject: [PATCH] update to use a generic nitter instance --- tootbot.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/tootbot.py b/tootbot.py index 626d14f..e4442b3 100755 --- a/tootbot.py +++ b/tootbot.py @@ -16,15 +16,11 @@ mastodon_api = None # Set to 1 to get some messages, 0 for error messages only debug=0 -# Posting delay (s), wait between mastodon posts, reduces the "burst" effect on timoeline, and instance workload if you hit rate limiters +# Posting delay (s), wait between mastodon posts, reduces the "burst" effect on timeline, and instance workload if you hit rate limiters posting_delay=3 # Post only this much tweets per cycle -max_tweets=2 - -# URL substrings dedicated to source image hosting -twitter_pics_hosting="https://pbs.twitimg.com/" -nitter_pics_hosting="https://nitter.net/pic/" +max_tweets=15 # Program logic below this line @@ -39,6 +35,10 @@ days = int(sys.argv[3]) tags = sys.argv[4] delay = int(sys.argv[5]) +# URL substrings dedicated to source image hosting +twitter_pics_hosting="https://pbs.twitimg.com/" +nitter_pics_hosting=source.split('/search', 1)[0] + "/pic/" + # Returns the parameter from the specified file def get_config(parameter, file_path): # Check if secrets file exists @@ -155,13 +155,15 @@ for tweet in reversed(d.entries): # get the pictures... from nitter if nitter_pics_hosting in tweet.summary: - for p in re.finditer(r"https://nitter.net/pic/[^ \xa0\"]*", tweet.summary): - try: - media = requests.get(p.group(0)) - media_posted = mastodon_api.media_post(media.content, mime_type=media.headers.get('content-type')) - toot_media.append(media_posted['id']) - except: - print("ERROR: Can't get media !") + for line in tweet.summary.split('\n'): + if nitter_pics_hosting in line: + pic=re.search("(?P<url>https?://[^\s'\"]+)", line).group("url") + try: + media = requests.get(pic) + media_posted = mastodon_api.media_post(media.content, mime_type=media.headers.get('content-type')) + toot_media.append(media_posted['id']) + except: + print("ERROR: Can't get media !") # replace short links by original URL m = re.search(r"http[^ \xa0]*", toot_body) -- GitLab