Fix raw posts output

master
Bob Mottram 2019-07-03 12:24:38 +01:00
parent 553349c3f2
commit 2fe64c7543
4 changed files with 40 additions and 20 deletions

View File

@ -57,6 +57,8 @@ parser.add_argument('--path', dest='baseDir', type=str,default=os.getcwd(),
help='Directory in which to store posts')
parser.add_argument('--posts', dest='posts', type=str,default=None,
help='Show posts for the given handle')
parser.add_argument('--postsraw', dest='postsraw', type=str,default=None,
help='Show raw json of posts for the given handle')
parser.add_argument('-f','--federate', nargs='+',dest='federationList',
help='Specify federation list separated by spaces')
parser.add_argument("--https", type=str2bool, nargs='?',
@ -85,7 +87,13 @@ if args.testsnetwork:
if args.posts:
nickname=args.posts.split('@')[0]
domain=args.posts.split('@')[1]
getPublicPostsOfPerson(nickname,domain)
getPublicPostsOfPerson(nickname,domain,False,True)
sys.exit()
if args.postsraw:
nickname=args.postsraw.split('@')[0]
domain=args.postsraw.split('@')[1]
getPublicPostsOfPerson(nickname,domain,True,False)
sys.exit()
if not args.domain:

View File

@ -121,15 +121,25 @@ def getPersonPubKey(session,personUrl: str,personCache: {}) -> str:
def getPosts(session,outboxUrl: str,maxPosts: int,maxMentions: int, \
maxEmoji: int,maxAttachments: int,federationList: [], \
personCache: {}) -> {}:
personCache: {},raw: bool,simple: bool) -> {}:
personPosts={}
if not outboxUrl:
return personPosts
asHeader = {'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'}
if raw:
result = []
i = 0
for item in parseUserFeed(session,outboxUrl,asHeader):
result.append(item)
i += 1
if i == maxPosts:
break
pprint(result)
return None
i = 0
for item in parseUserFeed(session,outboxUrl,asHeader):
pprint(item)
if not item.get('type'):
continue
if item['type'] != 'Create':
@ -195,18 +205,20 @@ def getPosts(session,outboxUrl: str,maxPosts: int,maxMentions: int, \
if item['object'].get('sensitive'):
sensitive = item['object']['sensitive']
personPosts[published] = {
"sensitive": sensitive,
"inreplyto": inReplyTo,
"summary": summary,
"html": content,
"plaintext": cleanHtml(content),
"attachment": attachment,
"mentions": mentions,
"emoji": emoji,
"conversation": conversation
}
#print(str(item)+'\n')
if simple:
print(cleanHtml(content)+'\n')
else:
personPosts[published] = {
"sensitive": sensitive,
"inreplyto": inReplyTo,
"summary": summary,
"html": content,
"plaintext": cleanHtml(content),
"attachment": attachment,
"mentions": mentions,
"emoji": emoji,
"conversation": conversation
}
i += 1
if i == maxPosts:
@ -538,7 +550,7 @@ def archivePosts(nickname: str,domain: str,baseDir: str, \
if noOfPosts <= maxPostsInOutbox:
break
def getPublicPostsOfPerson(nickname,domain):
def getPublicPostsOfPerson(nickname,domain,raw,simple):
""" This is really just for test purposes
"""
useTor=True
@ -559,5 +571,5 @@ def getPublicPostsOfPerson(nickname,domain):
maxMentions=10
maxEmoji=10
maxAttachments=5
userPosts = getPosts(session,personUrl,30,maxMentions,maxEmoji,maxAttachments,federationList,personCache)
userPosts = getPosts(session,personUrl,30,maxMentions,maxEmoji,maxAttachments,federationList,personCache,raw,simple)
#print(str(userPosts))

View File

@ -34,7 +34,7 @@ def getJson(session,url: str,headers: {},params: {}) -> {}:
sessionHeaders['User-agent'] = "Mozilla/5.0 (Linux; Android 5.1.1; Nexus 5 Build/LMY48B; wv)"
session.cookies.clear()
result=session.get(url, headers=sessionHeaders, params=sessionParams)
print("*****result "+url+' ' + str(result))
#print("*****result "+url+' ' + str(result))
return result.json()
def postJson(session,postJsonObject: {},federationList: [],inboxUrl: str,headers: {}) -> str:

View File

@ -43,7 +43,7 @@ def webfingerHandle(session,handle: str,https: bool,cachedWebfingers: {}) -> {}:
wfDomain=domain
if ':' in wfDomain:
wfDomain=wfDomain.split(':')[0]
print('***********cachedWebfingers '+str(cachedWebfingers))
#print('***********cachedWebfingers '+str(cachedWebfingers))
wf=getWebfingerFromCache(nickname+'@'+wfDomain,cachedWebfingers)
if wf:
return wf