mirror of https://gitlab.com/bashrc2/epicyon
Reading functions
parent
feb4286031
commit
ee0ffade9d
6
blog.py
6
blog.py
|
@ -28,6 +28,7 @@ from utils import firstParagraphFromString
|
||||||
from posts import createBlogsTimeline
|
from posts import createBlogsTimeline
|
||||||
from newswire import rss2Header
|
from newswire import rss2Header
|
||||||
from newswire import rss2Footer
|
from newswire import rss2Footer
|
||||||
|
from storage import readWholeFile
|
||||||
|
|
||||||
|
|
||||||
def _noOfBlogReplies(baseDir: str, httpPrefix: str, translate: {},
|
def _noOfBlogReplies(baseDir: str, httpPrefix: str, translate: {},
|
||||||
|
@ -744,8 +745,9 @@ def htmlEditBlog(mediaInstance: bool, translate: {},
|
||||||
editBlogText = '<h1">' + translate['Write your post text below.'] + '</h1>'
|
editBlogText = '<h1">' + translate['Write your post text below.'] + '</h1>'
|
||||||
|
|
||||||
if os.path.isfile(baseDir + '/accounts/newpost.txt'):
|
if os.path.isfile(baseDir + '/accounts/newpost.txt'):
|
||||||
with open(baseDir + '/accounts/newpost.txt', 'r') as file:
|
newPostStr = readWholeFile(baseDir + '/accounts/newpost.txt')
|
||||||
editBlogText = '<p>' + file.read() + '</p>'
|
if newPostStr:
|
||||||
|
editBlogText = '<p>' + newPostStr + '</p>'
|
||||||
|
|
||||||
cssFilename = baseDir + '/epicyon-profile.css'
|
cssFilename = baseDir + '/epicyon-profile.css'
|
||||||
if os.path.isfile(baseDir + '/epicyon.css'):
|
if os.path.isfile(baseDir + '/epicyon.css'):
|
||||||
|
|
|
@ -25,6 +25,7 @@ from utils import saveJson
|
||||||
from posts import getPersonBox
|
from posts import getPersonBox
|
||||||
from session import postJson
|
from session import postJson
|
||||||
from storage import storeValue
|
from storage import storeValue
|
||||||
|
from storage import readWholeFile
|
||||||
|
|
||||||
|
|
||||||
def undoBookmarksCollectionEntry(recentPostsCache: {},
|
def undoBookmarksCollectionEntry(recentPostsCache: {},
|
||||||
|
@ -59,9 +60,8 @@ def undoBookmarksCollectionEntry(recentPostsCache: {},
|
||||||
bookmarkIndex = bookmarkIndex.replace('\n', '').replace('\r', '')
|
bookmarkIndex = bookmarkIndex.replace('\n', '').replace('\r', '')
|
||||||
if bookmarkIndex not in open(bookmarksIndexFilename).read():
|
if bookmarkIndex not in open(bookmarksIndexFilename).read():
|
||||||
return
|
return
|
||||||
indexStr = ''
|
indexStr = readWholeFile(bookmarksIndexFilename)
|
||||||
with open(bookmarksIndexFilename, 'r') as indexFile:
|
indexStr = indexStr.replace(bookmarkIndex + '\n', '')
|
||||||
indexStr = indexFile.read().replace(bookmarkIndex + '\n', '')
|
|
||||||
storeValue(bookmarksIndexFilename, indexStr, 'writeonly')
|
storeValue(bookmarksIndexFilename, indexStr, 'writeonly')
|
||||||
|
|
||||||
if not postJsonObject.get('type'):
|
if not postJsonObject.get('type'):
|
||||||
|
|
|
@ -10,6 +10,7 @@ __module_group__ = "RSS Feeds"
|
||||||
import os
|
import os
|
||||||
import datetime
|
import datetime
|
||||||
from storage import storeValue
|
from storage import storeValue
|
||||||
|
from storage import readWholeFile
|
||||||
|
|
||||||
|
|
||||||
def getHashtagCategory(baseDir: str, hashtag: str) -> str:
|
def getHashtagCategory(baseDir: str, hashtag: str) -> str:
|
||||||
|
@ -24,8 +25,7 @@ def getHashtagCategory(baseDir: str, hashtag: str) -> str:
|
||||||
if not os.path.isfile(categoryFilename):
|
if not os.path.isfile(categoryFilename):
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
with open(categoryFilename, 'r') as fp:
|
categoryStr = readWholeFile(categoryFilename)
|
||||||
categoryStr = fp.read()
|
|
||||||
if categoryStr:
|
if categoryStr:
|
||||||
return categoryStr
|
return categoryStr
|
||||||
return ''
|
return ''
|
||||||
|
@ -53,12 +53,10 @@ def getHashtagCategories(baseDir: str,
|
||||||
hashtag = f.split('.')[0]
|
hashtag = f.split('.')[0]
|
||||||
if len(hashtag) > maxTagLength:
|
if len(hashtag) > maxTagLength:
|
||||||
continue
|
continue
|
||||||
with open(categoryFilename, 'r') as fp:
|
categoryStr = readWholeFile(categoryFilename)
|
||||||
categoryStr = fp.read()
|
|
||||||
|
|
||||||
if not categoryStr:
|
if not categoryStr:
|
||||||
continue
|
continue
|
||||||
|
if categoryStr:
|
||||||
if category:
|
if category:
|
||||||
# only return a dictionary for a specific category
|
# only return a dictionary for a specific category
|
||||||
if categoryStr != category:
|
if categoryStr != category:
|
||||||
|
|
4
city.py
4
city.py
|
@ -12,6 +12,7 @@ import datetime
|
||||||
import random
|
import random
|
||||||
import math
|
import math
|
||||||
from random import randint
|
from random import randint
|
||||||
|
from storage import readWholeFile
|
||||||
|
|
||||||
# states which the simulated city dweller can be in
|
# states which the simulated city dweller can be in
|
||||||
PERSON_SLEEP = 0
|
PERSON_SLEEP = 0
|
||||||
|
@ -294,8 +295,7 @@ def getSpoofedCity(city: str, baseDir: str, nickname: str, domain: str) -> str:
|
||||||
cityFilename = baseDir + '/accounts/' + \
|
cityFilename = baseDir + '/accounts/' + \
|
||||||
nickname + '@' + domain + '/city.txt'
|
nickname + '@' + domain + '/city.txt'
|
||||||
if os.path.isfile(cityFilename):
|
if os.path.isfile(cityFilename):
|
||||||
with open(cityFilename, 'r') as fp:
|
city = readWholeFile(cityFilename).replace('\n', '')
|
||||||
city = fp.read().replace('\n', '')
|
|
||||||
return city
|
return city
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ from utils import dangerousMarkup
|
||||||
from utils import isPGPEncrypted
|
from utils import isPGPEncrypted
|
||||||
from utils import containsPGPPublicKey
|
from utils import containsPGPPublicKey
|
||||||
from petnames import getPetName
|
from petnames import getPetName
|
||||||
|
from storage import readWholeFile
|
||||||
|
|
||||||
|
|
||||||
def removeHtmlTag(htmlStr: str, tag: str) -> str:
|
def removeHtmlTag(htmlStr: str, tag: str) -> str:
|
||||||
|
@ -169,8 +170,9 @@ def dangerousCSS(filename: str, allowLocalNetworkAccess: bool) -> bool:
|
||||||
if not os.path.isfile(filename):
|
if not os.path.isfile(filename):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
with open(filename, 'r') as fp:
|
content = readWholeFile(filename)
|
||||||
content = fp.read().lower()
|
if content:
|
||||||
|
content = content.lower()
|
||||||
|
|
||||||
cssMatches = ('behavior:', ':expression', '?php', '.php',
|
cssMatches = ('behavior:', ':expression', '?php', '.php',
|
||||||
'google', 'regexp', 'localhost',
|
'google', 'regexp', 'localhost',
|
||||||
|
|
35
daemon.py
35
daemon.py
|
@ -301,6 +301,7 @@ from speaker import getSSMLbox
|
||||||
from city import getSpoofedCity
|
from city import getSpoofedCity
|
||||||
import os
|
import os
|
||||||
from storage import storeValue
|
from storage import storeValue
|
||||||
|
from storage import readWholeFile
|
||||||
|
|
||||||
|
|
||||||
# maximum number of posts to list in outbox feed
|
# maximum number of posts to list in outbox feed
|
||||||
|
@ -665,11 +666,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
# self.send_header('Cache-Control', 'public, max-age=86400')
|
# self.send_header('Cache-Control', 'public, max-age=86400')
|
||||||
etag = None
|
etag = None
|
||||||
if os.path.isfile(mediaFilename + '.etag'):
|
if os.path.isfile(mediaFilename + '.etag'):
|
||||||
try:
|
etag = readWholeFile(mediaFilename + '.etag')
|
||||||
with open(mediaFilename + '.etag', 'r') as etagFile:
|
|
||||||
etag = etagFile.read()
|
|
||||||
except BaseException:
|
|
||||||
pass
|
|
||||||
if not etag:
|
if not etag:
|
||||||
etag = sha1(data).hexdigest() # nosec
|
etag = sha1(data).hexdigest() # nosec
|
||||||
storeValue(mediaFilename + '.etag', etag, 'writeonly')
|
storeValue(mediaFilename + '.etag', etag, 'writeonly')
|
||||||
|
@ -690,12 +687,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
oldEtag = self.headers['If-None-Match']
|
oldEtag = self.headers['If-None-Match']
|
||||||
if os.path.isfile(mediaFilename + '.etag'):
|
if os.path.isfile(mediaFilename + '.etag'):
|
||||||
# load the etag from file
|
# load the etag from file
|
||||||
currEtag = ''
|
currEtag = readWholeFile(mediaFilename)
|
||||||
try:
|
|
||||||
with open(mediaFilename, 'r') as etagFile:
|
|
||||||
currEtag = etagFile.read()
|
|
||||||
except BaseException:
|
|
||||||
pass
|
|
||||||
if oldEtag == currEtag:
|
if oldEtag == currEtag:
|
||||||
# The file has not changed
|
# The file has not changed
|
||||||
return True
|
return True
|
||||||
|
@ -1532,12 +1524,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
loginNickname + '@' + domain + '/.salt'
|
loginNickname + '@' + domain + '/.salt'
|
||||||
salt = createPassword(32)
|
salt = createPassword(32)
|
||||||
if os.path.isfile(saltFilename):
|
if os.path.isfile(saltFilename):
|
||||||
try:
|
salt = readWholeFile(saltFilename)
|
||||||
with open(saltFilename, 'r') as fp:
|
|
||||||
salt = fp.read()
|
|
||||||
except Exception as e:
|
|
||||||
print('WARN: Unable to read salt for ' +
|
|
||||||
loginNickname + ' ' + str(e))
|
|
||||||
else:
|
else:
|
||||||
storeValue(saltFilename, salt, 'writeonly')
|
storeValue(saltFilename, salt, 'writeonly')
|
||||||
|
|
||||||
|
@ -13108,11 +13095,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
fileLength = os.path.getsize(mediaFilename)
|
fileLength = os.path.getsize(mediaFilename)
|
||||||
mediaTagFilename = mediaFilename + '.etag'
|
mediaTagFilename = mediaFilename + '.etag'
|
||||||
if os.path.isfile(mediaTagFilename):
|
if os.path.isfile(mediaTagFilename):
|
||||||
try:
|
etag = readWholeFile(mediaTagFilename)
|
||||||
with open(mediaTagFilename, 'r') as etagFile:
|
|
||||||
etag = etagFile.read()
|
|
||||||
except BaseException:
|
|
||||||
pass
|
|
||||||
else:
|
else:
|
||||||
with open(mediaFilename, 'rb') as avFile:
|
with open(mediaFilename, 'rb') as avFile:
|
||||||
mediaBinary = avFile.read()
|
mediaBinary = avFile.read()
|
||||||
|
@ -14856,13 +14839,7 @@ def loadTokens(baseDir: str, tokensDict: {}, tokensLookup: {}) -> None:
|
||||||
if not os.path.isfile(tokenFilename):
|
if not os.path.isfile(tokenFilename):
|
||||||
continue
|
continue
|
||||||
nickname = handle.split('@')[0]
|
nickname = handle.split('@')[0]
|
||||||
token = None
|
token = readWholeFile(tokenFilename)
|
||||||
try:
|
|
||||||
with open(tokenFilename, 'r') as fp:
|
|
||||||
token = fp.read()
|
|
||||||
except Exception as e:
|
|
||||||
print('WARN: Unable to read token for ' +
|
|
||||||
nickname + ' ' + str(e))
|
|
||||||
if not token:
|
if not token:
|
||||||
continue
|
continue
|
||||||
tokensDict[nickname] = token
|
tokensDict[nickname] = token
|
||||||
|
|
|
@ -57,6 +57,7 @@ from bookmarks import sendUndoBookmarkViaServer
|
||||||
from delete import sendDeleteViaServer
|
from delete import sendDeleteViaServer
|
||||||
from person import getActorJson
|
from person import getActorJson
|
||||||
from storage import storeValue
|
from storage import storeValue
|
||||||
|
from storage import readWholeFile
|
||||||
|
|
||||||
|
|
||||||
def _desktopHelp() -> None:
|
def _desktopHelp() -> None:
|
||||||
|
@ -284,8 +285,7 @@ def _desktopShowBanner() -> None:
|
||||||
bannerFilename = 'theme/' + bannerTheme + '/banner.txt'
|
bannerFilename = 'theme/' + bannerTheme + '/banner.txt'
|
||||||
if not os.path.isfile(bannerFilename):
|
if not os.path.isfile(bannerFilename):
|
||||||
return
|
return
|
||||||
with open(bannerFilename, 'r') as bannerFile:
|
banner = readWholeFile(bannerFilename)
|
||||||
banner = bannerFile.read()
|
|
||||||
if banner:
|
if banner:
|
||||||
print(banner + '\n')
|
print(banner + '\n')
|
||||||
|
|
||||||
|
|
14
follow.py
14
follow.py
|
@ -31,6 +31,8 @@ from auth import createBasicAuthHeader
|
||||||
from session import getJson
|
from session import getJson
|
||||||
from session import postJson
|
from session import postJson
|
||||||
from storage import storeValue
|
from storage import storeValue
|
||||||
|
from storage import readWholeFile
|
||||||
|
from storage import readFileLines
|
||||||
|
|
||||||
|
|
||||||
def createInitialLastSeen(baseDir: str, httpPrefix: str) -> None:
|
def createInitialLastSeen(baseDir: str, httpPrefix: str) -> None:
|
||||||
|
@ -49,8 +51,8 @@ def createInitialLastSeen(baseDir: str, httpPrefix: str) -> None:
|
||||||
lastSeenDir = accountDir + '/lastseen'
|
lastSeenDir = accountDir + '/lastseen'
|
||||||
if not os.path.isdir(lastSeenDir):
|
if not os.path.isdir(lastSeenDir):
|
||||||
os.mkdir(lastSeenDir)
|
os.mkdir(lastSeenDir)
|
||||||
with open(followingFilename, 'r') as fp:
|
followingHandles = readFileLines(followingFilename)
|
||||||
followingHandles = fp.readlines()
|
if followingHandles:
|
||||||
for handle in followingHandles:
|
for handle in followingHandles:
|
||||||
if '#' in handle:
|
if '#' in handle:
|
||||||
continue
|
continue
|
||||||
|
@ -214,9 +216,7 @@ def isFollowerOfPerson(baseDir: str, nickname: str, domain: str,
|
||||||
|
|
||||||
alreadyFollowing = False
|
alreadyFollowing = False
|
||||||
|
|
||||||
followersStr = ''
|
followersStr = readWholeFile(followersFile)
|
||||||
with open(followersFile, 'r') as fpFollowers:
|
|
||||||
followersStr = fpFollowers.read()
|
|
||||||
|
|
||||||
if handle in followersStr:
|
if handle in followersStr:
|
||||||
alreadyFollowing = True
|
alreadyFollowing = True
|
||||||
|
@ -556,9 +556,7 @@ def _storeFollowRequest(baseDir: str,
|
||||||
if os.path.isfile(followersFilename):
|
if os.path.isfile(followersFilename):
|
||||||
alreadyFollowing = False
|
alreadyFollowing = False
|
||||||
|
|
||||||
followersStr = ''
|
followersStr = readWholeFile(followersFilename)
|
||||||
with open(followersFilename, 'r') as fpFollowers:
|
|
||||||
followersStr = fpFollowers.read()
|
|
||||||
|
|
||||||
if approveHandle in followersStr:
|
if approveHandle in followersStr:
|
||||||
alreadyFollowing = True
|
alreadyFollowing = True
|
||||||
|
|
|
@ -8,6 +8,7 @@ __status__ = "Production"
|
||||||
__module_group__ = "Calendar"
|
__module_group__ = "Calendar"
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
from storage import readWholeFile
|
||||||
from storage import storeValue
|
from storage import storeValue
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,8 +30,7 @@ def receivingCalendarEvents(baseDir: str, nickname: str, domain: str,
|
||||||
if not os.path.isfile(followingFilename):
|
if not os.path.isfile(followingFilename):
|
||||||
return False
|
return False
|
||||||
# create a new calendar file from the following file
|
# create a new calendar file from the following file
|
||||||
with open(followingFilename, 'r') as followingFile:
|
followingHandles = readWholeFile(followingFilename)
|
||||||
followingHandles = followingFile.read()
|
|
||||||
storeValue(calendarFilename, followingHandles, 'writeonly')
|
storeValue(calendarFilename, followingHandles, 'writeonly')
|
||||||
return handle + '\n' in open(calendarFilename).read()
|
return handle + '\n' in open(calendarFilename).read()
|
||||||
|
|
||||||
|
@ -66,14 +66,11 @@ def _receiveCalendarEvents(baseDir: str, nickname: str, domain: str,
|
||||||
followingHandles = ''
|
followingHandles = ''
|
||||||
if os.path.isfile(calendarFilename):
|
if os.path.isfile(calendarFilename):
|
||||||
print('Calendar file exists')
|
print('Calendar file exists')
|
||||||
with open(calendarFilename, 'r') as calendarFile:
|
followingHandles = readWholeFile(calendarFilename)
|
||||||
followingHandles = calendarFile.read()
|
|
||||||
else:
|
else:
|
||||||
# create a new calendar file from the following file
|
# create a new calendar file from the following file
|
||||||
print('Creating calendar file ' + calendarFilename)
|
print('Creating calendar file ' + calendarFilename)
|
||||||
followingHandles = ''
|
followingHandles = readWholeFile(followingFilename)
|
||||||
with open(followingFilename, 'r') as followingFile:
|
|
||||||
followingHandles = followingFile.read()
|
|
||||||
if add:
|
if add:
|
||||||
storeValue(calendarFilename, followingHandles + handle, 'write')
|
storeValue(calendarFilename, followingHandles + handle, 'write')
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ from utils import loadJson
|
||||||
from utils import saveJson
|
from utils import saveJson
|
||||||
from utils import locatePost
|
from utils import locatePost
|
||||||
from storage import storeValue
|
from storage import storeValue
|
||||||
|
from storage import readWholeFile
|
||||||
|
|
||||||
|
|
||||||
def _validUuid(testUuid: str, version=4):
|
def _validUuid(testUuid: str, version=4):
|
||||||
|
@ -35,8 +36,8 @@ def _removeEventFromTimeline(eventId: str, tlEventsFilename: str) -> None:
|
||||||
"""
|
"""
|
||||||
if eventId + '\n' not in open(tlEventsFilename).read():
|
if eventId + '\n' not in open(tlEventsFilename).read():
|
||||||
return
|
return
|
||||||
with open(tlEventsFilename, 'r') as fp:
|
eventsTimeline = readWholeFile(tlEventsFilename)
|
||||||
eventsTimeline = fp.read().replace(eventId + '\n', '')
|
eventsTimeline = eventsTimeline.replace(eventId + '\n', '')
|
||||||
storeValue(tlEventsFilename, eventsTimeline, 'writeonly')
|
storeValue(tlEventsFilename, eventsTimeline, 'writeonly')
|
||||||
|
|
||||||
|
|
||||||
|
|
8
inbox.py
8
inbox.py
|
@ -84,6 +84,7 @@ from context import hasValidContext
|
||||||
from speaker import updateSpeaker
|
from speaker import updateSpeaker
|
||||||
from announce import isSelfAnnounce
|
from announce import isSelfAnnounce
|
||||||
from storage import storeValue
|
from storage import storeValue
|
||||||
|
from storage import readWholeFile
|
||||||
|
|
||||||
|
|
||||||
def storeHashTags(baseDir: str, nickname: str, postJsonObject: {}) -> None:
|
def storeHashTags(baseDir: str, nickname: str, postJsonObject: {}) -> None:
|
||||||
|
@ -1879,8 +1880,7 @@ def _likeNotify(baseDir: str, domain: str, onionDomain: str,
|
||||||
# was there a previous like notification?
|
# was there a previous like notification?
|
||||||
if os.path.isfile(prevLikeFile):
|
if os.path.isfile(prevLikeFile):
|
||||||
# is it the same as the current notification ?
|
# is it the same as the current notification ?
|
||||||
with open(prevLikeFile, 'r') as fp:
|
prevLikeStr = readWholeFile(prevLikeFile)
|
||||||
prevLikeStr = fp.read()
|
|
||||||
if prevLikeStr == likeStr:
|
if prevLikeStr == likeStr:
|
||||||
return
|
return
|
||||||
storeValue(prevLikeFile, likeStr, 'writeonly')
|
storeValue(prevLikeFile, likeStr, 'writeonly')
|
||||||
|
@ -2108,8 +2108,8 @@ def _updateLastSeen(baseDir: str, handle: str, actor: str) -> None:
|
||||||
daysSinceEpoch = (currTime - datetime.datetime(1970, 1, 1)).days
|
daysSinceEpoch = (currTime - datetime.datetime(1970, 1, 1)).days
|
||||||
# has the value changed?
|
# has the value changed?
|
||||||
if os.path.isfile(lastSeenFilename):
|
if os.path.isfile(lastSeenFilename):
|
||||||
with open(lastSeenFilename, 'r') as lastSeenFile:
|
daysSinceEpochFile = readWholeFile(lastSeenFilename)
|
||||||
daysSinceEpochFile = lastSeenFile.read()
|
if daysSinceEpochFile:
|
||||||
if int(daysSinceEpochFile) == daysSinceEpoch:
|
if int(daysSinceEpochFile) == daysSinceEpoch:
|
||||||
# value hasn't changed, so we can save writing anything to file
|
# value hasn't changed, so we can save writing anything to file
|
||||||
return
|
return
|
||||||
|
|
|
@ -12,6 +12,7 @@ from follow import followedAccountAccepts
|
||||||
from follow import followedAccountRejects
|
from follow import followedAccountRejects
|
||||||
from follow import removeFromFollowRequests
|
from follow import removeFromFollowRequests
|
||||||
from utils import loadJson
|
from utils import loadJson
|
||||||
|
from storage import readWholeFile
|
||||||
from storage import storeValue
|
from storage import storeValue
|
||||||
|
|
||||||
|
|
||||||
|
@ -96,9 +97,7 @@ def manualApproveFollowRequest(session, baseDir: str,
|
||||||
return
|
return
|
||||||
|
|
||||||
# is the handle in the requests file?
|
# is the handle in the requests file?
|
||||||
approveFollowsStr = ''
|
approveFollowsStr = readWholeFile(approveFollowsFilename)
|
||||||
with open(approveFollowsFilename, 'r') as fpFollowers:
|
|
||||||
approveFollowsStr = fpFollowers.read()
|
|
||||||
exists = False
|
exists = False
|
||||||
approveHandleFull = approveHandle
|
approveHandleFull = approveHandle
|
||||||
if approveHandle in approveFollowsStr:
|
if approveHandle in approveFollowsStr:
|
||||||
|
|
7
media.py
7
media.py
|
@ -21,6 +21,7 @@ from shutil import copyfile
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
from shutil import move
|
from shutil import move
|
||||||
from city import spoofGeolocation
|
from city import spoofGeolocation
|
||||||
|
from storage import readWholeFile
|
||||||
from storage import storeValue
|
from storage import storeValue
|
||||||
|
|
||||||
|
|
||||||
|
@ -70,8 +71,10 @@ def _spoofMetaData(baseDir: str, nickname: str, domain: str,
|
||||||
baseDir + '/accounts/' + nickname + '@' + domain + '/decoyseed'
|
baseDir + '/accounts/' + nickname + '@' + domain + '/decoyseed'
|
||||||
decoySeed = 63725
|
decoySeed = 63725
|
||||||
if os.path.isfile(decoySeedFilename):
|
if os.path.isfile(decoySeedFilename):
|
||||||
with open(decoySeedFilename, 'r') as fp:
|
decoySeedStr = readWholeFile(decoySeedFilename)
|
||||||
decoySeed = int(fp.read())
|
if decoySeedStr:
|
||||||
|
if decoySeedStr.isdigit():
|
||||||
|
decoySeed = int(decoySeedStr)
|
||||||
else:
|
else:
|
||||||
decoySeed = randint(10000, 10000000000000000)
|
decoySeed = randint(10000, 10000000000000000)
|
||||||
decoySeedStr = str(decoySeed)
|
decoySeedStr = str(decoySeed)
|
||||||
|
|
|
@ -34,6 +34,7 @@ from utils import clearFromPostCaches
|
||||||
from utils import dangerousMarkup
|
from utils import dangerousMarkup
|
||||||
from inbox import storeHashTags
|
from inbox import storeHashTags
|
||||||
from session import createSession
|
from session import createSession
|
||||||
|
from storage import readWholeFile
|
||||||
from storage import storeValue
|
from storage import storeValue
|
||||||
|
|
||||||
|
|
||||||
|
@ -398,9 +399,8 @@ def _createNewsMirror(baseDir: str, domain: str,
|
||||||
|
|
||||||
# remove the corresponding index entries
|
# remove the corresponding index entries
|
||||||
if removals:
|
if removals:
|
||||||
indexContent = ''
|
indexContent = readWholeFile(mirrorIndexFilename)
|
||||||
with open(mirrorIndexFilename, 'r') as indexFile:
|
if indexContent:
|
||||||
indexContent = indexFile.read()
|
|
||||||
for removePostId in removals:
|
for removePostId in removals:
|
||||||
indexContent = \
|
indexContent = \
|
||||||
indexContent.replace(removePostId + '\n', '')
|
indexContent.replace(removePostId + '\n', '')
|
||||||
|
|
10
newswire.py
10
newswire.py
|
@ -29,6 +29,8 @@ from utils import removeHtml
|
||||||
from blocking import isBlockedDomain
|
from blocking import isBlockedDomain
|
||||||
from blocking import isBlockedHashtag
|
from blocking import isBlockedHashtag
|
||||||
from filters import isFiltered
|
from filters import isFiltered
|
||||||
|
from storage import readWholeFile
|
||||||
|
from storage import readFileLines
|
||||||
|
|
||||||
|
|
||||||
def _removeCDATA(text: str) -> str:
|
def _removeCDATA(text: str) -> str:
|
||||||
|
@ -219,8 +221,8 @@ def loadHashtagCategories(baseDir: str, language: str) -> None:
|
||||||
if not os.path.isfile(hashtagCategoriesFilename):
|
if not os.path.isfile(hashtagCategoriesFilename):
|
||||||
return
|
return
|
||||||
|
|
||||||
with open(hashtagCategoriesFilename, 'r') as fp:
|
xmlStr = readWholeFile(hashtagCategoriesFilename)
|
||||||
xmlStr = fp.read()
|
if xmlStr:
|
||||||
_xml2StrToHashtagCategories(baseDir, xmlStr, 1024, True)
|
_xml2StrToHashtagCategories(baseDir, xmlStr, 1024, True)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1014,9 +1016,7 @@ def getDictFromNewswire(session, baseDir: str, domain: str,
|
||||||
maxPostsPerSource = 5
|
maxPostsPerSource = 5
|
||||||
|
|
||||||
# add rss feeds
|
# add rss feeds
|
||||||
rssFeed = []
|
rssFeed = readFileLines(subscriptionsFilename)
|
||||||
with open(subscriptionsFilename, 'r') as fp:
|
|
||||||
rssFeed = fp.readlines()
|
|
||||||
result = {}
|
result = {}
|
||||||
for url in rssFeed:
|
for url in rssFeed:
|
||||||
url = url.strip()
|
url = url.strip()
|
||||||
|
|
|
@ -52,6 +52,7 @@ from session import createSession
|
||||||
from session import getJson
|
from session import getJson
|
||||||
from webfinger import webfingerHandle
|
from webfinger import webfingerHandle
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
from storage import readWholeFile
|
||||||
from storage import storeValue
|
from storage import storeValue
|
||||||
|
|
||||||
|
|
||||||
|
@ -1121,9 +1122,7 @@ def isPersonSnoozed(baseDir: str, nickname: str, domain: str,
|
||||||
replaceStr = line
|
replaceStr = line
|
||||||
break
|
break
|
||||||
if replaceStr:
|
if replaceStr:
|
||||||
content = None
|
content = readWholeFile(snoozedFilename).replace(replaceStr, '')
|
||||||
with open(snoozedFilename, 'r') as snoozedFile:
|
|
||||||
content = snoozedFile.read().replace(replaceStr, '')
|
|
||||||
if content:
|
if content:
|
||||||
storeValue(snoozedFilename, content, 'writeonly')
|
storeValue(snoozedFilename, content, 'writeonly')
|
||||||
|
|
||||||
|
@ -1168,9 +1167,7 @@ def personUnsnooze(baseDir: str, nickname: str, domain: str,
|
||||||
replaceStr = line
|
replaceStr = line
|
||||||
break
|
break
|
||||||
if replaceStr:
|
if replaceStr:
|
||||||
content = None
|
content = readWholeFile(snoozedFilename).replace(replaceStr, '')
|
||||||
with open(snoozedFilename, 'r') as snoozedFile:
|
|
||||||
content = snoozedFile.read().replace(replaceStr, '')
|
|
||||||
if content:
|
if content:
|
||||||
storeValue(snoozedFilename, content, 'writeonly')
|
storeValue(snoozedFilename, content, 'writeonly')
|
||||||
|
|
||||||
|
|
13
petnames.py
13
petnames.py
|
@ -7,6 +7,7 @@ __email__ = "bob@freedombone.net"
|
||||||
__status__ = "Production"
|
__status__ = "Production"
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
from storage import readWholeFile
|
||||||
from storage import storeValue
|
from storage import storeValue
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,8 +29,8 @@ def setPetName(baseDir: str, nickname: str, domain: str,
|
||||||
|
|
||||||
# does this entry already exist?
|
# does this entry already exist?
|
||||||
if os.path.isfile(petnamesFilename):
|
if os.path.isfile(petnamesFilename):
|
||||||
with open(petnamesFilename, 'r') as petnamesFile:
|
petnamesStr = readWholeFile(petnamesFilename)
|
||||||
petnamesStr = petnamesFile.read()
|
if petnamesStr:
|
||||||
if entry in petnamesStr:
|
if entry in petnamesStr:
|
||||||
return True
|
return True
|
||||||
if ' ' + handle + '\n' in petnamesStr:
|
if ' ' + handle + '\n' in petnamesStr:
|
||||||
|
@ -65,8 +66,8 @@ def getPetName(baseDir: str, nickname: str, domain: str,
|
||||||
|
|
||||||
if not os.path.isfile(petnamesFilename):
|
if not os.path.isfile(petnamesFilename):
|
||||||
return ''
|
return ''
|
||||||
with open(petnamesFilename, 'r') as petnamesFile:
|
petnamesStr = readWholeFile(petnamesFilename)
|
||||||
petnamesStr = petnamesFile.read()
|
if petnamesStr:
|
||||||
if ' ' + handle + '\n' in petnamesStr:
|
if ' ' + handle + '\n' in petnamesStr:
|
||||||
petnamesList = petnamesStr.split('\n')
|
petnamesList = petnamesStr.split('\n')
|
||||||
for pet in petnamesList:
|
for pet in petnamesList:
|
||||||
|
@ -86,8 +87,8 @@ def _getPetNameHandle(baseDir: str, nickname: str, domain: str,
|
||||||
|
|
||||||
if not os.path.isfile(petnamesFilename):
|
if not os.path.isfile(petnamesFilename):
|
||||||
return ''
|
return ''
|
||||||
with open(petnamesFilename, 'r') as petnamesFile:
|
petnamesStr = readWholeFile(petnamesFilename)
|
||||||
petnamesStr = petnamesFile.read()
|
if petnamesStr:
|
||||||
if petname + ' ' in petnamesStr:
|
if petname + ' ' in petnamesStr:
|
||||||
petnamesList = petnamesStr.split('\n')
|
petnamesList = petnamesStr.split('\n')
|
||||||
for pet in petnamesList:
|
for pet in petnamesList:
|
||||||
|
|
13
posts.py
13
posts.py
|
@ -72,6 +72,7 @@ from git import convertPostToPatch
|
||||||
from linked_data_sig import generateJsonSignature
|
from linked_data_sig import generateJsonSignature
|
||||||
from petnames import resolvePetnames
|
from petnames import resolvePetnames
|
||||||
from storage import storeValue
|
from storage import storeValue
|
||||||
|
from storage import readWholeFile
|
||||||
|
|
||||||
|
|
||||||
def isModerator(baseDir: str, nickname: str) -> bool:
|
def isModerator(baseDir: str, nickname: str) -> bool:
|
||||||
|
@ -3022,9 +3023,8 @@ def _addPostToTimeline(filePath: str, boxname: str,
|
||||||
postsInBox: [], boxActor: str) -> bool:
|
postsInBox: [], boxActor: str) -> bool:
|
||||||
""" Reads a post from file and decides whether it is valid
|
""" Reads a post from file and decides whether it is valid
|
||||||
"""
|
"""
|
||||||
with open(filePath, 'r') as postFile:
|
postStr = readWholeFile(filePath)
|
||||||
postStr = postFile.read()
|
if postStr:
|
||||||
|
|
||||||
if filePath.endswith('.json'):
|
if filePath.endswith('.json'):
|
||||||
repliesFilename = filePath.replace('.json', '.replies')
|
repliesFilename = filePath.replace('.json', '.replies')
|
||||||
if os.path.isfile(repliesFilename):
|
if os.path.isfile(repliesFilename):
|
||||||
|
@ -3715,9 +3715,7 @@ def getPublicPostDomainsBlocked(session, baseDir: str,
|
||||||
return []
|
return []
|
||||||
|
|
||||||
# read the blocked domains as a single string
|
# read the blocked domains as a single string
|
||||||
blockedStr = ''
|
blockedStr = readWholeFile(blockingFilename)
|
||||||
with open(blockingFilename, 'r') as fp:
|
|
||||||
blockedStr = fp.read()
|
|
||||||
|
|
||||||
blockedDomains = []
|
blockedDomains = []
|
||||||
for domainName in postDomains:
|
for domainName in postDomains:
|
||||||
|
@ -3766,8 +3764,7 @@ def checkDomains(session, baseDir: str,
|
||||||
updateFollowerWarnings = False
|
updateFollowerWarnings = False
|
||||||
followerWarningStr = ''
|
followerWarningStr = ''
|
||||||
if os.path.isfile(followerWarningFilename):
|
if os.path.isfile(followerWarningFilename):
|
||||||
with open(followerWarningFilename, 'r') as fp:
|
followerWarningStr = readWholeFile(followerWarningFilename)
|
||||||
followerWarningStr = fp.read()
|
|
||||||
|
|
||||||
if singleCheck:
|
if singleCheck:
|
||||||
# checks a single random non-mutual
|
# checks a single random non-mutual
|
||||||
|
|
13
speaker.py
13
speaker.py
|
@ -22,6 +22,8 @@ from utils import loadJson
|
||||||
from utils import saveJson
|
from utils import saveJson
|
||||||
from utils import isPGPEncrypted
|
from utils import isPGPEncrypted
|
||||||
from content import htmlReplaceQuoteMarks
|
from content import htmlReplaceQuoteMarks
|
||||||
|
from storage import readFileLines
|
||||||
|
from storage import readWholeFile
|
||||||
|
|
||||||
speakerRemoveChars = ('.\n', '. ', ',', ';', '?', '!')
|
speakerRemoveChars = ('.\n', '. ', ',', ';', '?', '!')
|
||||||
|
|
||||||
|
@ -135,8 +137,8 @@ def _speakerPronounce(baseDir: str, sayText: str, translate: {}) -> str:
|
||||||
")": ","
|
")": ","
|
||||||
}
|
}
|
||||||
if os.path.isfile(pronounceFilename):
|
if os.path.isfile(pronounceFilename):
|
||||||
with open(pronounceFilename, 'r') as fp:
|
pronounceList = readFileLines(pronounceFilename)
|
||||||
pronounceList = fp.readlines()
|
if pronounceList:
|
||||||
for conversion in pronounceList:
|
for conversion in pronounceList:
|
||||||
separator = None
|
separator = None
|
||||||
if '->' in conversion:
|
if '->' in conversion:
|
||||||
|
@ -494,8 +496,8 @@ def _postToSpeakerJson(baseDir: str, httpPrefix: str,
|
||||||
accountsDir = baseDir + '/accounts/' + nickname + '@' + domainFull
|
accountsDir = baseDir + '/accounts/' + nickname + '@' + domainFull
|
||||||
approveFollowsFilename = accountsDir + '/followrequests.txt'
|
approveFollowsFilename = accountsDir + '/followrequests.txt'
|
||||||
if os.path.isfile(approveFollowsFilename):
|
if os.path.isfile(approveFollowsFilename):
|
||||||
with open(approveFollowsFilename, 'r') as fp:
|
follows = readFileLines(approveFollowsFilename)
|
||||||
follows = fp.readlines()
|
if follows:
|
||||||
if len(follows) > 0:
|
if len(follows) > 0:
|
||||||
followRequestsExist = True
|
followRequestsExist = True
|
||||||
for i in range(len(follows)):
|
for i in range(len(follows)):
|
||||||
|
@ -512,8 +514,7 @@ def _postToSpeakerJson(baseDir: str, httpPrefix: str,
|
||||||
likedBy = ''
|
likedBy = ''
|
||||||
likeFilename = accountsDir + '/.newLike'
|
likeFilename = accountsDir + '/.newLike'
|
||||||
if os.path.isfile(likeFilename):
|
if os.path.isfile(likeFilename):
|
||||||
with open(likeFilename, 'r') as fp:
|
likedBy = readWholeFile(likeFilename)
|
||||||
likedBy = fp.read()
|
|
||||||
calendarFilename = accountsDir + '/.newCalendar'
|
calendarFilename = accountsDir + '/.newCalendar'
|
||||||
postCal = os.path.isfile(calendarFilename)
|
postCal = os.path.isfile(calendarFilename)
|
||||||
shareFilename = accountsDir + '/.newShare'
|
shareFilename = accountsDir + '/.newShare'
|
||||||
|
|
16
storage.py
16
storage.py
|
@ -54,3 +54,19 @@ def storeValue(filename: str, lineStr: str, storeType: str) -> bool:
|
||||||
print('WARN: Unable to prepend to ' +
|
print('WARN: Unable to prepend to ' +
|
||||||
filename + ' ' + str(e))
|
filename + ' ' + str(e))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def readWholeFile(filename: str) -> str:
|
||||||
|
"""Returns the entire contents of a file
|
||||||
|
"""
|
||||||
|
with open(filename, 'r') as fp:
|
||||||
|
return fp.read()
|
||||||
|
return ''
|
||||||
|
|
||||||
|
|
||||||
|
def readFileLines(filename: str) -> []:
|
||||||
|
"""Returns a list of lines from a file
|
||||||
|
"""
|
||||||
|
with open(filename, 'r') as fp:
|
||||||
|
return fp.readlines()
|
||||||
|
return []
|
||||||
|
|
33
theme.py
33
theme.py
|
@ -17,6 +17,7 @@ from shutil import unpack_archive
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
from content import dangerousCSS
|
from content import dangerousCSS
|
||||||
from storage import storeValue
|
from storage import storeValue
|
||||||
|
from storage import readWholeFile
|
||||||
|
|
||||||
|
|
||||||
def importTheme(baseDir: str, filename: str) -> bool:
|
def importTheme(baseDir: str, filename: str) -> bool:
|
||||||
|
@ -35,9 +36,9 @@ def importTheme(baseDir: str, filename: str) -> bool:
|
||||||
print('WARN: ' + themeFile +
|
print('WARN: ' + themeFile +
|
||||||
' missing from imported theme')
|
' missing from imported theme')
|
||||||
return False
|
return False
|
||||||
newThemeName = None
|
newThemeName = readWholeFile(tempThemeDir + '/name.txt')
|
||||||
with open(tempThemeDir + '/name.txt', 'r') as fp:
|
if newThemeName:
|
||||||
newThemeName = fp.read().replace('\n', '').replace('\r', '')
|
newThemeName = newThemeName.replace('\n', '').replace('\r', '')
|
||||||
if len(newThemeName) > 20:
|
if len(newThemeName) > 20:
|
||||||
print('WARN: Imported theme name is too long')
|
print('WARN: Imported theme name is too long')
|
||||||
return False
|
return False
|
||||||
|
@ -327,8 +328,8 @@ def _setThemeFromDict(baseDir: str, name: str,
|
||||||
if not os.path.isfile(templateFilename):
|
if not os.path.isfile(templateFilename):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
with open(templateFilename, 'r') as cssfile:
|
css = readWholeFile(templateFilename)
|
||||||
css = cssfile.read()
|
if css:
|
||||||
for paramName, paramValue in themeParams.items():
|
for paramName, paramValue in themeParams.items():
|
||||||
if paramName == 'newswire-publish-icon':
|
if paramName == 'newswire-publish-icon':
|
||||||
if paramValue.lower() == 'true':
|
if paramValue.lower() == 'true':
|
||||||
|
@ -385,8 +386,8 @@ def _setBackgroundFormat(baseDir: str, name: str,
|
||||||
cssFilename = baseDir + '/' + backgroundType + '.css'
|
cssFilename = baseDir + '/' + backgroundType + '.css'
|
||||||
if not os.path.isfile(cssFilename):
|
if not os.path.isfile(cssFilename):
|
||||||
return
|
return
|
||||||
with open(cssFilename, 'r') as cssfile:
|
css = readWholeFile(cssFilename)
|
||||||
css = cssfile.read()
|
if css:
|
||||||
css = css.replace('background.jpg', 'background.' + extension)
|
css = css.replace('background.jpg', 'background.' + extension)
|
||||||
storeValue(cssFilename, css, 'writeonly')
|
storeValue(cssFilename, css, 'writeonly')
|
||||||
|
|
||||||
|
@ -399,8 +400,8 @@ def enableGrayscale(baseDir: str) -> None:
|
||||||
templateFilename = baseDir + '/' + filename
|
templateFilename = baseDir + '/' + filename
|
||||||
if not os.path.isfile(templateFilename):
|
if not os.path.isfile(templateFilename):
|
||||||
continue
|
continue
|
||||||
with open(templateFilename, 'r') as cssfile:
|
css = readWholeFile(templateFilename)
|
||||||
css = cssfile.read()
|
if css:
|
||||||
if 'grayscale' not in css:
|
if 'grayscale' not in css:
|
||||||
css = \
|
css = \
|
||||||
css.replace('body, html {',
|
css.replace('body, html {',
|
||||||
|
@ -420,8 +421,8 @@ def disableGrayscale(baseDir: str) -> None:
|
||||||
templateFilename = baseDir + '/' + filename
|
templateFilename = baseDir + '/' + filename
|
||||||
if not os.path.isfile(templateFilename):
|
if not os.path.isfile(templateFilename):
|
||||||
continue
|
continue
|
||||||
with open(templateFilename, 'r') as cssfile:
|
css = readWholeFile(templateFilename)
|
||||||
css = cssfile.read()
|
if css:
|
||||||
if 'grayscale' in css:
|
if 'grayscale' in css:
|
||||||
css = \
|
css = \
|
||||||
css.replace('\n filter: grayscale(100%);', '')
|
css.replace('\n filter: grayscale(100%);', '')
|
||||||
|
@ -456,8 +457,8 @@ def _setCustomFont(baseDir: str):
|
||||||
templateFilename = baseDir + '/' + filename
|
templateFilename = baseDir + '/' + filename
|
||||||
if not os.path.isfile(templateFilename):
|
if not os.path.isfile(templateFilename):
|
||||||
continue
|
continue
|
||||||
with open(templateFilename, 'r') as cssfile:
|
css = readWholeFile(templateFilename)
|
||||||
css = cssfile.read()
|
if css:
|
||||||
css = \
|
css = \
|
||||||
setCSSparam(css, "*src",
|
setCSSparam(css, "*src",
|
||||||
"url('./fonts/custom." +
|
"url('./fonts/custom." +
|
||||||
|
@ -540,8 +541,7 @@ def getTextModeBanner(baseDir: str) -> str:
|
||||||
"""
|
"""
|
||||||
textModeBannerFilename = baseDir + '/accounts/banner.txt'
|
textModeBannerFilename = baseDir + '/accounts/banner.txt'
|
||||||
if os.path.isfile(textModeBannerFilename):
|
if os.path.isfile(textModeBannerFilename):
|
||||||
with open(textModeBannerFilename, 'r') as fp:
|
bannerStr = readWholeFile(textModeBannerFilename)
|
||||||
bannerStr = fp.read()
|
|
||||||
if bannerStr:
|
if bannerStr:
|
||||||
return bannerStr.replace('\n', '<br>')
|
return bannerStr.replace('\n', '<br>')
|
||||||
return None
|
return None
|
||||||
|
@ -554,8 +554,7 @@ def getTextModeLogo(baseDir: str) -> str:
|
||||||
if not os.path.isfile(textModeLogoFilename):
|
if not os.path.isfile(textModeLogoFilename):
|
||||||
textModeLogoFilename = baseDir + '/img/logo.txt'
|
textModeLogoFilename = baseDir + '/img/logo.txt'
|
||||||
|
|
||||||
with open(textModeLogoFilename, 'r') as fp:
|
logoStr = readWholeFile(textModeLogoFilename)
|
||||||
logoStr = fp.read()
|
|
||||||
if logoStr:
|
if logoStr:
|
||||||
return logoStr.replace('\n', '<br>')
|
return logoStr.replace('\n', '<br>')
|
||||||
return None
|
return None
|
||||||
|
|
36
utils.py
36
utils.py
|
@ -19,6 +19,7 @@ from followingCalendar import addPersonToCalendar
|
||||||
from cryptography.hazmat.backends import default_backend
|
from cryptography.hazmat.backends import default_backend
|
||||||
from cryptography.hazmat.primitives import hashes
|
from cryptography.hazmat.primitives import hashes
|
||||||
from storage import storeValue
|
from storage import storeValue
|
||||||
|
from storage import readWholeFile
|
||||||
|
|
||||||
# posts containing these strings will always get screened out,
|
# posts containing these strings will always get screened out,
|
||||||
# both incoming and outgoing.
|
# both incoming and outgoing.
|
||||||
|
@ -163,8 +164,8 @@ def isDormant(baseDir: str, nickname: str, domain: str, actor: str,
|
||||||
if not os.path.isfile(lastSeenFilename):
|
if not os.path.isfile(lastSeenFilename):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
with open(lastSeenFilename, 'r') as lastSeenFile:
|
daysSinceEpochStr = readWholeFile(lastSeenFilename)
|
||||||
daysSinceEpochStr = lastSeenFile.read()
|
if daysSinceEpochStr:
|
||||||
daysSinceEpoch = int(daysSinceEpochStr)
|
daysSinceEpoch = int(daysSinceEpochStr)
|
||||||
currTime = datetime.datetime.utcnow()
|
currTime = datetime.datetime.utcnow()
|
||||||
currDaysSinceEpoch = (currTime - datetime.datetime(1970, 1, 1)).days
|
currDaysSinceEpoch = (currTime - datetime.datetime(1970, 1, 1)).days
|
||||||
|
@ -506,8 +507,8 @@ def loadJson(filename: str, delaySec=2, maxTries=5) -> {}:
|
||||||
tries = 0
|
tries = 0
|
||||||
while tries < maxTries:
|
while tries < maxTries:
|
||||||
try:
|
try:
|
||||||
with open(filename, 'r') as fp:
|
data = readWholeFile(filename)
|
||||||
data = fp.read()
|
if data:
|
||||||
jsonObject = json.loads(data)
|
jsonObject = json.loads(data)
|
||||||
break
|
break
|
||||||
except BaseException:
|
except BaseException:
|
||||||
|
@ -527,8 +528,7 @@ def loadJsonOnionify(filename: str, domain: str, onionDomain: str,
|
||||||
tries = 0
|
tries = 0
|
||||||
while tries < 5:
|
while tries < 5:
|
||||||
try:
|
try:
|
||||||
with open(filename, 'r') as fp:
|
data = readWholeFile(filename)
|
||||||
data = fp.read()
|
|
||||||
if data:
|
if data:
|
||||||
data = data.replace(domain, onionDomain)
|
data = data.replace(domain, onionDomain)
|
||||||
data = data.replace('https:', 'http:')
|
data = data.replace('https:', 'http:')
|
||||||
|
@ -942,8 +942,7 @@ def _setDefaultPetName(baseDir: str, nickname: str, domain: str,
|
||||||
storeValue(petnamesFilename, petnameLookupEntry, 'writeonly')
|
storeValue(petnamesFilename, petnameLookupEntry, 'writeonly')
|
||||||
return
|
return
|
||||||
|
|
||||||
with open(petnamesFilename, 'r') as petnamesFile:
|
petnamesStr = readWholeFile(petnamesFilename)
|
||||||
petnamesStr = petnamesFile.read()
|
|
||||||
if petnamesStr:
|
if petnamesStr:
|
||||||
petnamesList = petnamesStr.split('\n')
|
petnamesList = petnamesStr.split('\n')
|
||||||
for pet in petnamesList:
|
for pet in petnamesList:
|
||||||
|
@ -1094,8 +1093,7 @@ def locateNewsArrival(baseDir: str, domain: str,
|
||||||
accountDir = baseDir + '/accounts/news@' + domain + '/'
|
accountDir = baseDir + '/accounts/news@' + domain + '/'
|
||||||
postFilename = accountDir + 'outbox/' + postUrl
|
postFilename = accountDir + 'outbox/' + postUrl
|
||||||
if os.path.isfile(postFilename):
|
if os.path.isfile(postFilename):
|
||||||
with open(postFilename, 'r') as arrivalFile:
|
arrival = readWholeFile(postFilename)
|
||||||
arrival = arrivalFile.read()
|
|
||||||
if arrival:
|
if arrival:
|
||||||
arrivalDate = \
|
arrivalDate = \
|
||||||
datetime.datetime.strptime(arrival,
|
datetime.datetime.strptime(arrival,
|
||||||
|
@ -1488,8 +1486,8 @@ def noOfActiveAccountsMonthly(baseDir: str, months: int) -> bool:
|
||||||
lastUsedFilename = \
|
lastUsedFilename = \
|
||||||
baseDir + '/accounts/' + account + '/.lastUsed'
|
baseDir + '/accounts/' + account + '/.lastUsed'
|
||||||
if os.path.isfile(lastUsedFilename):
|
if os.path.isfile(lastUsedFilename):
|
||||||
with open(lastUsedFilename, 'r') as lastUsedFile:
|
lastUsed = readWholeFile(lastUsedFilename)
|
||||||
lastUsed = lastUsedFile.read()
|
if lastUsed:
|
||||||
if lastUsed.isdigit():
|
if lastUsed.isdigit():
|
||||||
timeDiff = (currTime - int(lastUsed))
|
timeDiff = (currTime - int(lastUsed))
|
||||||
if timeDiff < monthSeconds:
|
if timeDiff < monthSeconds:
|
||||||
|
@ -1645,8 +1643,8 @@ def getCSS(baseDir: str, cssFilename: str, cssCache: {}) -> str:
|
||||||
# file hasn't changed, so return the version in the cache
|
# file hasn't changed, so return the version in the cache
|
||||||
return cssCache[cssFilename][1]
|
return cssCache[cssFilename][1]
|
||||||
|
|
||||||
with open(cssFilename, 'r') as fpCSS:
|
css = readWholeFile(cssFilename)
|
||||||
css = fpCSS.read()
|
if css:
|
||||||
if cssCache.get(cssFilename):
|
if cssCache.get(cssFilename):
|
||||||
# alter the cache contents
|
# alter the cache contents
|
||||||
cssCache[cssFilename][0] = lastModified
|
cssCache[cssFilename][0] = lastModified
|
||||||
|
@ -1756,9 +1754,8 @@ def _searchVirtualBoxPosts(baseDir: str, nickname: str, domain: str,
|
||||||
postFilename = path + '/' + postFilename.strip()
|
postFilename = path + '/' + postFilename.strip()
|
||||||
if not os.path.isfile(postFilename):
|
if not os.path.isfile(postFilename):
|
||||||
continue
|
continue
|
||||||
with open(postFilename, 'r') as postFile:
|
data = readWholeFile(postFilename).lower()
|
||||||
data = postFile.read().lower()
|
if data:
|
||||||
|
|
||||||
notFound = False
|
notFound = False
|
||||||
for keyword in searchWords:
|
for keyword in searchWords:
|
||||||
if keyword not in data:
|
if keyword not in data:
|
||||||
|
@ -1799,9 +1796,8 @@ def searchBoxPosts(baseDir: str, nickname: str, domain: str,
|
||||||
for root, dirs, fnames in os.walk(path):
|
for root, dirs, fnames in os.walk(path):
|
||||||
for fname in fnames:
|
for fname in fnames:
|
||||||
filePath = os.path.join(root, fname)
|
filePath = os.path.join(root, fname)
|
||||||
with open(filePath, 'r') as postFile:
|
data = readWholeFile(filePath).lower()
|
||||||
data = postFile.read().lower()
|
if data:
|
||||||
|
|
||||||
notFound = False
|
notFound = False
|
||||||
for keyword in searchWords:
|
for keyword in searchWords:
|
||||||
if keyword not in data:
|
if keyword not in data:
|
||||||
|
|
|
@ -13,6 +13,7 @@ from utils import getConfigParam
|
||||||
from webapp_utils import htmlHeaderWithWebsiteMarkup
|
from webapp_utils import htmlHeaderWithWebsiteMarkup
|
||||||
from webapp_utils import htmlFooter
|
from webapp_utils import htmlFooter
|
||||||
from webapp_utils import markdownToHtml
|
from webapp_utils import markdownToHtml
|
||||||
|
from storage import readWholeFile
|
||||||
|
|
||||||
|
|
||||||
def htmlAbout(cssCache: {}, baseDir: str, httpPrefix: str,
|
def htmlAbout(cssCache: {}, baseDir: str, httpPrefix: str,
|
||||||
|
@ -32,8 +33,9 @@ def htmlAbout(cssCache: {}, baseDir: str, httpPrefix: str,
|
||||||
|
|
||||||
aboutText = 'Information about this instance goes here.'
|
aboutText = 'Information about this instance goes here.'
|
||||||
if os.path.isfile(baseDir + '/accounts/about.md'):
|
if os.path.isfile(baseDir + '/accounts/about.md'):
|
||||||
with open(baseDir + '/accounts/about.md', 'r') as aboutFile:
|
aboutText = readWholeFile(baseDir + '/accounts/about.md')
|
||||||
aboutText = markdownToHtml(aboutFile.read())
|
if aboutText:
|
||||||
|
aboutText = markdownToHtml(aboutText)
|
||||||
|
|
||||||
aboutForm = ''
|
aboutForm = ''
|
||||||
cssFilename = baseDir + '/epicyon-profile.css'
|
cssFilename = baseDir + '/epicyon-profile.css'
|
||||||
|
|
|
@ -18,6 +18,7 @@ from webapp_utils import headerButtonsFrontScreen
|
||||||
from webapp_utils import htmlHeaderWithExternalStyle
|
from webapp_utils import htmlHeaderWithExternalStyle
|
||||||
from webapp_utils import htmlFooter
|
from webapp_utils import htmlFooter
|
||||||
from webapp_utils import getBannerFile
|
from webapp_utils import getBannerFile
|
||||||
|
from storage import readWholeFile
|
||||||
|
|
||||||
|
|
||||||
def _linksExist(baseDir: str) -> bool:
|
def _linksExist(baseDir: str) -> bool:
|
||||||
|
@ -403,8 +404,7 @@ def htmlEditLinks(cssCache: {}, translate: {}, baseDir: str, path: str,
|
||||||
linksFilename = baseDir + '/accounts/links.txt'
|
linksFilename = baseDir + '/accounts/links.txt'
|
||||||
linksStr = ''
|
linksStr = ''
|
||||||
if os.path.isfile(linksFilename):
|
if os.path.isfile(linksFilename):
|
||||||
with open(linksFilename, 'r') as fp:
|
linksStr = readWholeFile(linksFilename)
|
||||||
linksStr = fp.read()
|
|
||||||
|
|
||||||
editLinksForm += \
|
editLinksForm += \
|
||||||
'<div class="container">'
|
'<div class="container">'
|
||||||
|
@ -426,8 +426,7 @@ def htmlEditLinks(cssCache: {}, translate: {}, baseDir: str, path: str,
|
||||||
aboutFilename = baseDir + '/accounts/about.md'
|
aboutFilename = baseDir + '/accounts/about.md'
|
||||||
aboutStr = ''
|
aboutStr = ''
|
||||||
if os.path.isfile(aboutFilename):
|
if os.path.isfile(aboutFilename):
|
||||||
with open(aboutFilename, 'r') as fp:
|
aboutStr = readWholeFile(aboutFilename)
|
||||||
aboutStr = fp.read()
|
|
||||||
|
|
||||||
editLinksForm += \
|
editLinksForm += \
|
||||||
'<div class="container">'
|
'<div class="container">'
|
||||||
|
@ -445,8 +444,7 @@ def htmlEditLinks(cssCache: {}, translate: {}, baseDir: str, path: str,
|
||||||
TOSFilename = baseDir + '/accounts/tos.md'
|
TOSFilename = baseDir + '/accounts/tos.md'
|
||||||
TOSStr = ''
|
TOSStr = ''
|
||||||
if os.path.isfile(TOSFilename):
|
if os.path.isfile(TOSFilename):
|
||||||
with open(TOSFilename, 'r') as fp:
|
TOSStr = readWholeFile(TOSFilename)
|
||||||
TOSStr = fp.read()
|
|
||||||
|
|
||||||
editLinksForm += \
|
editLinksForm += \
|
||||||
'<div class="container">'
|
'<div class="container">'
|
||||||
|
|
|
@ -24,6 +24,7 @@ from webapp_utils import htmlFooter
|
||||||
from webapp_utils import getBannerFile
|
from webapp_utils import getBannerFile
|
||||||
from webapp_utils import htmlPostSeparator
|
from webapp_utils import htmlPostSeparator
|
||||||
from webapp_utils import headerButtonsFrontScreen
|
from webapp_utils import headerButtonsFrontScreen
|
||||||
|
from storage import readWholeFile
|
||||||
|
|
||||||
|
|
||||||
def _votesIndicator(totalVotes: int, positiveVoting: bool) -> str:
|
def _votesIndicator(totalVotes: int, positiveVoting: bool) -> str:
|
||||||
|
@ -576,8 +577,7 @@ def htmlEditNewswire(cssCache: {}, translate: {}, baseDir: str, path: str,
|
||||||
newswireFilename = baseDir + '/accounts/newswire.txt'
|
newswireFilename = baseDir + '/accounts/newswire.txt'
|
||||||
newswireStr = ''
|
newswireStr = ''
|
||||||
if os.path.isfile(newswireFilename):
|
if os.path.isfile(newswireFilename):
|
||||||
with open(newswireFilename, 'r') as fp:
|
newswireStr = readWholeFile(newswireFilename)
|
||||||
newswireStr = fp.read()
|
|
||||||
|
|
||||||
editNewswireForm += \
|
editNewswireForm += \
|
||||||
'<div class="container">'
|
'<div class="container">'
|
||||||
|
@ -595,8 +595,7 @@ def htmlEditNewswire(cssCache: {}, translate: {}, baseDir: str, path: str,
|
||||||
filterFilename = \
|
filterFilename = \
|
||||||
baseDir + '/accounts/news@' + domain + '/filters.txt'
|
baseDir + '/accounts/news@' + domain + '/filters.txt'
|
||||||
if os.path.isfile(filterFilename):
|
if os.path.isfile(filterFilename):
|
||||||
with open(filterFilename, 'r') as filterfile:
|
filterStr = readWholeFile(filterFilename)
|
||||||
filterStr = filterfile.read()
|
|
||||||
|
|
||||||
editNewswireForm += \
|
editNewswireForm += \
|
||||||
' <br><b><label class="labels">' + \
|
' <br><b><label class="labels">' + \
|
||||||
|
@ -611,8 +610,7 @@ def htmlEditNewswire(cssCache: {}, translate: {}, baseDir: str, path: str,
|
||||||
hashtagRulesFilename = \
|
hashtagRulesFilename = \
|
||||||
baseDir + '/accounts/hashtagrules.txt'
|
baseDir + '/accounts/hashtagrules.txt'
|
||||||
if os.path.isfile(hashtagRulesFilename):
|
if os.path.isfile(hashtagRulesFilename):
|
||||||
with open(hashtagRulesFilename, 'r') as rulesfile:
|
hashtagRulesStr = readWholeFile(hashtagRulesFilename)
|
||||||
hashtagRulesStr = rulesfile.read()
|
|
||||||
|
|
||||||
editNewswireForm += \
|
editNewswireForm += \
|
||||||
' <br><b><label class="labels">' + \
|
' <br><b><label class="labels">' + \
|
||||||
|
|
|
@ -17,6 +17,7 @@ from utils import getConfigParam
|
||||||
from webapp_utils import getBannerFile
|
from webapp_utils import getBannerFile
|
||||||
from webapp_utils import htmlHeaderWithExternalStyle
|
from webapp_utils import htmlHeaderWithExternalStyle
|
||||||
from webapp_utils import htmlFooter
|
from webapp_utils import htmlFooter
|
||||||
|
from storage import readWholeFile
|
||||||
|
|
||||||
|
|
||||||
def _htmlFollowingDataList(baseDir: str, nickname: str,
|
def _htmlFollowingDataList(baseDir: str, nickname: str,
|
||||||
|
@ -27,8 +28,7 @@ def _htmlFollowingDataList(baseDir: str, nickname: str,
|
||||||
followingFilename = \
|
followingFilename = \
|
||||||
baseDir + '/accounts/' + nickname + '@' + domain + '/following.txt'
|
baseDir + '/accounts/' + nickname + '@' + domain + '/following.txt'
|
||||||
if os.path.isfile(followingFilename):
|
if os.path.isfile(followingFilename):
|
||||||
with open(followingFilename, 'r') as followingFile:
|
msg = readWholeFile(followingFilename)
|
||||||
msg = followingFile.read()
|
|
||||||
# add your own handle, so that you can send DMs
|
# add your own handle, so that you can send DMs
|
||||||
# to yourself as reminders
|
# to yourself as reminders
|
||||||
msg += nickname + '@' + domainFull + '\n'
|
msg += nickname + '@' + domainFull + '\n'
|
||||||
|
@ -38,8 +38,8 @@ def _htmlFollowingDataList(baseDir: str, nickname: str,
|
||||||
nickname + '@' + domain + '/petnames.txt'
|
nickname + '@' + domain + '/petnames.txt'
|
||||||
if os.path.isfile(petnamesFilename):
|
if os.path.isfile(petnamesFilename):
|
||||||
followingList = []
|
followingList = []
|
||||||
with open(petnamesFilename, 'r') as petnamesFile:
|
petStr = readWholeFile(petnamesFilename)
|
||||||
petStr = petnamesFile.read()
|
if petStr:
|
||||||
# extract each petname and append it
|
# extract each petname and append it
|
||||||
petnamesList = petStr.split('\n')
|
petnamesList = petStr.split('\n')
|
||||||
for pet in petnamesList:
|
for pet in petnamesList:
|
||||||
|
|
Loading…
Reference in New Issue