following and followers files

master
Bob Mottram 2019-06-29 19:23:13 +01:00
parent 1c2db15263
commit 1bd7a40892
2 changed files with 85 additions and 4 deletions

View File

@ -24,6 +24,11 @@ from pprint import pprint
from httpsig import testHttpsig
from daemon import runDaemon
import socket
from follow import clearFollows
from follow import followPerson
from follow import followerOfPerson
from follow import unfollowPerson
from follow import unfollowerOfPerson
federationList=['mastodon.social']
username='testuser'
@ -34,11 +39,18 @@ https=True
useTor=False
session = createSession(useTor)
#asHeader = {'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'}
clearFollows(username,domain)
followPerson(username,domain,'badger','wild.com')
followPerson(username,domain,'squirrel','secret.com')
followPerson(username,domain,'rodent','drainpipe.com')
unfollowPerson(username,domain,'squirrel','secret.com')
sys.exit()
asHeader = {'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'}
#userFollowing = getJson(session,"https://mastodon.social/users/Gargron/followers?page=true",asHeader,None)
#userFollowing = getJson(session,"https://mastodon.social/users/Gargron/following?page=true",asHeader,None)
#pprint(userFollowing)
#sys.exit()
userFollowing = getJson(session,"https://mastodon.social/users/Gargron/following?page=true",asHeader,None)
pprint(userFollowing)
sys.exit()
privateKeyPem,publicKeyPem,person,wfEndpoint=createPerson(username,domain,https,True)

69
follow.py 100644
View File

@ -0,0 +1,69 @@
__filename__ = "follow.py"
__author__ = "Bob Mottram"
__license__ = "AGPL3+"
__version__ = "0.0.1"
__maintainer__ = "Bob Mottram"
__email__ = "bob@freedombone.net"
__status__ = "Production"
import json
from pprint import pprint
import os
import sys
def followPerson(username: str, domain: str, followUsername: str, followDomain: str, followFile='following.txt') -> None:
"""Adds a person to the follow list
"""
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
if os.path.isfile(filename):
if handleToFollow in open(filename).read():
return
with open(filename, "a") as followfile:
followfile.write(handleToFollow+'\n')
return
with open(filename, "w") as followfile:
followfile.write(handleToFollow+'\n')
def followerOfPerson(username: str, domain: str, followerUsername: str, followerDomain: str) -> None:
followPerson(username, domain, followerUsername, followerDomain,'followers.txt')
def unfollowPerson(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
if os.path.isfile(filename):
if handleToUnfollow not in open(filename).read():
return
with open(filename, "r") as f:
lines = f.readlines()
with open(filename, "w") as f:
for line in lines:
if line.strip("\n") != handleToUnfollow:
f.write(line)
def unfollowerOfPerson(username: str, domain: str, followerUsername: str, followerDomain: str) -> None:
unfollowPerson(username, domain, followerUsername, followerDomain,'followers.txt')
def clearFollows(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:
clearFollows(username, domain,'followers.txt')