Last active
December 11, 2015 21:48
-
-
Save xcombelle/4664743 to your computer and use it in GitHub Desktop.
a simple python 3 script to delete a pad in etherpad lite via http api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import urllib.request,urllib.parse | |
import argparse | |
import json | |
import sys | |
parser = argparse.ArgumentParser() | |
parser.add_argument("--apifile", help="Api file",default="APIKEY.txt") | |
parser.add_argument( "--hostname", help="Host name",default="localhost") | |
parser.add_argument("-p", "--port",help="Port",default="9001") | |
parser.add_argument("-k", "--apikey",help="Api key") | |
parser.add_argument("-f","--force",action="store_true",help="don't ask confirmation before deletion") | |
parser.add_argument("padid",help="Pad Id") | |
args = parser.parse_args() | |
if args.apikey and args.apifile!="APIKEY.txt": | |
print ("specify only apifile or key",file=sys.stderr) | |
sys.exit(1) | |
if not args.force: | |
confirm = input("delete pad: \""+args.padid+"\" ? ") | |
if not confirm=="y": | |
sys.exit(1) | |
if not args.apikey: | |
apikey = open(args.apifile).read() | |
else: | |
apikey = args.apikey | |
result = json.loads(urllib.request.urlopen("http://"+args.hostname+":"+args.port+"/api/1/deletePad?apikey="+urllib.parse.quote(apikey,"utf-8")+"&padID="+urllib.parse.quote(args.padid,"utf-8")).read().decode("utf-8")) | |
if result["code"] != 0: | |
print(result["message"],file=sys.stderr) | |
sys.exit(result["code"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment