mirror of https://gitlab.com/bashrc2/epicyon
Undoing likes
parent
2b2ebd1347
commit
ab62e04721
28
epicyon.py
28
epicyon.py
|
@ -63,6 +63,8 @@ from utils import getDomainFromActor
|
||||||
from utils import getNicknameFromActor
|
from utils import getNicknameFromActor
|
||||||
from media import archiveMedia
|
from media import archiveMedia
|
||||||
from delete import sendDeleteViaServer
|
from delete import sendDeleteViaServer
|
||||||
|
from like import sendLikeViaServer
|
||||||
|
from like import sendUndoLikeViaServer
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
def str2bool(v):
|
def str2bool(v):
|
||||||
|
@ -171,6 +173,8 @@ parser.add_argument('--repeat','--announce', dest='announce', type=str,default=N
|
||||||
help='Announce/repeat a url')
|
help='Announce/repeat a url')
|
||||||
parser.add_argument('--favorite','--like', dest='like', type=str,default=None, \
|
parser.add_argument('--favorite','--like', dest='like', type=str,default=None, \
|
||||||
help='Like a url')
|
help='Like a url')
|
||||||
|
parser.add_argument('--undolike','--unlike', dest='undolike', type=str,default=None, \
|
||||||
|
help='Undo a like of a url')
|
||||||
parser.add_argument('--sendto', nargs='+',dest='sendto', \
|
parser.add_argument('--sendto', nargs='+',dest='sendto', \
|
||||||
help='List of post recipients')
|
help='List of post recipients')
|
||||||
parser.add_argument('--attach', dest='attach', type=str,default=None, \
|
parser.add_argument('--attach', dest='attach', type=str,default=None, \
|
||||||
|
@ -411,6 +415,30 @@ if args.like:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
if args.undolike:
|
||||||
|
if not nickname:
|
||||||
|
print('Specify a nickname with the --nickname option')
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
if not args.password:
|
||||||
|
print('Specify a password with the --password option')
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
session = createSession(domain,port,useTor)
|
||||||
|
personCache={}
|
||||||
|
cachedWebfingers={}
|
||||||
|
print('Sending undo like of '+args.undolike)
|
||||||
|
|
||||||
|
sendUndoLikeViaServer(session,nickname,args.password,
|
||||||
|
domain,port, \
|
||||||
|
httpPrefix,args.undolike, \
|
||||||
|
cachedWebfingers,personCache, \
|
||||||
|
True)
|
||||||
|
for i in range(10):
|
||||||
|
# TODO detect send success/fail
|
||||||
|
time.sleep(1)
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
if args.delete:
|
if args.delete:
|
||||||
if not nickname:
|
if not nickname:
|
||||||
print('Specify a nickname with the --nickname option')
|
print('Specify a nickname with the --nickname option')
|
||||||
|
|
73
like.py
73
like.py
|
@ -289,7 +289,7 @@ def sendLikeViaServer(session,fromNickname: str,password: str,
|
||||||
|
|
||||||
newLikeJson = {
|
newLikeJson = {
|
||||||
'type': 'Like',
|
'type': 'Like',
|
||||||
'actor': httpPrefix+'://'+fullDomain+'/users/'+nickname,
|
'actor': httpPrefix+'://'+fromDomainFull+'/users/'+fromNickname,
|
||||||
'object': likeUrl,
|
'object': likeUrl,
|
||||||
'to': [toUrl],
|
'to': [toUrl],
|
||||||
'cc': [ccUrl]
|
'cc': [ccUrl]
|
||||||
|
@ -335,3 +335,74 @@ def sendLikeViaServer(session,fromNickname: str,password: str,
|
||||||
print('DEBUG: c2s POST like success')
|
print('DEBUG: c2s POST like success')
|
||||||
|
|
||||||
return newLikeJson
|
return newLikeJson
|
||||||
|
|
||||||
|
def sendUndoLikeViaServer(session,fromNickname: str,password: str,
|
||||||
|
fromDomain: str,fromPort: int, \
|
||||||
|
httpPrefix: str,likeUrl: str, \
|
||||||
|
cachedWebfingers: {},personCache: {}, \
|
||||||
|
debug: bool) -> {}:
|
||||||
|
"""Undo a like via c2s
|
||||||
|
"""
|
||||||
|
if not session:
|
||||||
|
print('WARN: No session for sendUndoLikeViaServer')
|
||||||
|
return 6
|
||||||
|
|
||||||
|
fromDomainFull=fromDomain
|
||||||
|
if fromPort!=80 and fromPort!=443:
|
||||||
|
fromDomainFull=fromDomain+':'+str(fromPort)
|
||||||
|
|
||||||
|
toUrl = 'https://www.w3.org/ns/activitystreams#Public'
|
||||||
|
ccUrl = httpPrefix + '://'+fromDomainFull+'/users/'+fromNickname+'/followers'
|
||||||
|
|
||||||
|
newUndoLikeJson = {
|
||||||
|
'type': 'Undo',
|
||||||
|
'actor': httpPrefix+'://'+fromDomainFull+'/users/'+fromNickname,
|
||||||
|
'object': {
|
||||||
|
'type': 'Like',
|
||||||
|
'actor': httpPrefix+'://'+fromDomainFull+'/users/'+fromNickname,
|
||||||
|
'object': likeUrl,
|
||||||
|
'to': [toUrl],
|
||||||
|
'cc': [ccUrl]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handle=httpPrefix+'://'+fromDomainFull+'/@'+fromNickname
|
||||||
|
|
||||||
|
# lookup the inbox for the To handle
|
||||||
|
wfRequest = webfingerHandle(session,handle,httpPrefix,cachedWebfingers)
|
||||||
|
if not wfRequest:
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: announce webfinger failed for '+handle)
|
||||||
|
return 1
|
||||||
|
|
||||||
|
postToBox='outbox'
|
||||||
|
|
||||||
|
# get the actor inbox for the To handle
|
||||||
|
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition = \
|
||||||
|
getPersonBox(session,wfRequest,personCache,postToBox)
|
||||||
|
|
||||||
|
if not inboxUrl:
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: No '+postToBox+' was found for '+handle)
|
||||||
|
return 3
|
||||||
|
if not fromPersonId:
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: No actor was found for '+handle)
|
||||||
|
return 4
|
||||||
|
|
||||||
|
authHeader=createBasicAuthHeader(fromNickname,password)
|
||||||
|
|
||||||
|
headers = {'host': fromDomain, \
|
||||||
|
'Content-type': 'application/json', \
|
||||||
|
'Authorization': authHeader}
|
||||||
|
postResult = \
|
||||||
|
postJson(session,newUndoLikeJson,[],inboxUrl,headers,"inbox:write")
|
||||||
|
#if not postResult:
|
||||||
|
# if debug:
|
||||||
|
# print('DEBUG: POST announce failed for c2s to '+inboxUrl)
|
||||||
|
# return 5
|
||||||
|
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: c2s POST undo like success')
|
||||||
|
|
||||||
|
return newUndoLikeJson
|
||||||
|
|
Loading…
Reference in New Issue