mkupl.py - create a uniq upload link

This commit is contained in:
Wolfgang Nowak 2021-10-25 00:42:50 +02:00
commit c160203072

36
mkupl.py Executable file
View file

@ -0,0 +1,36 @@
#!/usr/bin/python3
import sys, os, pg, uuid, shutil
"""
Generates a uniq uploadlink
"""
try:
datenbank = pg.connect(
# dbname="datenpunk", host="somehost", user="donald", passwd="blablabla"
dbname="wn"
)
except:
sys.exit("\nCan't find my database. Doing nothing :(\n")
dbtable = "uploadlinks"
prefix = "uplgenid-"
sourcedir = os.path.expanduser("~/")
sourcefile = sourcedir + "up.php"
targetdir = os.path.expanduser("~/www/i21k.de/")
targetfilename = prefix + str(uuid.uuid4()) + ".php"
targetfile = targetdir + targetfilename
uploaduser = input("Bitte gib einen Kontext an, z.B. einen Usernamen: ")
print("Copying ", sourcefile, "to", targetfile)
shutil.copy(sourcefile, targetfile)
print("Generating databaseentry for user", uploaduser)
dbuploadquery = "insert into " + dbtable + " (benutzer, phpfile) values ('" + uploaduser + "','" + targetfilename + "');"
print(dbuploadquery)
try:
dbentry = datenbank.query(dbuploadquery)
except:
sys.exit("\nError bei Abfrage: " + dbuploadquery)
datenbank.close()