Follow option uses c2s

master
Bob Mottram 2019-07-17 13:17:54 +01:00
parent 6b3de06ec7
commit fa454aca2b
1 changed files with 20 additions and 24 deletions

View File

@ -216,8 +216,8 @@ if args.tests:
if args.testsnetwork: if args.testsnetwork:
print('Network Tests') print('Network Tests')
#testPostMessageBetweenServers() testPostMessageBetweenServers()
#testFollowBetweenServers() testFollowBetweenServers()
testClientToServer() testClientToServer()
sys.exit() sys.exit()
@ -362,7 +362,15 @@ if args.announce:
time.sleep(1) time.sleep(1)
sys.exit() sys.exit()
if args.follow and nickname: if args.follow:
# follow via c2s protocol
if not nickname:
print('Please specify the nickname for the account with --nickname')
sys.exit()
if not args.password:
print('Please specify the password for '+nickname+' on '+domain)
sys.exit()
if not os.path.isdir(baseDir+'/accounts/'+nickname+'@'+domain): if not os.path.isdir(baseDir+'/accounts/'+nickname+'@'+domain):
print(nickname+' is not an account on the system. use --addaccount if necessary.') print(nickname+' is not an account on the system. use --addaccount if necessary.')
sys.exit() sys.exit()
@ -374,34 +382,22 @@ if args.follow and nickname:
followNickname=getNicknameFromActor(args.follow) followNickname=getNicknameFromActor(args.follow)
followDomain,followPort=getDomainFromActor(args.follow) followDomain,followPort=getDomainFromActor(args.follow)
if os.path.isfile(baseDir+'/accounts/'+nickname+'@'+domain+'/following.txt'):
if followNickname+'@'+followDomain in open(baseDir+'/accounts/'+nickname+'@'+domain+'/following.txt').read():
print(nickname+'@'+domain+' is already following '+followNickname+'@'+followDomain)
sys.exit()
session = createSession(domain,port,useTor) session = createSession(domain,port,useTor)
personCache={} personCache={}
cachedWebfingers={} cachedWebfingers={}
sendThreads=[]
sendThreads=[]
postLog=[]
followHttpPrefix=httpPrefix followHttpPrefix=httpPrefix
if args.follow.startswith('https'): if args.follow.startswith('https'):
followHttpPrefix='https' followHttpPrefix='https'
sendFollowRequest(session,baseDir, \
nickname,domain,port,httpPrefix, \ sendFollowRequestViaServer(session,nickname,args.password, \
followNickname,followDomain,followPort, \ domain,port, \
followHttpPrefix, \ followNickname,followDomain,followPort, \
False,federationList, \ httpPrefix, \
sendThreads,postLog, \ cachedWebfingers,personCache, \
cachedWebfingers,personCache,debug) debug)
for t in range(30): for t in range(20):
time.sleep(1) time.sleep(1)
if os.path.isfile(baseDir+'/accounts/'+nickname+'@'+domain+'/following.txt'): # TODO some method to know if it worked
if followNickname+'@'+followDomain in open(baseDir+'/accounts/'+nickname+'@'+domain+'/following.txt').read():
print('Ok')
sys.exit()
print('Follow attempt failed')
sys.exit() sys.exit()
nickname='admin' nickname='admin'