mirror of https://gitlab.com/bashrc2/epicyon
More debug
parent
72ee03ed37
commit
d6ac3b91cb
37
posts.py
37
posts.py
|
@ -184,13 +184,20 @@ def getUserUrl(wfRequest: {}, sourceId: int = 0, debug: bool = False) -> str:
|
||||||
|
|
||||||
def parseUserFeed(session, feedUrl: str, asHeader: {},
|
def parseUserFeed(session, feedUrl: str, asHeader: {},
|
||||||
projectVersion: str, httpPrefix: str,
|
projectVersion: str, httpPrefix: str,
|
||||||
domain: str, depth=0) -> {}:
|
domain: str, debug: bool, depth: int = 0) -> {}:
|
||||||
if depth > 10:
|
if depth > 10:
|
||||||
|
if debug:
|
||||||
|
print('Maximum search depth reached')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
if debug:
|
||||||
|
print('Getting user feed for ' + feedUrl)
|
||||||
|
print('User feed header ' + str(asHeader))
|
||||||
feedJson = getJson(session, feedUrl, asHeader, None,
|
feedJson = getJson(session, feedUrl, asHeader, None,
|
||||||
False, projectVersion, httpPrefix, domain)
|
False, projectVersion, httpPrefix, domain)
|
||||||
if not feedJson:
|
if not feedJson:
|
||||||
|
if debug:
|
||||||
|
print('No user feed was returned')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if 'orderedItems' in feedJson:
|
if 'orderedItems' in feedJson:
|
||||||
|
@ -203,13 +210,16 @@ def parseUserFeed(session, feedUrl: str, asHeader: {},
|
||||||
elif 'next' in feedJson:
|
elif 'next' in feedJson:
|
||||||
nextUrl = feedJson['next']
|
nextUrl = feedJson['next']
|
||||||
|
|
||||||
|
if debug:
|
||||||
|
print('User feed next url: ' + str(nextUrl))
|
||||||
|
|
||||||
if nextUrl:
|
if nextUrl:
|
||||||
if isinstance(nextUrl, str):
|
if isinstance(nextUrl, str):
|
||||||
if '?max_id=0' not in nextUrl:
|
if '?max_id=0' not in nextUrl:
|
||||||
userFeed = \
|
userFeed = \
|
||||||
parseUserFeed(session, nextUrl, asHeader,
|
parseUserFeed(session, nextUrl, asHeader,
|
||||||
projectVersion, httpPrefix,
|
projectVersion, httpPrefix,
|
||||||
domain, depth + 1)
|
domain, debug, depth + 1)
|
||||||
if userFeed:
|
if userFeed:
|
||||||
for item in userFeed:
|
for item in userFeed:
|
||||||
yield item
|
yield item
|
||||||
|
@ -355,6 +365,8 @@ def _getPosts(session, outboxUrl: str, maxPosts: int,
|
||||||
domain: str, systemLanguage: str) -> {}:
|
domain: str, systemLanguage: str) -> {}:
|
||||||
"""Gets public posts from an outbox
|
"""Gets public posts from an outbox
|
||||||
"""
|
"""
|
||||||
|
if debug:
|
||||||
|
print('Getting outbox posts for ' + outboxUrl)
|
||||||
personPosts = {}
|
personPosts = {}
|
||||||
if not outboxUrl:
|
if not outboxUrl:
|
||||||
return personPosts
|
return personPosts
|
||||||
|
@ -367,10 +379,12 @@ def _getPosts(session, outboxUrl: str, maxPosts: int,
|
||||||
'Accept': 'application/ld+json; profile="' + profileStr + '"'
|
'Accept': 'application/ld+json; profile="' + profileStr + '"'
|
||||||
}
|
}
|
||||||
if raw:
|
if raw:
|
||||||
|
if debug:
|
||||||
|
print('Returning the raw feed')
|
||||||
result = []
|
result = []
|
||||||
i = 0
|
i = 0
|
||||||
userFeed = parseUserFeed(session, outboxUrl, asHeader,
|
userFeed = parseUserFeed(session, outboxUrl, asHeader,
|
||||||
projectVersion, httpPrefix, domain)
|
projectVersion, httpPrefix, domain, debug)
|
||||||
for item in userFeed:
|
for item in userFeed:
|
||||||
result.append(item)
|
result.append(item)
|
||||||
i += 1
|
i += 1
|
||||||
|
@ -379,9 +393,11 @@ def _getPosts(session, outboxUrl: str, maxPosts: int,
|
||||||
pprint(result)
|
pprint(result)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
if debug:
|
||||||
|
print('Returning a human readable version of the feed')
|
||||||
i = 0
|
i = 0
|
||||||
userFeed = parseUserFeed(session, outboxUrl, asHeader,
|
userFeed = parseUserFeed(session, outboxUrl, asHeader,
|
||||||
projectVersion, httpPrefix, domain)
|
projectVersion, httpPrefix, domain, debug)
|
||||||
for item in userFeed:
|
for item in userFeed:
|
||||||
if not item.get('id'):
|
if not item.get('id'):
|
||||||
if debug:
|
if debug:
|
||||||
|
@ -597,7 +613,7 @@ def getPostDomains(session, outboxUrl: str, maxPosts: int,
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
userFeed = parseUserFeed(session, outboxUrl, asHeader,
|
userFeed = parseUserFeed(session, outboxUrl, asHeader,
|
||||||
projectVersion, httpPrefix, domain)
|
projectVersion, httpPrefix, domain, debug)
|
||||||
for item in userFeed:
|
for item in userFeed:
|
||||||
i += 1
|
i += 1
|
||||||
if i > maxPosts:
|
if i > maxPosts:
|
||||||
|
@ -652,7 +668,7 @@ def _getPostsForBlockedDomains(baseDir: str,
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
userFeed = parseUserFeed(session, outboxUrl, asHeader,
|
userFeed = parseUserFeed(session, outboxUrl, asHeader,
|
||||||
projectVersion, httpPrefix, domain)
|
projectVersion, httpPrefix, domain, debug)
|
||||||
for item in userFeed:
|
for item in userFeed:
|
||||||
i += 1
|
i += 1
|
||||||
if i > maxPosts:
|
if i > maxPosts:
|
||||||
|
@ -3599,6 +3615,8 @@ def getPublicPostsOfPerson(baseDir: str, nickname: str, domain: str,
|
||||||
print('Starting new session for getting public posts')
|
print('Starting new session for getting public posts')
|
||||||
session = createSession(proxyType)
|
session = createSession(proxyType)
|
||||||
if not session:
|
if not session:
|
||||||
|
if debug:
|
||||||
|
print('Session was not created')
|
||||||
return
|
return
|
||||||
personCache = {}
|
personCache = {}
|
||||||
cachedWebfingers = {}
|
cachedWebfingers = {}
|
||||||
|
@ -3610,12 +3628,16 @@ def getPublicPostsOfPerson(baseDir: str, nickname: str, domain: str,
|
||||||
webfingerHandle(session, handle, httpPrefix, cachedWebfingers,
|
webfingerHandle(session, handle, httpPrefix, cachedWebfingers,
|
||||||
domain, projectVersion, debug, False)
|
domain, projectVersion, debug, False)
|
||||||
if not wfRequest:
|
if not wfRequest:
|
||||||
|
if debug:
|
||||||
|
print('No webfinger result was returned for ' + handle)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
if not isinstance(wfRequest, dict):
|
if not isinstance(wfRequest, dict):
|
||||||
print('Webfinger for ' + handle + ' did not return a dict. ' +
|
print('Webfinger for ' + handle + ' did not return a dict. ' +
|
||||||
str(wfRequest))
|
str(wfRequest))
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
if debug:
|
||||||
|
print('Getting the outbox for ' + handle)
|
||||||
(personUrl, pubKeyId, pubKey,
|
(personUrl, pubKeyId, pubKey,
|
||||||
personId, shaedInbox,
|
personId, shaedInbox,
|
||||||
avatarUrl, displayName) = getPersonBox(baseDir, session, wfRequest,
|
avatarUrl, displayName) = getPersonBox(baseDir, session, wfRequest,
|
||||||
|
@ -3623,6 +3645,9 @@ def getPublicPostsOfPerson(baseDir: str, nickname: str, domain: str,
|
||||||
projectVersion, httpPrefix,
|
projectVersion, httpPrefix,
|
||||||
nickname, domain, 'outbox',
|
nickname, domain, 'outbox',
|
||||||
62524)
|
62524)
|
||||||
|
if debug:
|
||||||
|
print('Actor url: ' + personId)
|
||||||
|
|
||||||
maxMentions = 10
|
maxMentions = 10
|
||||||
maxEmoji = 10
|
maxEmoji = 10
|
||||||
maxAttachments = 5
|
maxAttachments = 5
|
||||||
|
|
|
@ -246,7 +246,7 @@ def htmlProfileAfterSearch(cssCache: {},
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
for item in parseUserFeed(session, outboxUrl, asHeader,
|
for item in parseUserFeed(session, outboxUrl, asHeader,
|
||||||
projectVersion, httpPrefix, domain):
|
projectVersion, httpPrefix, domain, debug):
|
||||||
if not item.get('actor'):
|
if not item.get('actor'):
|
||||||
continue
|
continue
|
||||||
if item['actor'] != personUrl:
|
if item['actor'] != personUrl:
|
||||||
|
|
Loading…
Reference in New Issue