diff --git a/epicyon.py b/epicyon.py index 45ca6572..c2ad9f3f 100644 --- a/epicyon.py +++ b/epicyon.py @@ -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: diff --git a/posts.py b/posts.py index 810b09c1..f033310b 100644 --- a/posts.py +++ b/posts.py @@ -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': @@ -194,19 +204,21 @@ def getPosts(session,outboxUrl: str,maxPosts: int,maxMentions: int, \ sensitive = False 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)) diff --git a/session.py b/session.py index ddea1f6d..0a2d7a28 100644 --- a/session.py +++ b/session.py @@ -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: diff --git a/webfinger.py b/webfinger.py index 25cb1cb0..84404825 100644 --- a/webfinger.py +++ b/webfinger.py @@ -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