def update_setting(self, key, value): """ Update the value of a setting in the database. Arguments: key (str): The setting to change value (str): The value to change the setting to """ db.modify('settings', 'value=%s', (value, key), where='skey=%s')
def set_status(self, new_status): """ Set the status of the request, and update the database to reflect the new status Arguments: new_status (PCRStatus): New status for the request """ self.status = new_status db.modify('pcr', 'status=%s', (int(self.status), self.id), where='id=%s')
def change_user_password(self, username, newpw): """ Set the given user's password to the given password. Arguments: username (str): The user to change the password for newpw (str): The new password """ newpw = newpw.encode('utf-8') pwhash = bcrypt.hashpw(newpw, bcrypt.gensalt()) db.modify('users', 'password=%s', (pwhash, username), where='username=%s')
def service_request(self): """ Service this request, updating account credentials in the database, and updating the current status of the request """ for cred in self.creds: username, password = cred db.set_credential_password(username, password, self.team_id, self.check_id, self.domain) self.completed = datetime.datetime.now() db.modify('pcr', 'completed=%s', (self.completed, self.id), where='id=%s') self.set_status(PCRStatus.COMPLETE)
delete(id) return redirect('/userlist') @app.route('/update',methods=['POST','GET']) def update(): if not session.get('name',None): return redirect('login') if request.method == 'POST': data = dict(request.form) ''' condition = ["%s='%s'" % (k,v[0]) for k,v in data.items()] sql = 'update users set %s where id = %s' % (','.join(condition),data['id'][0]) cur.execute(sql) ''' modify(data) return redirect('/userlist') else: id = request.args.get('id',None) if not id: errmsg = 'must have id' return render_template('update.html',result=errmsg) fields = ['id', 'name', 'name_cn', 'email', 'mobile'] ''' try: sql = 'select %s from users where id = %s ' % (','.join(fields),id) cur.execute(sql) res = cur.fetchone() user = dict((k,res[i]) for i,k in enumerate(fields)) return render_template('update.html', user = user) except:
import db import sys from threading import Thread if __name__ == '__main__': if len(sys.argv) > 3: print("Usage: ./engine [start|stop] [team_number]") if len(sys.argv) == 2: engine = ScoringEngine() if len(sys.argv) == 3: team_num = int(sys.argv[2]) - 1 engine = ScoringEngine(team_num) if sys.argv[1] == 'start': file_manager = FileManager() file_manager_thread = Thread(target=file_manager.manage_files) file_manager_thread.start() db.modify('settings', set='value=%s', where='skey=%s', args=(True, 'running')) engine.start() elif sys.argv[1] == 'stop': db.modify('settings', set='value=%s', where='skey=%s', args=(False, 'running')) else: print("Usage: ./engine [start|stop] [team_number]")
def POST(self): db_info = [] form = web.input() layout_txt = form.layoutfile reader = csv.reader(cStringIO.StringIO(layout_txt)) nodes, lanes, links, phases = {}, {}, {}, {} heading = "" for row in reader: try: if len(row) == 0: heading = "" elif "[" in row[0]: heading = row[0][1:-1] elif heading == "Nodes" and row[1] == "0": nodes[row[0]] = {"int_id": row[0]} links[row[0]] = [[], []] lanes[row[0]] = {"speed": [], "phase": [], "peds": []} phases[row[0]] = [] elif heading == "Links": if row[0] == "RECORDNAME": links["col"] = row[2:] elif row[0] == "Grade" and row[1] in nodes.keys(): links[row[1]][0] = row[2:] elif row[0] == "Name" and row[1] in nodes.keys(): links[row[1]][1] = row[2:] elif heading == "Lanes": if row[0] == "RECORDNAME": lanes["col"] = row[2:] elif row[1] not in lanes.keys(): continue elif row[0] == "Speed": lanes[row[1]]["speed"] = row[2:] elif row[0] == "Phase1": lanes[row[1]]["phase"] = row[2:] elif row[0] == "Peds": lanes[row[1]]["peds"] = row[2:] elif heading == "Phases": if row[0] == "RECORDNAME": phases["col"] = [p[1:] for p in row[2:]] elif row[0] == "BRP" and row[1] in phases.keys(): phases[row[1]] = row[2:] except IndexError: pass lanes_mod = {} for int_id in nodes.keys(): if int_id == "col": continue matrix = [] str_phases = map(str, range(1, num_phases + 1)) brp = list(set(phases[int_id])) if "" in brp: brp.remove("") brp.sort() maxes, phase_maxes = [], [] for index in range(len(brp)): if len(brp) == index + 1: maxes.append(brp[index]) elif brp[index][:2] != brp[index + 1][:2]: maxes.append(brp[index]) for index in range(len(maxes)): phase = phases["col"][phases[int_id].index(maxes[index])] if phase in lanes[int_id]["phase"]: phase_maxes.append(phase) else: phase_maxes.append("") for index in range(len(lanes[int_id]["phase"])): phase = lanes[int_id]["phase"][index] dirs = lanes["col"][index] speed = lanes[int_id]["speed"][index] peds = lanes[int_id]["peds"][index] mov = "" speed = speed or "0" if "L" in dirs: mov = "on" speed = "20" peds = peds or "0" if dirs[:2] in links["col"]: i = links["col"].index(dirs[:2]) road = links[int_id][1][i] grade = links[int_id][0][i] else: road = "" grade = "" end = [] if phase in phase_maxes: barrier = maxes[phase_maxes.index(phase)][0] print barrier for brp in maxes: if brp[0] == barrier: p = phase_maxes[maxes.index(brp)] if p and p != phase and int(p) > 0 and int(p) <= num_phases: end.append(p) end = ",".join(end) if phase in str_phases: matrix.append([phase, dirs, speed, grade, mov, road, end]) str_phases.pop(str_phases.index(phase)) for phase in str_phases: matrix.append([phase] + [""] * 7) matrix.sort(key=lambda x: x[0]) lanes_mod[int_id] = zip(*matrix) for int_id in nodes.keys(): nodes[int_id]["dir"] = ";".join(lanes_mod[int_id][1]) nodes[int_id]["speed"] = ";".join(lanes_mod[int_id][2]) nodes[int_id]["grade"] = ";".join(lanes_mod[int_id][3]) nodes[int_id]["mov"] = ";".join(lanes_mod[int_id][4]) nodes[int_id]["road"] = ";".join(lanes_mod[int_id][5]) nodes[int_id]["end"] = ";".join(lanes_mod[int_id][6]) nodes[int_id]["min_walk"] = "7" names = list(set(links[int_id][1])) if "" in names: names.remove("") if len(names) > 1: nodes[int_id]["minor"] = names[1] if len(names) > 0: nodes[int_id]["major"] = names[0] db.modify(**nodes[int_id]) raise web.seeother("/")
def POST(self): form = dict(web.input()) db.modify(**form) raise web.seeother("/overview")
def POST(self): form = dict(web.input()) db.modify(**form) raise web.seeother("/intersection" + "?IntID=" + form["int_id"])