From ae1ce9080f478bdc7612e012ec37937c3655095a Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 23 Nov 2019 10:28:36 +0000 Subject: [PATCH] Remove commentjson entirely --- README.md | 3 +-- utils.py | 29 ++++------------------------- website/index.html | 2 +- 3 files changed, 6 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index b4dd1637..0cf01cae 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,6 @@ On Arch/Parabola: sudo pacman -S tor python-pip python-pysocks python-pycryptodome \ python-beautifulsoup4 imagemagick python-pillow \ python-numpy python-dateutil certbot -sudo pip install commentjson ``` Or on Debian: @@ -30,7 +29,7 @@ sudo apt-get -y install tor python3-pip python3-socks imagemagick \ python3-numpy python3-setuptools python3-crypto \ python3-dateutil python3-pil.imagetk python3-idna \ certbot nginx -sudo pip3 install requests commentjson beautifulsoup4 pycryptodome +sudo pip3 install requests beautifulsoup4 pycryptodome ``` ## Installation diff --git a/utils.py b/utils.py index f2eb31ce..b4b48bc6 100644 --- a/utils.py +++ b/utils.py @@ -11,7 +11,6 @@ import time import shutil import datetime import json -import commentjson def saveJson(jsonObject: {},filename: str) -> bool: """Saves json to a file @@ -36,7 +35,8 @@ def loadJson(filename: str,delaySec=2) -> {}: while tries<5: try: with open(filename, 'r') as fp: - jsonObject=commentjson.load(fp) + data=fp.read() + jsonObject=json.loads(data) break except: print('WARN: loadJson exception') @@ -122,17 +122,7 @@ def getDisplayName(baseDir: str,actor: str,personCache: {}) -> str: # Try to obtain from the cached actors cachedActorFilename=baseDir+'/cache/actors/'+actor.replace('/','#')+'.json' if os.path.isfile(cachedActorFilename): - actorJson=None - tries=0 - while tries<5: - try: - with open(cachedActorFilename, 'r') as fp: - actorJson=commentjson.load(fp) - break - except: - print('WARN: getDisplayName') - time.sleep(1) - tries+=1 + actorJson=loadJson(cachedActorFilename,1) if actorJson: if actorJson.get('name'): return(actorJson['name']) @@ -310,18 +300,7 @@ def removeModerationPostFromIndex(baseDir: str,postUrl: str,debug: bool) -> None def deletePost(baseDir: str,httpPrefix: str,nickname: str,domain: str,postFilename: str,debug: bool) -> None: """Recursively deletes a post and its replies and attachments """ - postJsonObject=None - tries=0 - while tries<5: - try: - with open(postFilename, 'r') as fp: - postJsonObject=commentjson.load(fp) - break - except: - print('WARN: deletePost') - time.sleep(1) - tries+=1 - + postJsonObject=loadJson(postFilename,1) if postJsonObject: # don't allow deletion of bookmarked posts bookmarksIndexFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/bookmarks.index' diff --git a/website/index.html b/website/index.html index 7282cbb5..7852bfd7 100644 --- a/website/index.html +++ b/website/index.html @@ -1226,7 +1226,7 @@

On a Debian based system:

sudo apt-get -y install tor python3-pip python3-socks imagemagick python3-numpy python3-setuptools python3-crypto python3-dateutil python3-pil.imagetk python3-idna certbot nginx

-

sudo pip3 install commentjson beautifulsoup4 pycryptodome

+

sudo pip3 install beautifulsoup4 pycryptodome