Deleting posts

master
Bob Mottram 2019-06-29 12:47:33 +01:00
parent 41d68a0e05
commit 162d3944e4
3 changed files with 22 additions and 4 deletions

View File

@ -3,6 +3,7 @@
Some experiments with ActivityPub in Python.
Based on the specification: https://www.w3.org/TR/activitypub
Also: https://raw.githubusercontent.com/w3c/activitypub/gh-pages/activitypub-tutorial.txt
## Install

View File

@ -12,6 +12,7 @@ from person import setBio
from webfinger import webfingerHandle
from posts import getUserPosts
from posts import createPublicPost
from posts import deleteAllPosts
from session import createSession
import json
import sys
@ -31,14 +32,15 @@ useTor=False
session = createSession(useTor)
privateKeyPem,publicKeyPem,person,wfEndpoint=createPerson(username,domain,https,True)
deleteAllPosts(username,domain)
setPreferredUsername(username,domain,'badger')
setBio(username,domain,'Some personal info')
#createPublicPost(username, domain, https, "G'day world!", False, True, None, None, 'Not suitable for Vogons')
createPublicPost(username, domain, https, "G'day world!", False, True, None, None, 'Not suitable for Vogons')
#runDaemon(domain,port,federationList,useTor)
#testHttpsig()
#sys.exit()
sys.exit()
#pprint(person)
#print('\n')

View File

@ -11,7 +11,7 @@ import json
import commentjson
import html
import datetime
import os
import os, shutil
from pprint import pprint
from random import randint
from session import getJson
@ -167,8 +167,22 @@ def createOutboxDir(username: str,domain: str) -> (str,str):
outboxJsonFilename=baseDir+'/accounts/'+handle+'/outbox.json'
return outboxJsonFilename,outboxDir
def deleteAllPosts(username: str, domain: str) -> None:
"""Deletes all posts for a person
"""
outboxJsonFilename,outboxDir = createOutboxDir(username,domain)
for deleteFilename in os.listdir(outboxDir):
filePath = os.path.join(outboxDir, deleteFilename)
try:
if os.path.isfile(filePath):
os.unlink(filePath)
elif os.path.isdir(filePath): shutil.rmtree(filePath)
except Exception as e:
print(e)
# TODO update output feed
def createPublicPost(username: str, domain: str, https: bool, content: str, followersOnly: bool, saveToFile: bool, inReplyTo=None, inReplyToAtomUri=None, subject=None) -> {}:
"""Creates a post
"""Creates a public post
"""
prefix='https'
if not https:
@ -232,6 +246,7 @@ def createPublicPost(username: str, domain: str, https: bool, content: str, foll
filename=outboxDir+'/'+newPostId.replace('/','#')+'.json'
with open(filename, 'w') as fp:
commentjson.dump(newPost, fp, indent=4, sort_keys=False)
# TODO update output feed
return newPost
def createOutbox(username: str,domain: str,https: bool,noOfItems: int):