master
Bob Mottram 2019-06-28 20:36:39 +01:00
parent 9c2859b616
commit 7e99a5907f
3 changed files with 10 additions and 17 deletions

View File

@ -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)

View File

@ -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

View File

@ -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