Move function out of daemon

merge-requests/30/head
Bob Mottram 2021-06-07 18:49:10 +01:00
parent 56c1785ab2
commit 84d6e50820
3 changed files with 80 additions and 57 deletions

12
city.py
View File

@ -217,3 +217,15 @@ def spoofGeolocation(baseDir: str,
return (default_latitude, default_longitude,
default_latdirection, default_longdirection,
"", "", 0)
def getSpoofedCity(city: str, baseDir: str, nickname: str, domain: str) -> str:
"""Returns the name of the city to use as a GPS spoofing location for
image metadata
"""
cityFilename = baseDir + '/accounts/' + \
nickname + '@' + domain + '/city.txt'
if os.path.isfile(cityFilename):
with open(cityFilename, 'r') as fp:
city = fp.read().replace('\n', '')
return city

View File

@ -290,6 +290,7 @@ from filters import addGlobalFilter
from filters import removeGlobalFilter
from context import hasValidContext
from speaker import getSSMLbox
from city import getSpoofedCity
import os
@ -327,18 +328,6 @@ def saveDomainQrcode(baseDir: str, httpPrefix: str,
class PubServer(BaseHTTPRequestHandler):
protocol_version = 'HTTP/1.1'
def _getSpoofedCity(self, baseDir: str, nickname: str, domain: str) -> str:
"""Returns the name of the city to use as a GPS spoofing location for
image metadata
"""
city = self.server.city
cityFilename = baseDir + '/accounts/' + \
nickname + '@' + domain + '/city.txt'
if os.path.isfile(cityFilename):
with open(cityFilename, 'r') as fp:
city = fp.read().replace('\n', '')
return city
def _getInstalceUrl(self, callingDomain: str) -> str:
"""Returns the URL for this instance
"""
@ -447,7 +436,8 @@ class PubServer(BaseHTTPRequestHandler):
eventDate = None
eventTime = None
location = None
city = self._getSpoofedCity(self.server.baseDir,
city = getSpoofedCity(self.server.city,
self.server.baseDir,
nickname, self.server.domain)
messageJson = \
@ -1197,7 +1187,8 @@ class PubServer(BaseHTTPRequestHandler):
if postToNickname:
print('Posting to nickname ' + postToNickname)
self.postToNickname = postToNickname
city = self._getSpoofedCity(self.server.baseDir,
city = getSpoofedCity(self.server.city,
self.server.baseDir,
postToNickname, self.server.domain)
return postMessageToOutbox(self.server.session,
@ -4184,7 +4175,8 @@ class PubServer(BaseHTTPRequestHandler):
except BaseException:
pass
city = self._getSpoofedCity(baseDir, nickname, domain)
city = getSpoofedCity(self.server.city,
baseDir, nickname, domain)
processMetaData(baseDir, nickname, domain,
filename, postImageFilename, city)
@ -7585,7 +7577,9 @@ class PubServer(BaseHTTPRequestHandler):
accessKeys = self.server.keyShortcuts[nickname]
rolesList = getActorRolesList(actorJson)
city = self._getSpoofedCity(baseDir, nickname, domain)
city = \
getSpoofedCity(self.server.city,
baseDir, nickname, domain)
msg = \
htmlProfile(self.server.rssIconAtTop,
self.server.cssCache,
@ -7683,7 +7677,8 @@ class PubServer(BaseHTTPRequestHandler):
actorSkillsList = \
getOccupationSkills(actorJson)
skills = getSkillsFromList(actorSkillsList)
city = self._getSpoofedCity(baseDir,
city = getSpoofedCity(self.server.city,
baseDir,
nickname, domain)
msg = \
htmlProfile(self.server.rssIconAtTop,
@ -9582,7 +9577,8 @@ class PubServer(BaseHTTPRequestHandler):
accessKeys = \
self.server.keyShortcuts[nickname]
city = self._getSpoofedCity(baseDir, nickname, domain)
city = getSpoofedCity(self.server.city,
baseDir, nickname, domain)
msg = \
htmlProfile(self.server.rssIconAtTop,
self.server.cssCache,
@ -9694,7 +9690,8 @@ class PubServer(BaseHTTPRequestHandler):
accessKeys = \
self.server.keyShortcuts[nickname]
city = self._getSpoofedCity(baseDir, nickname, domain)
city = getSpoofedCity(self.server.city,
baseDir, nickname, domain)
msg = \
htmlProfile(self.server.rssIconAtTop,
self.server.cssCache,
@ -9805,7 +9802,8 @@ class PubServer(BaseHTTPRequestHandler):
accessKeys = \
self.server.keyShortcuts[nickname]
city = self._getSpoofedCity(baseDir, nickname, domain)
city = getSpoofedCity(self.server.city,
baseDir, nickname, domain)
msg = \
htmlProfile(self.server.rssIconAtTop,
self.server.cssCache,
@ -9940,7 +9938,8 @@ class PubServer(BaseHTTPRequestHandler):
accessKeys = \
self.server.keyShortcuts[nickname]
city = self._getSpoofedCity(baseDir, nickname, domain)
city = getSpoofedCity(self.server.city,
baseDir, nickname, domain)
msg = \
htmlProfile(self.server.rssIconAtTop,
self.server.cssCache,
@ -10542,7 +10541,8 @@ class PubServer(BaseHTTPRequestHandler):
peertubeInstances = self.server.peertubeInstances
nickname = getNicknameFromActor(path)
if nickname:
city = self._getSpoofedCity(baseDir, nickname, domain)
city = getSpoofedCity(self.server.city,
baseDir, nickname, domain)
else:
city = self.server.city
@ -13335,7 +13335,8 @@ class PubServer(BaseHTTPRequestHandler):
filename.endswith('.gif'):
postImageFilename = filename.replace('.temp', '')
print('Removing metadata from ' + postImageFilename)
city = self._getSpoofedCity(self.server.baseDir,
city = getSpoofedCity(self.server.city,
self.server.baseDir,
nickname, self.server.domain)
processMetaData(self.server.baseDir,
nickname, self.server.domain,
@ -13448,7 +13449,8 @@ class PubServer(BaseHTTPRequestHandler):
nickname, self.server.domain)
return 1
city = self._getSpoofedCity(self.server.baseDir,
city = getSpoofedCity(self.server.city,
self.server.baseDir,
nickname, self.server.domain)
messageJson = \
createPublicPost(self.server.baseDir,
@ -13597,7 +13599,8 @@ class PubServer(BaseHTTPRequestHandler):
imgDescription = fields['imageDescription']
if filename:
city = self._getSpoofedCity(self.server.baseDir,
city = getSpoofedCity(self.server.city,
self.server.baseDir,
nickname,
self.server.domain)
postJsonObject['object'] = \
@ -13632,7 +13635,8 @@ class PubServer(BaseHTTPRequestHandler):
str(fields['postUrl']))
return -1
elif postType == 'newunlisted':
city = self._getSpoofedCity(self.server.baseDir,
city = getSpoofedCity(self.server.city,
self.server.baseDir,
nickname,
self.server.domain)
messageJson = \
@ -13666,7 +13670,8 @@ class PubServer(BaseHTTPRequestHandler):
else:
return -1
elif postType == 'newfollowers':
city = self._getSpoofedCity(self.server.baseDir,
city = getSpoofedCity(self.server.city,
self.server.baseDir,
nickname,
self.server.domain)
messageJson = \
@ -13722,7 +13727,8 @@ class PubServer(BaseHTTPRequestHandler):
maximumAttendeeCapacity = \
int(fields['maximumAttendeeCapacity'])
city = self._getSpoofedCity(self.server.baseDir,
city = getSpoofedCity(self.server.city,
self.server.baseDir,
nickname,
self.server.domain)
messageJson = \
@ -13762,7 +13768,8 @@ class PubServer(BaseHTTPRequestHandler):
messageJson = None
print('A DM was posted')
if '@' in mentionsStr:
city = self._getSpoofedCity(self.server.baseDir,
city = getSpoofedCity(self.server.city,
self.server.baseDir,
nickname,
self.server.domain)
messageJson = \
@ -13806,7 +13813,8 @@ class PubServer(BaseHTTPRequestHandler):
print('A reminder was posted for ' + handle)
if '@' + handle not in mentionsStr:
mentionsStr = '@' + handle + ' ' + mentionsStr
city = self._getSpoofedCity(self.server.baseDir,
city = getSpoofedCity(self.server.city,
self.server.baseDir,
nickname,
self.server.domain)
messageJson = \
@ -13843,7 +13851,8 @@ class PubServer(BaseHTTPRequestHandler):
# and not accounts being reported we disable any
# included fediverse addresses by replacing '@' with '-at-'
fields['message'] = fields['message'].replace('@', '-at-')
city = self._getSpoofedCity(self.server.baseDir,
city = getSpoofedCity(self.server.city,
self.server.baseDir,
nickname,
self.server.domain)
messageJson = \
@ -13875,7 +13884,8 @@ class PubServer(BaseHTTPRequestHandler):
str(questionCtr)])
if not qOptions:
return -1
city = self._getSpoofedCity(self.server.baseDir,
city = getSpoofedCity(self.server.city,
self.server.baseDir,
nickname,
self.server.domain)
messageJson = \
@ -13914,7 +13924,8 @@ class PubServer(BaseHTTPRequestHandler):
if durationStr:
if ' ' not in durationStr:
durationStr = durationStr + ' days'
city = self._getSpoofedCity(self.server.baseDir,
city = getSpoofedCity(self.server.city,
self.server.baseDir,
nickname,
self.server.domain)
addShare(self.server.baseDir,