From 1ec03c7d81abc6416a60b2ee76ea0f1a6ee2bcfc Mon Sep 17 00:00:00 2001 From: JC Francois Date: Sat, 31 Aug 2019 20:30:40 +0200 Subject: [PATCH] Added tolerance for ConnectionError when visiting linked page to extract picture --- twoot.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/twoot.py b/twoot.py index 310fa01..fc349ee 100755 --- a/twoot.py +++ b/twoot.py @@ -219,12 +219,15 @@ def main(argv): m = re.search(r"http[^ \n\xa0]*", tweet_text) if m is not None: link_url = m.group(0) - r = requests.get(link_url) - if r.status_code == 200: - # Matches the first instance of either twitter:image or twitter:image:src meta tag - match = re.search(r'', r.text) - if match is not None: - photos.append(match.group(1)) + try: + r = requests.get(link_url) + if r.status_code == 200: + # Matches the first instance of either twitter:image or twitter:image:src meta tag + match = re.search(r'', r.text) + if match is not None: + photos.append(match.group(1)) + except ConnectionError: + pass # Add dictionary with content of tweet to list tweet = {