#!/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()