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') help='Directory in which to store posts')
parser.add_argument('--posts', dest='posts', type=str,default=None, parser.add_argument('--posts', dest='posts', type=str,default=None,
help='Show posts for the given handle') 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', parser.add_argument('-f','--federate', nargs='+',dest='federationList',
help='Specify federation list separated by spaces') help='Specify federation list separated by spaces')
parser.add_argument("--https", type=str2bool, nargs='?', parser.add_argument("--https", type=str2bool, nargs='?',
@ -85,7 +87,13 @@ if args.testsnetwork:
if args.posts: if args.posts:
nickname=args.posts.split('@')[0] nickname=args.posts.split('@')[0]
domain=args.posts.split('@')[1] 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() sys.exit()
if not args.domain: 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, \ def getPosts(session,outboxUrl: str,maxPosts: int,maxMentions: int, \
maxEmoji: int,maxAttachments: int,federationList: [], \ maxEmoji: int,maxAttachments: int,federationList: [], \
personCache: {}) -> {}: personCache: {},raw: bool,simple: bool) -> {}:
personPosts={} personPosts={}
if not outboxUrl: if not outboxUrl:
return personPosts return personPosts
asHeader = {'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'} 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 i = 0
for item in parseUserFeed(session,outboxUrl,asHeader): for item in parseUserFeed(session,outboxUrl,asHeader):
pprint(item)
if not item.get('type'): if not item.get('type'):
continue continue
if item['type'] != 'Create': if item['type'] != 'Create':
@ -194,19 +204,21 @@ def getPosts(session,outboxUrl: str,maxPosts: int,maxMentions: int, \
sensitive = False sensitive = False
if item['object'].get('sensitive'): if item['object'].get('sensitive'):
sensitive = item['object']['sensitive'] sensitive = item['object']['sensitive']
personPosts[published] = { if simple:
"sensitive": sensitive, print(cleanHtml(content)+'\n')
"inreplyto": inReplyTo, else:
"summary": summary, personPosts[published] = {
"html": content, "sensitive": sensitive,
"plaintext": cleanHtml(content), "inreplyto": inReplyTo,
"attachment": attachment, "summary": summary,
"mentions": mentions, "html": content,
"emoji": emoji, "plaintext": cleanHtml(content),
"conversation": conversation "attachment": attachment,
} "mentions": mentions,
#print(str(item)+'\n') "emoji": emoji,
"conversation": conversation
}
i += 1 i += 1
if i == maxPosts: if i == maxPosts:
@ -538,7 +550,7 @@ def archivePosts(nickname: str,domain: str,baseDir: str, \
if noOfPosts <= maxPostsInOutbox: if noOfPosts <= maxPostsInOutbox:
break break
def getPublicPostsOfPerson(nickname,domain): def getPublicPostsOfPerson(nickname,domain,raw,simple):
""" This is really just for test purposes """ This is really just for test purposes
""" """
useTor=True useTor=True
@ -559,5 +571,5 @@ def getPublicPostsOfPerson(nickname,domain):
maxMentions=10 maxMentions=10
maxEmoji=10 maxEmoji=10
maxAttachments=5 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)) #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)" sessionHeaders['User-agent'] = "Mozilla/5.0 (Linux; Android 5.1.1; Nexus 5 Build/LMY48B; wv)"
session.cookies.clear() session.cookies.clear()
result=session.get(url, headers=sessionHeaders, params=sessionParams) result=session.get(url, headers=sessionHeaders, params=sessionParams)
print("*****result "+url+' ' + str(result)) #print("*****result "+url+' ' + str(result))
return result.json() return result.json()
def postJson(session,postJsonObject: {},federationList: [],inboxUrl: str,headers: {}) -> str: 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 wfDomain=domain
if ':' in wfDomain: if ':' in wfDomain:
wfDomain=wfDomain.split(':')[0] wfDomain=wfDomain.split(':')[0]
print('***********cachedWebfingers '+str(cachedWebfingers)) #print('***********cachedWebfingers '+str(cachedWebfingers))
wf=getWebfingerFromCache(nickname+'@'+wfDomain,cachedWebfingers) wf=getWebfingerFromCache(nickname+'@'+wfDomain,cachedWebfingers)
if wf: if wf:
return wf return wf