diff --git a/feeds.py b/feeds.py index 5a5eba61a..310243981 100644 --- a/feeds.py +++ b/feeds.py @@ -9,16 +9,14 @@ __module_group__ = "RSS Feeds" def rss2TagHeader(hashtag: str, httpPrefix: str, domainFull: str) -> str: - rssStr = "" - rssStr += "" - rssStr += '' - rssStr += ' #' + hashtag + '' - rssStr += ' ' + httpPrefix + '://' + domainFull + \ + return \ + "" + \ + "" + \ + '' + \ + ' #' + hashtag + '' + \ + ' ' + httpPrefix + '://' + domainFull + \ '/tags/rss2/' + hashtag + '' - return rssStr def rss2TagFooter() -> str: - rssStr = '' - rssStr += '' - return rssStr + return '' diff --git a/follow.py b/follow.py index 5567dd9bf..0ef1c5ce6 100644 --- a/follow.py +++ b/follow.py @@ -220,18 +220,13 @@ def isFollowerOfPerson(baseDir: str, nickname: str, domain: str, if handle in followersStr: alreadyFollowing = True - elif '://' + followerDomain + \ - '/profile/' + followerNickname in followersStr: - alreadyFollowing = True - elif '://' + followerDomain + \ - '/channel/' + followerNickname in followersStr: - alreadyFollowing = True - elif '://' + followerDomain + \ - '/accounts/' + followerNickname in followersStr: - alreadyFollowing = True - elif '://' + followerDomain + \ - '/u/' + followerNickname in followersStr: - alreadyFollowing = True + else: + paths = ('/profile/', '/channel/', '/accounts/', '/u/') + for userPath in paths: + url = '://' + followerDomain + userPath + followerNickname + if url in followersStr: + alreadyFollowing = True + break return alreadyFollowing diff --git a/happening.py b/happening.py index b5606e0e7..2a6b2e842 100644 --- a/happening.py +++ b/happening.py @@ -132,12 +132,10 @@ def saveEventPost(baseDir: str, handle: str, postId: str, calendarNotificationFilename = \ baseDir + '/accounts/' + handle + '/.newCalendar' with open(calendarNotificationFilename, 'w+') as calendarNotificationFile: - calendarNotificationFile.write('/calendar?year=' + - str(eventYear) + - '?month=' + - str(eventMonthNumber) + - '?day=' + - str(eventDayOfMonth)) + notifyStr = \ + '/calendar?year=' + str(eventYear) + '?month=' + \ + str(eventMonthNumber) + '?day=' + str(eventDayOfMonth) + calendarNotificationFile.write(notifyStr) return True diff --git a/manualapprove.py b/manualapprove.py index 91948a344..c915683ef 100644 --- a/manualapprove.py +++ b/manualapprove.py @@ -111,18 +111,12 @@ def manualApproveFollowRequest(session, baseDir: str, reqNick = approveHandle.split('@')[0] reqDomain = approveHandle.split('@')[1].strip() reqPrefix = httpPrefix + '://' + reqDomain - if reqPrefix + '/profile/' + reqNick in approveFollowsStr: - exists = True - approveHandleFull = reqPrefix + '/profile/' + reqNick - elif reqPrefix + '/channel/' + reqNick in approveFollowsStr: - exists = True - approveHandleFull = reqPrefix + '/channel/' + reqNick - elif reqPrefix + '/accounts/' + reqNick in approveFollowsStr: - exists = True - approveHandleFull = reqPrefix + '/accounts/' + reqNick - elif reqPrefix + '/u/' + reqNick in approveFollowsStr: - exists = True - approveHandleFull = reqPrefix + '/u/' + reqNick + paths = ('/profile/', '/channel/', '/accounts/', '/u/') + for userPath in paths: + if reqPrefix + userPath + reqNick in approveFollowsStr: + exists = True + approveHandleFull = reqPrefix + userPath + reqNick + break if not exists: print('Manual follow accept: ' + approveHandleFull + ' not in requests file "' + diff --git a/markdown.py b/markdown.py index 67d99b426..eb0cbf2d7 100644 --- a/markdown.py +++ b/markdown.py @@ -140,29 +140,22 @@ def markdownToHtml(markdown: str) -> str: linesList = markdown.split('\n') htmlStr = '' ctr = 0 + titles = { + "h5": '#####', + "h4": '####', + "h3": '###', + "h2": '##', + "h1": '#' + } for line in linesList: if ctr > 0: htmlStr += '
' - if line.startswith('#####'): - line = line.replace('#####', '').strip() - line = '
' + line + '
' - ctr = -1 - elif line.startswith('####'): - line = line.replace('####', '').strip() - line = '

' + line + '

' - ctr = -1 - elif line.startswith('###'): - line = line.replace('###', '').strip() - line = '

' + line + '

' - ctr = -1 - elif line.startswith('##'): - line = line.replace('##', '').strip() - line = '

' + line + '

' - ctr = -1 - elif line.startswith('#'): - line = line.replace('#', '').strip() - line = '

' + line + '

' - ctr = -1 + for h, hashes in titles.items(): + if line.startswith(hashes): + line = line.replace(hashes, '').strip() + line = '<' + h + '>' + line + '' + ctr = -1 + break htmlStr += line ctr += 1 return htmlStr diff --git a/migrate.py b/migrate.py index b36002a41..bae02eb61 100644 --- a/migrate.py +++ b/migrate.py @@ -13,9 +13,9 @@ from utils import getNicknameFromActor from utils import getDomainFromActor from webfinger import webfingerHandle from blocking import isBlocked -from session import getJson from posts import getUserUrl from follow import unfollowAccount +from person import getActorJson def _moveFollowingHandlesForAccount(baseDir: str, nickname: str, domain: str, @@ -73,22 +73,16 @@ def _updateMovedHandle(baseDir: str, nickname: str, domain: str, print('wfRequest error: ' + str(wfRequest['errors'])) return ctr - profileStr = 'https://www.w3.org/ns/activitystreams' - asHeader = { - 'Accept': 'application/activity+json; profile="' + profileStr + '"' - } if not personUrl: personUrl = getUserUrl(wfRequest, 0, debug) if not personUrl: return ctr - profileStr = 'https://www.w3.org/ns/activitystreams' - asHeader = { - 'Accept': 'application/ld+json; profile="' + profileStr + '"' - } + gnunet = False + if httpPrefix == 'gnunet': + gnunet = True personJson = \ - getJson(session, personUrl, asHeader, None, - debug, __version__, httpPrefix, None) + getActorJson(domain, personUrl, httpPrefix, gnunet, debug) if not personJson: return ctr if not personJson.get('movedTo'): diff --git a/tests.py b/tests.py index 9496820ac..c6ac118db 100644 --- a/tests.py +++ b/tests.py @@ -3951,9 +3951,8 @@ def _testSpoofGeolocation() -> None: hourStr = str(hour) if hour < 10: hourStr = '0' + hourStr - currTime = datetime.datetime.strptime("2021-05-" + str(dayNumber) + - " " + hourStr + ":14", - "%Y-%m-%d %H:%M") + dateTimeStr = "2021-05-" + str(dayNumber) + " " + hourStr + ":14" + currTime = datetime.datetime.strptime(dateTimeStr, "%Y-%m-%d %H:%M") coords = spoofGeolocation('', 'new york, usa', currTime, decoySeed, citiesList, nogoList) longitude = coords[1] @@ -3989,9 +3988,8 @@ def _testSpoofGeolocation() -> None: hourStr = str(hour) if hour < 10: hourStr = '0' + hourStr - currTime = datetime.datetime.strptime("2021-05-" + str(dayNumber) + - " " + hourStr + ":14", - "%Y-%m-%d %H:%M") + dateTimeStr = "2021-05-" + str(dayNumber) + " " + hourStr + ":14" + currTime = datetime.datetime.strptime(dateTimeStr, "%Y-%m-%d %H:%M") coords = spoofGeolocation('', 'london, england', currTime, decoySeed, citiesList, nogoList) longitude = coords[1] @@ -4040,9 +4038,8 @@ def _testSpoofGeolocation() -> None: hourStr = str(hour) if hour < 10: hourStr = '0' + hourStr - currTime = datetime.datetime.strptime("2021-05-" + str(dayNumber) + - " " + hourStr + ":14", - "%Y-%m-%d %H:%M") + dateTimeStr = "2021-05-" + str(dayNumber) + " " + hourStr + ":14" + currTime = datetime.datetime.strptime(dateTimeStr, "%Y-%m-%d %H:%M") coords = spoofGeolocation('', 'SAN FRANCISCO, USA', currTime, decoySeed, citiesList, nogoList) longitude = coords[1] @@ -4095,9 +4092,8 @@ def _testSpoofGeolocation() -> None: hourStr = str(hour) if hour < 10: hourStr = '0' + hourStr - currTime = datetime.datetime.strptime("2021-05-" + str(dayNumber) + - " " + hourStr + ":14", - "%Y-%m-%d %H:%M") + dateTimeStr = "2021-05-" + str(dayNumber) + " " + hourStr + ":14" + currTime = datetime.datetime.strptime(dateTimeStr, "%Y-%m-%d %H:%M") coords = spoofGeolocation('', 'SEATTLE, USA', currTime, decoySeed, citiesList, nogoList) longitude = coords[1]