Actor option

master
Bob Mottram 2019-07-05 16:53:26 +01:00
parent bfbf6ec625
commit 42314dd4c8
1 changed files with 37 additions and 1 deletions

View File

@ -18,6 +18,7 @@ from posts import createOutbox
from posts import archivePosts from posts import archivePosts
from posts import sendPost from posts import sendPost
from posts import getPublicPostsOfPerson from posts import getPublicPostsOfPerson
from posts import getUserUrl
from session import createSession from session import createSession
from session import getJson from session import getJson
import json import json
@ -70,6 +71,8 @@ parser.add_argument('--pass','--password', dest='password', type=str,default=Non
help='Set a password for an account') help='Set a password for an account')
parser.add_argument('--chpass','--changepassword', nargs='+',dest='changepassword', parser.add_argument('--chpass','--changepassword', nargs='+',dest='changepassword',
help='Change the password for an account') help='Change the password for an account')
parser.add_argument('--actor', dest='actor', type=str,default=None,
help='Show the json actor the given handle')
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, parser.add_argument('--postsraw', dest='postsraw', type=str,default=None,
@ -110,12 +113,18 @@ if args.testsnetwork:
sys.exit() sys.exit()
if args.posts: if args.posts:
if '@' not in args.posts:
print('Syntax: --posts nickname@domain')
sys.exit()
nickname=args.posts.split('@')[0] nickname=args.posts.split('@')[0]
domain=args.posts.split('@')[1] domain=args.posts.split('@')[1]
getPublicPostsOfPerson(nickname,domain,False,True) getPublicPostsOfPerson(nickname,domain,False,True)
sys.exit() sys.exit()
if args.postsraw: if args.postsraw:
if '@' not in args.posts:
print('Syntax: --postsraw nickname@domain')
sys.exit()
nickname=args.postsraw.split('@')[0] nickname=args.postsraw.split('@')[0]
domain=args.postsraw.split('@')[1] domain=args.postsraw.split('@')[1]
getPublicPostsOfPerson(nickname,domain,True,False) getPublicPostsOfPerson(nickname,domain,True,False)
@ -154,6 +163,33 @@ if args.dat:
httpPrefix='dat' httpPrefix='dat'
useTor=args.tor useTor=args.tor
if args.actor:
if '@' not in args.actor:
print('Syntax: --actor nickname@domain')
sys.exit()
nickname=args.actor.split('@')[0]
domain=args.actor.split('@')[1].replace('\n','')
wfCache={}
if domain.endswith('.onion'):
httpPrefix='http'
port=80
else:
httpPrefix='https'
port=443
session = createSession(domain,port,useTor)
wfRequest = webfingerHandle(session,nickname+'@'+domain,httpPrefix,wfCache)
if not wfRequest:
print('Unable to webfinger '+nickname+'@'+domain)
sys.exit()
asHeader = {'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'}
personUrl = getUserUrl(wfRequest)
personJson = getJson(session,personUrl,asHeader,None)
if personJson:
pprint(personJson)
else:
print('Failed to get '+personUrl)
sys.exit()
if args.addaccount: if args.addaccount:
if '@' in args.addaccount: if '@' in args.addaccount:
nickname=args.addaccount.split('@')[0] nickname=args.addaccount.split('@')[0]