diff --git a/README.md b/README.md index 04d5170e..130eb00c 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,8 @@ On Arch/Parabola: sudo pacman -S tor python-pip python-pysocks python-pycryptodome \ imagemagick python-pillow python-requests \ perl-image-exiftool python-numpy python-dateutil \ - python-qrcode python-png certbot flake8 -suso pip3 install pyLD + certbot flake8 +sudo pip3 install pyLD pyqrcode pypng ``` Or on Debian: diff --git a/deploy/i2p b/deploy/i2p index 23ec38c3..47a2ea8b 100755 --- a/deploy/i2p +++ b/deploy/i2p @@ -57,8 +57,8 @@ if [ -f /usr/bin/pacman ]; then pacman -S --noconfirm python-pip python-pysocks python-pycryptodome \ imagemagick python-pillow python-requests \ perl-image-exiftool python-numpy python-dateutil \ - python-qrcode certbot flake8 git i2pd wget qrencode - pip3 install pyLD + certbot flake8 git i2pd wget qrencode + pip3 install pyLD pyqrcode pypng else apt-get update apt-get -y install imagemagick python3-crypto python3-pycryptodome \ diff --git a/deploy/onion b/deploy/onion index b2d076c5..6c1093c0 100755 --- a/deploy/onion +++ b/deploy/onion @@ -38,8 +38,8 @@ if [ -f /usr/bin/pacman ]; then pacman -S --noconfirm tor python-pip python-pysocks python-pycryptodome \ imagemagick python-pillow python-requests \ perl-image-exiftool python-numpy python-dateutil \ - python-qrcode certbot flake8 git qrencode - pip3 install pyLD + certbot flake8 git qrencode + pip3 install pyLD pyqrcode pypng else apt-get update apt-get -y install imagemagick python3-crypto python3-pycryptodome \ diff --git a/tests.py b/tests.py index d062c337..906f6f42 100644 --- a/tests.py +++ b/tests.py @@ -31,6 +31,7 @@ from follow import clearFollows from follow import clearFollowers from follow import sendFollowRequestViaServer from follow import sendUnfollowRequestViaServer +from utils import siteIsActive from utils import updateRecentPostsCache from utils import followPerson from utils import getNicknameFromActor @@ -1858,8 +1859,15 @@ def testJsonld(): assert(jsonldVerify(signedDocument, publicKeyPem)) +def testSiteIsActive(): + print('testSiteIsActive') + assert(siteIsActive('https://mastodon.social')) + assert(not siteIsActive('https://notarealwebsite.a.b.c')) + + def runAllTests(): print('Running tests...') + testSiteIsActive() testJsonld() testRemoveTextFormatting() testWebLinks() diff --git a/utils.py b/utils.py index b310735e..881f75e4 100644 --- a/utils.py +++ b/utils.py @@ -11,6 +11,8 @@ import time import shutil import datetime import json +from urllib.request import urlopen +from urllib.request import URLError from pprint import pprint from calendar import monthrange @@ -1066,3 +1068,15 @@ def updateAnnounceCollection(recentPostsCache: {}, print('DEBUG: saving post with shares (announcements) added') pprint(postJsonObject) saveJson(postJsonObject, postFilename) + + +def siteIsActive(url: str) -> bool: + """Returns true if the current url is resolvable. + This can be used to check that an instance is online before + trying to send posts to it. + """ + try: + urlopen(url, timeout=10) + return True + except URLError as err: + return False