forked from indymedia/epicyon
Parsing post collections from pleroma
parent
132cb65030
commit
753eb34bde
26
posts.py
26
posts.py
|
@ -136,9 +136,16 @@ def parseUserFeed(session,feedUrl: str,asHeader: {}, \
|
||||||
nextUrl = feedJson['next']
|
nextUrl = feedJson['next']
|
||||||
|
|
||||||
if nextUrl:
|
if nextUrl:
|
||||||
for item in parseUserFeed(session,nextUrl,asHeader, \
|
if isinstance(nextUrl, str):
|
||||||
projectVersion,httpPrefix,domain):
|
userFeed=parseUserFeed(session,nextUrl,asHeader, \
|
||||||
yield item
|
projectVersion,httpPrefix,domain)
|
||||||
|
for item in userFeed:
|
||||||
|
yield item
|
||||||
|
elif isinstance(nextUrl, dict):
|
||||||
|
userFeed=nextUrl
|
||||||
|
if userFeed.get('orderedItems'):
|
||||||
|
for item in userFeed['orderedItems']:
|
||||||
|
yield item
|
||||||
|
|
||||||
def getPersonBox(baseDir: str,session,wfRequest: {},personCache: {}, \
|
def getPersonBox(baseDir: str,session,wfRequest: {},personCache: {}, \
|
||||||
projectVersion: str,httpPrefix: str,domain: str, \
|
projectVersion: str,httpPrefix: str,domain: str, \
|
||||||
|
@ -205,16 +212,16 @@ def getPosts(session,outboxUrl: str,maxPosts: int, \
|
||||||
projectVersion: str,httpPrefix: str,domain: str) -> {}:
|
projectVersion: str,httpPrefix: str,domain: str) -> {}:
|
||||||
"""Gets public posts from an outbox
|
"""Gets public posts from an outbox
|
||||||
"""
|
"""
|
||||||
personPosts={}
|
personPosts={}
|
||||||
if not outboxUrl:
|
if not outboxUrl:
|
||||||
return personPosts
|
return personPosts
|
||||||
|
|
||||||
asHeader = {'Accept': 'application/activity+json; profile="https://www.w3.org/ns/activitystreams"'}
|
asHeader = {'Accept': 'application/activity+json; profile="https://www.w3.org/ns/activitystreams"'}
|
||||||
if raw:
|
if raw:
|
||||||
result = []
|
result = []
|
||||||
i = 0
|
i = 0
|
||||||
for item in parseUserFeed(session,outboxUrl,asHeader, \
|
userFeed=parseUserFeed(session,outboxUrl,asHeader, \
|
||||||
projectVersion,httpPrefix,domain):
|
projectVersion,httpPrefix,domain)
|
||||||
|
for item in userFeed:
|
||||||
result.append(item)
|
result.append(item)
|
||||||
i += 1
|
i += 1
|
||||||
if i == maxPosts:
|
if i == maxPosts:
|
||||||
|
@ -223,8 +230,9 @@ def getPosts(session,outboxUrl: str,maxPosts: int, \
|
||||||
return None
|
return None
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
for item in parseUserFeed(session,outboxUrl,asHeader, \
|
userFeed=parseUserFeed(session,outboxUrl,asHeader, \
|
||||||
projectVersion,httpPrefix,domain):
|
projectVersion,httpPrefix,domain)
|
||||||
|
for item in userFeed:
|
||||||
if not item.get('id'):
|
if not item.get('id'):
|
||||||
if debug:
|
if debug:
|
||||||
print('No id')
|
print('No id')
|
||||||
|
|
|
@ -27,6 +27,10 @@ def createSession(domain: str, port: int, onionRoute: bool):
|
||||||
|
|
||||||
def getJson(session,url: str,headers: {},params: {}, \
|
def getJson(session,url: str,headers: {},params: {}, \
|
||||||
version='1.0.0',httpPrefix='https',domain='testdomain') -> {}:
|
version='1.0.0',httpPrefix='https',domain='testdomain') -> {}:
|
||||||
|
if not isinstance(url, str):
|
||||||
|
print('url: '+str(url))
|
||||||
|
print('ERROR: getJson url should be a string')
|
||||||
|
return None
|
||||||
sessionParams={}
|
sessionParams={}
|
||||||
sessionHeaders={}
|
sessionHeaders={}
|
||||||
if headers:
|
if headers:
|
||||||
|
@ -46,7 +50,7 @@ def getJson(session,url: str,headers: {},params: {}, \
|
||||||
return result.json()
|
return result.json()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('ERROR: getJson failed')
|
print('ERROR: getJson failed')
|
||||||
print('url: '+url)
|
print('url: '+str(url))
|
||||||
print('headers: '+str(sessionHeaders))
|
print('headers: '+str(sessionHeaders))
|
||||||
print('params: '+str(sessionParams))
|
print('params: '+str(sessionParams))
|
||||||
print(e)
|
print(e)
|
||||||
|
|
Loading…
Reference in New Issue