def shorten(): conn = psycopg2.connect( # connects to db host="localhost", database="urls", user="******", password="******") db = conn.cursor() # creates the cursor for the connection new_url = generate() # database limit is 25 characters original_url = request.form.get("url") # gets the url from user input qr_id = 'qr_codes/' + str(generate_qr( new_url)) + '.png' # generates the path for the qr code image if original_url == "" or not url_validator(original_url): return redirect("/") #TODO: make it redirect to error try: db.execute("SELECT new_url FROM urls WHERE original_url=%s", (original_url, )) duplicate_url = db.fetchone()[0] except TypeError: duplicate_url = False if duplicate_url != False: new_url = duplicate_url else: db.execute("INSERT INTO urls (original_url, new_url) VALUES (%s, %s)", (original_url, new_url)) conn.commit() return render_template("index.html", new_url=new_url, qr_id=qr_id)
def generate(dest): input_dir = os.path.join('examples', 'simple') return helpers.generate(input_dir, dest)
import copy from insertion import insertion from helpers import generate from selection import selection from merge import mergesort from heap import heapsort from quicksort import quicksort import time small_int_data = [240, 291, 110, 305, 88, 73, 547, 4, 606, 775, 156] data = [small_int_data, generate(10)] print(data) print("data stop\n") def sort(X): X.sort() return X def is_sorted(A): for nr, x in enumerate(A[:-1]): if x > A[nr+1]: return False else: return True sorting = [sort, selection, mergesort, heapsort, quicksort]
def populated_output_dir(populated_input_dir, output_dir): result = helpers.generate(populated_input_dir, output_dir) assert result.returncode == 0 yield output_dir
import sys import os this_dir = os.path.dirname(os.path.abspath(__file__)) needed_dir = os.path.abspath(os.path.join(this_dir, '../.')) sys.path.insert(0, needed_dir) from helpers import generate if __name__ == "__main__": print("USAGE: file.py id") id = None count = 10 fileFormat = "pgm" if len(sys.argv) >= 2: id = int(sys.argv[1]) if len(sys.argv) >= 3: count = int(sys.argv[2]) if len(sys.argv) >= 4: fileFormat = sys.argv[3] generate(id=id, count=count, fileFormat=fileFormat)