forked from indymedia/epicyon
Pass base directory as parameter
parent
d9d5ce94dc
commit
006cc3bbb3
38
epicyon.py
38
epicyon.py
|
@ -48,19 +48,19 @@ baseDir=os.getcwd()
|
|||
session = createSession(useTor)
|
||||
|
||||
|
||||
clearFollows(username,domain)
|
||||
followPerson(username,domain,'badger','wild.com',federationList)
|
||||
followPerson(username,domain,'squirrel','secret.com',federationList)
|
||||
followPerson(username,domain,'rodent','drainpipe.com',federationList)
|
||||
followPerson(username,domain,'batman','mesh.com',federationList)
|
||||
followPerson(username,domain,'giraffe','trees.com',federationList)
|
||||
clearFollows(baseDir,username,domain)
|
||||
followPerson(baseDir,username,domain,'badger','wild.com',federationList)
|
||||
followPerson(baseDir,username,domain,'squirrel','secret.com',federationList)
|
||||
followPerson(baseDir,username,domain,'rodent','drainpipe.com',federationList)
|
||||
followPerson(baseDir,username,domain,'batman','mesh.com',federationList)
|
||||
followPerson(baseDir,username,domain,'giraffe','trees.com',federationList)
|
||||
|
||||
clearFollowers(username,domain)
|
||||
followerOfPerson(username,domain,'badger','wild.com',federationList)
|
||||
followerOfPerson(username,domain,'squirrel','secret.com',federationList)
|
||||
followerOfPerson(username,domain,'rodent','drainpipe.com',federationList)
|
||||
followerOfPerson(username,domain,'batman','mesh.com',federationList)
|
||||
followerOfPerson(username,domain,'giraffe','trees.com',federationList)
|
||||
clearFollowers(baseDir,username,domain)
|
||||
followerOfPerson(baseDir,username,domain,'badger','wild.com',federationList)
|
||||
followerOfPerson(baseDir,username,domain,'squirrel','secret.com',federationList)
|
||||
followerOfPerson(baseDir,username,domain,'rodent','drainpipe.com',federationList)
|
||||
followerOfPerson(baseDir,username,domain,'batman','mesh.com',federationList)
|
||||
followerOfPerson(baseDir,username,domain,'giraffe','trees.com',federationList)
|
||||
|
||||
#unfollowPerson(username,domain,'squirrel','secret.com')
|
||||
#sys.exit()
|
||||
|
@ -75,18 +75,18 @@ followerOfPerson(username,domain,'giraffe','trees.com',federationList)
|
|||
|
||||
privateKeyPem,publicKeyPem,person,wfEndpoint=createPerson(baseDir,username,domain,port,https,True)
|
||||
#deleteAllPosts(username,domain)
|
||||
setPreferredUsername(username,domain,'badger')
|
||||
setBio(username,domain,'Some personal info')
|
||||
setPreferredUsername(baseDir,username,domain,'badger')
|
||||
setBio(baseDir,username,domain,'Some personal info')
|
||||
#createPublicPost(username, domain, https, "G'day world!", False, True, None, None, 'Not suitable for Vogons')
|
||||
#archivePosts(username,domain,baseDir,4)
|
||||
#outboxJson=createOutbox(baseDir,username,domain,port,https,2,True,None)
|
||||
#pprint(outboxJson)
|
||||
|
||||
testPostMessageBetweenServers()
|
||||
#testPostMessageBetweenServers()
|
||||
#runDaemon(domain,port,https,federationList,useTor)
|
||||
|
||||
#testHttpsig()
|
||||
sys.exit()
|
||||
#sys.exit()
|
||||
|
||||
#pprint(person)
|
||||
#print('\n')
|
||||
|
@ -96,9 +96,9 @@ handle="https://mastodon.social/@Gargron"
|
|||
wfRequest = webfingerHandle(session,handle,True)
|
||||
if not wfRequest:
|
||||
sys.exit()
|
||||
#wfResult = json.dumps(wfRequest, indent=4, sort_keys=True)
|
||||
#print(str(wfResult))
|
||||
#sys.exit()
|
||||
wfResult = json.dumps(wfRequest, indent=4, sort_keys=True)
|
||||
print(str(wfResult))
|
||||
sys.exit()
|
||||
|
||||
maxMentions=10
|
||||
maxEmoji=10
|
||||
|
|
23
follow.py
23
follow.py
|
@ -12,14 +12,13 @@ import os
|
|||
import sys
|
||||
from person import validUsername
|
||||
|
||||
def followPerson(username: str, domain: str, followUsername: str, followDomain: str, federationList, followFile='following.txt') -> bool:
|
||||
def followPerson(baseDir: str,username: str, domain: str, followUsername: str, followDomain: str, federationList, followFile='following.txt') -> bool:
|
||||
"""Adds a person to the follow list
|
||||
"""
|
||||
if followDomain.lower().replace('\n','') not in federationList:
|
||||
return False
|
||||
handle=username.lower()+'@'+domain.lower()
|
||||
handleToFollow=followUsername.lower()+'@'+followDomain.lower()
|
||||
baseDir=os.getcwd()
|
||||
if not os.path.isdir(baseDir+'/accounts/'+handle):
|
||||
os.mkdir(baseDir+'/accounts/'+handle)
|
||||
filename=baseDir+'/accounts/'+handle+'/'+followFile
|
||||
|
@ -33,17 +32,16 @@ def followPerson(username: str, domain: str, followUsername: str, followDomain:
|
|||
followfile.write(handleToFollow+'\n')
|
||||
return True
|
||||
|
||||
def followerOfPerson(username: str, domain: str, followerUsername: str, followerDomain: str, federationList) -> bool:
|
||||
def followerOfPerson(baseDir: str,username: str, domain: str, followerUsername: str, followerDomain: str, federationList) -> bool:
|
||||
"""Adds a follower of the given person
|
||||
"""
|
||||
return followPerson(username, domain, followerUsername, followerDomain, federationList, 'followers.txt')
|
||||
return followPerson(baseDir,username, domain, followerUsername, followerDomain, federationList, 'followers.txt')
|
||||
|
||||
def unfollowPerson(username: str, domain: str, followUsername: str, followDomain: str,followFile='following.txt') -> None:
|
||||
def unfollowPerson(baseDir: str,username: str, domain: str, followUsername: str, followDomain: str,followFile='following.txt') -> None:
|
||||
"""Removes a person to the follow list
|
||||
"""
|
||||
handle=username.lower()+'@'+domain.lower()
|
||||
handleToUnfollow=followUsername.lower()+'@'+followDomain.lower()
|
||||
baseDir=os.getcwd()
|
||||
if not os.path.isdir(baseDir+'/accounts/'+handle):
|
||||
os.mkdir(baseDir+'/accounts/'+handle)
|
||||
filename=baseDir+'/accounts/'+handle+'/'+followFile
|
||||
|
@ -62,27 +60,25 @@ def unfollowerOfPerson(username: str, domain: str, followerUsername: str, follow
|
|||
"""
|
||||
unfollowPerson(username, domain, followerUsername, followerDomain,'followers.txt')
|
||||
|
||||
def clearFollows(username: str, domain: str,followFile='following.txt') -> None:
|
||||
def clearFollows(baseDir: str,username: str, domain: str,followFile='following.txt') -> None:
|
||||
"""Removes all follows
|
||||
"""
|
||||
handle=username.lower()+'@'+domain.lower()
|
||||
baseDir=os.getcwd()
|
||||
if not os.path.isdir(baseDir+'/accounts/'+handle):
|
||||
os.mkdir(baseDir+'/accounts/'+handle)
|
||||
filename=baseDir+'/accounts/'+handle+'/'+followFile
|
||||
if os.path.isfile(filename):
|
||||
os.remove(filename)
|
||||
|
||||
def clearFollowers(username: str, domain: str) -> None:
|
||||
def clearFollowers(baseDir: str,username: str, domain: str) -> None:
|
||||
"""Removes all followers
|
||||
"""
|
||||
clearFollows(username, domain,'followers.txt')
|
||||
clearFollows(baseDir,username, domain,'followers.txt')
|
||||
|
||||
def getNoOfFollows(username: str,domain: str, followFile='following.txt') -> int:
|
||||
def getNoOfFollows(baseDir: str,username: str,domain: str, followFile='following.txt') -> int:
|
||||
"""Returns the number of follows or followers
|
||||
"""
|
||||
handle=username.lower()+'@'+domain.lower()
|
||||
baseDir=os.getcwd()
|
||||
filename=baseDir+'/accounts/'+handle+'/'+followFile
|
||||
if not os.path.isfile(filename):
|
||||
return 0
|
||||
|
@ -102,7 +98,7 @@ def getNoOfFollowers(username: str,domain: str) -> int:
|
|||
"""
|
||||
return getNoOfFollows(username,domain,'followers.txt')
|
||||
|
||||
def getFollowingFeed(domain: str,port: int,path: str,https: bool,followsPerPage=12,followFile='following') -> {}:
|
||||
def getFollowingFeed(baseDir: str,domain: str,port: int,path: str,https: bool,followsPerPage=12,followFile='following') -> {}:
|
||||
"""Returns the following and followers feeds from GET requests
|
||||
"""
|
||||
if '/'+followFile not in path:
|
||||
|
@ -162,7 +158,6 @@ def getFollowingFeed(domain: str,port: int,path: str,https: bool,followsPerPage=
|
|||
'totalItems': 0,
|
||||
'type': 'OrderedCollectionPage'}
|
||||
|
||||
baseDir=os.getcwd()
|
||||
handle=username.lower()+'@'+domain.lower()
|
||||
filename=baseDir+'/accounts/'+handle+'/'+followFile+'.txt'
|
||||
if not os.path.isfile(filename):
|
||||
|
|
|
@ -196,11 +196,10 @@ def personOutboxJson(baseDir: str,domain: str,port: int,path: str,https: bool,no
|
|||
return None
|
||||
return createOutbox(baseDir,username,domain,port,https,noOfItems,headerOnly,pageNumber)
|
||||
|
||||
def setPreferredUsername(username: str, domain: str, preferredName: str) -> bool:
|
||||
def setPreferredUsername(baseDir: str,username: str, domain: str, preferredName: str) -> bool:
|
||||
if len(preferredName)>32:
|
||||
return False
|
||||
handle=username.lower()+'@'+domain.lower()
|
||||
baseDir=os.getcwd()
|
||||
filename=baseDir+'/accounts/'+handle.lower()+'.json'
|
||||
if not os.path.isfile(filename):
|
||||
return False
|
||||
|
@ -214,11 +213,10 @@ def setPreferredUsername(username: str, domain: str, preferredName: str) -> bool
|
|||
commentjson.dump(personJson, fp, indent=4, sort_keys=False)
|
||||
return True
|
||||
|
||||
def setBio(username: str, domain: str, bio: str) -> bool:
|
||||
def setBio(baseDir: str,username: str, domain: str, bio: str) -> bool:
|
||||
if len(bio)>32:
|
||||
return False
|
||||
handle=username.lower()+'@'+domain.lower()
|
||||
baseDir=os.getcwd()
|
||||
filename=baseDir+'/accounts/'+handle.lower()+'.json'
|
||||
if not os.path.isfile(filename):
|
||||
return False
|
||||
|
|
2
posts.py
2
posts.py
|
@ -374,7 +374,7 @@ def sendPost(session,baseDir,username: str, domain: str, port: int, toUsername:
|
|||
# construct the http header
|
||||
signatureHeaderJson = createSignedHeader(privateKeyPem, username, domain, port, '/inbox', https, withDigest, postJsonObject)
|
||||
signatureHeaderJson['Content-type'] = 'application/json'
|
||||
print("*************signatureHeaderJson "+str(signatureHeaderJson))
|
||||
|
||||
# Keep the number of threads being used small
|
||||
while len(sendThreads)>10:
|
||||
sendThreads[0].kill()
|
||||
|
|
|
@ -50,8 +50,6 @@ def webfingerHandle(session,handle: str,https: bool):
|
|||
par = {'resource': 'acct:{}'.format(username+'@'+domain)}
|
||||
hdr = {'Accept': 'application/jrd+json'}
|
||||
#try:
|
||||
print("webfinger url = "+url)
|
||||
print("webfinger par = "+str(par))
|
||||
result = getJson(session, url, hdr, par)
|
||||
#except:
|
||||
# print("Unable to webfinger " + url)
|
||||
|
@ -149,13 +147,11 @@ def webfingerLookup(path: str,baseDir: str):
|
|||
if not path.startswith('/.well-known/webfinger?'):
|
||||
return None
|
||||
handle=None
|
||||
print('************** '+path)
|
||||
if 'resource=acct:' in path:
|
||||
handle=path.split('resource=acct:')[1].strip()
|
||||
else:
|
||||
if 'resource=acct%3A' in path:
|
||||
handle=path.split('resource=acct%3A')[1].replace('%40','@').strip()
|
||||
print('************** handle: '+handle)
|
||||
if not handle:
|
||||
return None
|
||||
if '&' in handle:
|
||||
|
@ -163,7 +159,6 @@ def webfingerLookup(path: str,baseDir: str):
|
|||
if '@' not in handle:
|
||||
return None
|
||||
filename=baseDir+'/wfendpoints/'+handle.lower()+'.json'
|
||||
print('************** filename: '+filename)
|
||||
if not os.path.isfile(filename):
|
||||
return None
|
||||
wfJson={"user": "unknown"}
|
||||
|
|
Loading…
Reference in New Issue