commit c160203072ff2f37fc431f96b16c0c28b798553d Author: Wolfgang Nowak Date: Mon Oct 25 00:42:50 2021 +0200 mkupl.py - create a uniq upload link diff --git a/mkupl.py b/mkupl.py new file mode 100755 index 0000000..79898ce --- /dev/null +++ b/mkupl.py @@ -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()