Update
This commit is contained in:
parent
e2909d7c78
commit
a70485612a
|
@ -96,3 +96,6 @@ ENV/
|
|||
|
||||
# JSON data
|
||||
*.json
|
||||
|
||||
# URL collections
|
||||
urlcollections/*
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
import shlex, subprocess
|
||||
def createShellArgs(*args,**kwargs):
|
||||
rargs = []
|
||||
for k in kwargs:
|
||||
if len(k)==1:
|
||||
rargs.append("-{!s} {!r}".format(k,kwargs[k]))
|
||||
else:
|
||||
rargs.append("--{!s} {!r}".format(k.strip("_").replace("_","-"),kwargs[k]))
|
||||
rargs.extend(map(str,args))
|
||||
return " ".join(rargs)
|
||||
|
||||
class Program:
|
||||
def __init__(self,binary):
|
||||
self.binary = binary
|
||||
self.default_method = "run"
|
||||
|
||||
def __use_method(self,f,*args,**kwargs):
|
||||
cli = self.binary+" "+createShellArgs(*args,**kwargs)
|
||||
print(cli)
|
||||
return f(shlex.split(cli))
|
||||
|
||||
def __call__(self,*args,**kwargs):
|
||||
return getattr(self,self.default_method,self.run)(*args,**kwargs)
|
||||
|
||||
def run(self,*args,**kwargs):
|
||||
return self.__use_method(subprocess.run,*args,**kwargs)
|
||||
|
||||
def check_output(self,*args,**kwargs):
|
||||
return self.__use_method(subprocess.check_output,*args,**kwargs)
|
||||
|
||||
def call(self,*args,**kwargs):
|
||||
return self.__use_method(subprocess.call,*args,**kwargs)
|
||||
|
||||
def getoutput(self,*args,**kwargs):
|
||||
return self.__use_method(subprocess.getoutput,*args,**kwargs)
|
||||
|
||||
def check_call(self,*args,**kwargs):
|
||||
return self.__use_method(subprocess.check_call,*args,**kwargs)
|
||||
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
from datetime import datetime,tzinfo,timedelta
|
||||
|
||||
def readFile(filename):
|
||||
with open(filename) as f:
|
||||
return f.read()
|
||||
|
||||
class FixedOffset(tzinfo):
|
||||
def __init__(self,name,hours,minutes):
|
||||
self.__offset = timedelta(hours=hours,minutes=minutes)
|
||||
self.__name = name
|
||||
def utcoffset(self,d):
|
||||
return self.__offset
|
||||
def tzname(self):
|
||||
return self.__name
|
||||
def dst(self,d):
|
||||
return timedelta(0)
|
||||
|
||||
class CommonTimezones:
|
||||
UTC = FixedOffset("UTC",0,0)
|
||||
EST = FixedOffset("EST",-5,0)
|
||||
EDT = FixedOffset("EDT",-4,0)
|
||||
|
||||
def now_tz(tz="UTC"):
|
||||
if hasattr(CommonTimezones,tz):
|
||||
return datetime.now(tz=getattr(CommonTimezones,tz))
|
|
@ -0,0 +1,79 @@
|
|||
import plugin,dictdata,json,os
|
||||
|
||||
d = dictdata.DictData("urls.json")
|
||||
|
||||
def collections(): return sorted(list(d.value.keys()))
|
||||
|
||||
def getFilename():
|
||||
i = 0
|
||||
while os.path.exists("/home/khuxkm/public_html/public/urls-{:05d}.txt".format(i)):
|
||||
i+=1
|
||||
return "/home/khuxkm/public_html/public/urls-{:05d}.txt".format(i)
|
||||
|
||||
def writeCollection(c,fn):
|
||||
with open(fn,"w") as f:
|
||||
f.write("\n".join(d[c])+"\n")
|
||||
|
||||
@plugin.group("url","<list/new/add/remove/export/expire/dump> [args]")
|
||||
def url(self,channel,nick,subcmd,*args):
|
||||
d.load(d.filename)
|
||||
if subcmd not in "list new add remove export dump expire":
|
||||
return True
|
||||
return False
|
||||
|
||||
@url.command("list")
|
||||
def url_list(self,channel,nick,subcmd,name=None):
|
||||
if name is None:
|
||||
self.say(channel,"{}: Collections: {}".format(nick,", ".join(collections())))
|
||||
elif name in collections():
|
||||
self.say(channel,"{}: URLs in this list include: {}".format(nick,", ".join(d.get(name,[])[-3:])))
|
||||
else:
|
||||
self.say(channel,"{}: No such collection {!r}".format(nick,name))
|
||||
|
||||
@url.command("new")
|
||||
def url_new(self,channel,nick,subcmd,name):
|
||||
if name in collections():
|
||||
self.say(channel,"{}: Collection {!r} already exists".format(nick,name))
|
||||
return
|
||||
d[name]=[]
|
||||
d.save(d.filename)
|
||||
|
||||
@url.command("expire")
|
||||
def url_expire(self,channel,nick,subcmd,name):
|
||||
if name not in collections():
|
||||
self.say(channel,"{}: Collection {!r} doesn't exist".format(nick,name))
|
||||
return
|
||||
del d.value[name]
|
||||
d.save(d.filename)
|
||||
|
||||
@url.command("add")
|
||||
def url_add(self,channel,nick,subcmd,collection,u):
|
||||
if collection not in collections():
|
||||
self.say(channel,"{}: No collection {!r}".format(nick,collection))
|
||||
return
|
||||
d[collection].append(u)
|
||||
d.save(d.filename)
|
||||
|
||||
@url.command("remove")
|
||||
def url_remove(self,channel,nick,subcmd,collection,u):
|
||||
if collection not in collections():
|
||||
self.say(channel,"{}: No collection {!r}".format(nick,collection))
|
||||
return
|
||||
if u not in d[collection]:
|
||||
return
|
||||
d[collection].remove(u)
|
||||
d.save(d.filename)
|
||||
|
||||
@url.command("dump")
|
||||
def url_dump(self,channel,nick,*args):
|
||||
self.say(nick,d.serialize())
|
||||
|
||||
@url.command("export")
|
||||
def url_export(self,channel,nick,subcmd,collection):
|
||||
if collection not in collections():
|
||||
self.say(channel,"{}: No collection {!r}".format(nick,collection))
|
||||
return
|
||||
fn = getFilename()
|
||||
out = fn.replace("/home/khuxkm/public_html","https://khuxkm.fuckup.club")
|
||||
writeCollection(collection,fn)
|
||||
self.say(channel,"{}: Collection {!r} exported to {}".format(nick,collection,out))
|
Reference in New Issue