From 7e99a5907f227e4777a93b3e98e2d6f40e3ea7ff Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 28 Jun 2019 20:36:39 +0100 Subject: [PATCH] Tidying --- epicyon.py | 2 -- posts.py | 19 ++++--------------- session.py | 6 ++++++ 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/epicyon.py b/epicyon.py index 6a2560075..2eee23fe5 100644 --- a/epicyon.py +++ b/epicyon.py @@ -28,8 +28,6 @@ runDaemon('mydomain.com',6227,False) #testHttpsig() #sys.exit() -privateKeyPem,publicKeyPem,person,wfEndpoint=createPerson('testuser','mydomain.com',True,True) -sys.exit() #pprint(person) #print('\n') #pprint(wfEndpoint) diff --git a/posts.py b/posts.py index 93a7421ab..d6d87ef65 100644 --- a/posts.py +++ b/posts.py @@ -36,13 +36,8 @@ def getUserUrl(wfRequest) -> str: return link['href'] return None -def parseUserFeed(feedUrl,asHeader) -> None: - session = requests.session() - session.proxies = {} - headers=asHeader - headers['User-agent'] = "HotJava/1.1.2 FCS" - session.cookies.clear() - feed = session.get(feedUrl, headers=asHeader).json() +def parseUserFeed(session,feedUrl,asHeader) -> None: + feed = getJson(session,feedUrl,asHeader,None) if 'orderedItems' in feed: for item in feed['orderedItems']: @@ -55,7 +50,7 @@ def parseUserFeed(feedUrl,asHeader) -> None: nextUrl = feed['next'] if nextUrl: - for item in parseUserFeed(nextUrl,asHeader): + for item in parseUserFeed(session,nextUrl,asHeader): yield item def getUserPosts(session,wfRequest,maxPosts,maxMentions,maxEmoji,maxAttachments,allowedDomains) -> {}: @@ -70,7 +65,7 @@ def getUserPosts(session,wfRequest,maxPosts,maxMentions,maxEmoji,maxAttachments, feedUrl = userJson['outbox'] i = 0 - for item in parseUserFeed(feedUrl,asHeader): + for item in parseUserFeed(session,feedUrl,asHeader): if not item.get('type'): continue if item['type'] != 'Create': @@ -206,9 +201,3 @@ def createPublicPost(username: str, domain: str, https: bool, content: str, foll } } return newPost - -def postToInbox(session,postJson,inboxUrl: str): - """Post a json message to the inbox of another person - """ - postResult = session.post(url = inboxUrl, data = postJson) - return postResult.text diff --git a/session.py b/session.py index ab966e44b..202fa9a8a 100644 --- a/session.py +++ b/session.py @@ -27,3 +27,9 @@ def getJson(session,url: str,headers,params): sessionHeaders['User-agent'] = "HotJava/1.1.2 FCS" session.cookies.clear() return session.get(url, headers=sessionHeaders, params=sessionParams).json() + +def postJson(session,postJson,inboxUrl: str): + """Post a json message to the inbox of another person + """ + postResult = session.post(url = inboxUrl, data = postJson) + return postResult.text