#!/usr/local/bin/python3.3 import cgi import cgitb import pymysql import datetime from functions import get_cookies, phead, ptail cgitb.enable() cookie = get_cookies() if cookie: print(cookie) fname = cookie["fname"].value lname = cookie["lname"].value name = " ".join((fname, lname)) admin = cookie["admin"].value uid = cookie["uid"].value uname = cookie["uname"].value form = cgi.FieldStorage() bid = form.getvalue('bid') q1 = """ select name, location from BEDfile where bid = "%s"; """ % bid data = [] #data should be in the order: user, passwd, host, db with open('./dbinfo.txt') as f: for line in f: line = line.strip('\n') data.append(line) info = [] for item in data: item = item.split(':') info.append(item) user=info[0][1] passwd=info[1][1] host=info[2][1] db=info[3][1] def runQuery(query, user, passwd): connection = pymysql.connect(host=host,db=db,user=user,passwd=passwd) cursor = connection.cursor() cursor.execute(query) res = cursor.fetchall() cursor.close() connection.close() return res def read_file(location): res = [] with open(location) as f: for i in f: i = i.split("\t") res.append(int(i[2]) - int(i[1])) return res def clean_lengths(results): if results: res = "" for i in results: res += "["+str(i)+"]," res = res[:-1] + "]);" else: res = None return res print("Content-type: text/html\n") phead(name, admin) print("""
""") if admin == "1": print('
  • admin

  • ') if bid != None: res = runQuery(q1, user, passwd) filename = res[0][0] feature_lengths = read_file(res[0][1]) cl_lengths = clean_lengths(feature_lengths) print("""
    """ % filename) ptail() else: print("Location: login.py") print("Content-type: text/html\n")