def anonbump(me, it): data = dict( register_ajax='/regy', from_url=retrieve(me), what_url=retrieve(it), me=me, it=it, ) return render_template('anonbump.html', **data)
def show_history(): values = db.retrieve() if values: names = "\r\n".join( [f"{v['first name']} {v['last name']}" for v in values]) messagebox.showinfo('User History', names) else: messagebox.showinfo('User History', 'No history yet.')
def bump(me, it, you): if you == 'anon': return anonbump(me, it) data = dict( from_url=retrieve(me), iframe_url=retrieve(it), your_url=retrieve(you), me=me, it=it, you=you, ) if me != you: log.info('bump %s %s %s', me, it, you) try: record_bump(me, it, you) except: log.exception('bump to db') return render_template('bump.html', **data)
def test_find(): query = db.makeRecord("20 ROOT ROOT 2000 24") for i in db._attribute: indexname = i + '_' + name + '.json' res = db.find(query[i], indexname) if not res == None: lines = db.retrieve(res[0].keys[res[1]], database) print ('Records found in ' + indexname) db.printRecords(lines)
def fetchAllOperationHours(self): if len(self.all_operation_hours) <= 0: query = '''select operation_hours.day_id, days.name,operation_hours.start_time,operation_hours.end_time from operation_hours inner join days on operation_hours.day_id=days.id where stall_id={}; '''.format(self.id) rs = db.retrieve(query) [self.all_operation_hours.append( OperationHour(data['day_id'], data['name'], data['start_time'], data['end_time'])) for data in rs]
def node_search(request): nodes = retrieve('nodes') or [] query_val = request.GET.get('val') filtered_nodes = [] for node in nodes: if (query_val in node['val']): filtered_nodes.append(node) return JsonResponse({'data': filtered_nodes})
def nodes_detail(request, node_id): nodes = retrieve('nodes') or [] try: node = nodes[node_id] except KeyError: return JsonResponse( status=404, data={"error": f"Character with id {node_id!r} does not exist."}, ) return JsonResponse({"data": node})
def fetchAllMenu(self): query = '''SELECT menu_items.id,menu_items.name,menu_items.description,menu_items.pic_addr,menu_items.price,menu_items.stall_id,menu_items_time.day_id, days.name as day_name,menu_items_time.start_time,menu_items_time.end_time from menu_items INNER JOIN menu_items_time on menu_items.id=menu_items_time.menu_item_id INNER JOIN days on menu_items_time.day_id=days.id WHERE menu_items.stall_id={} group by menu_items.id order by menu_items.name; '''.format(self.id) self.menu_items_by_day = [MenuItem(data) for data in db.retrieve(query)]
def add_node(request): nodes = retrieve('nodes') or [] body = json.loads(request.body) val = body['val'] node = Node(val) nodes += [node.as_dict()] store('nodes', nodes) return JsonResponse({'data': node.as_dict()})
def example(): if request.method == "GET": uid = request.args.get("uid") key = retrieve(uid) if not key: pass return jsonify({"uid": uid, "key": key}) if request.method == "POST": data = request.get_json() try: uid = data.get("uid") key = data.get("key") return jsonify({"done": insertPublicKey(uid, key)}) except: return jsonify({"done": -1})
def fetchMenuByDay(self, day_id, time): # menu item items column doesn't require query = '''SELECT menu_items.id,menu_items.name,menu_items.description,menu_items.pic_addr,menu_items.price,menu_items.stall_id,menu_items_time.day_id, days.name as day_name,menu_items_time.start_time,menu_items_time.end_time from menu_items INNER JOIN menu_items_time on menu_items.id=menu_items_time.menu_item_id INNER JOIN days on menu_items_time.day_id=days.id WHERE menu_items.stall_id={} AND days.id={} AND time(menu_items_time.start_time)<='{}' AND '{}'<=time(menu_items_time.end_time) order by menu_items.name ; '''.format(self.id, day_id, time, time) self.menu_items_by_day = [MenuItem(data) for data in db.retrieve(query)]
def fetchStalls(day_id, time): # each store only has 1 store type, if not must use group concat query = '''select stalls.id,stalls.name,stalls.description,stalls.pic_addr,stalls.canteen_id,operation_hours.day_id,days.name as day_name,operation_hours.start_time,operation_hours.end_time, stall_types.name as stall_type from stalls inner join operation_hours on stalls.id = operation_hours.stall_id inner join days on operation_hours.day_id=days.id INNER JOIN stall_stall_types on stalls.id=stall_stall_types.stall_id INNER JOIN stall_types on stall_stall_types.stall_type_id=stall_types.id where operation_hours.day_id={} and time(operation_hours.start_time)<= time('{}') and time('{}') <=time(operation_hours.end_time) order by stalls.name'''.format(day_id, time, time) # result will be list of dictionary, below # {'id': 1, 'name': 'Chicken Rice', 'description': 'Tender chicken', 'piame,start_time,end_time,picc_addr': '', 'canteen_id': 1, 'day_id': 1, 'day_name': 'Monday', 'start_time': '09:30:00', 'end_time': '19:30:00'} result = db.retrieve(query) return [Stall(data) for data in result]
def test_rangefind(): range_query = {'ID':(0,10), 'surname':('pelopiou', 'ROOT'), 'name':('john', 'sotiris'), 'year':(2000, 2005), 'age':(20, 21)} for i in db._attribute: indexname = i + '_' + name + '.json' key1 = range_query[i][0] key2 = range_query[i][1] list = db.findRange(key1, key2, indexname) (MIN, MAX) = (key1, key2) if (key1>key2): (MIN, MAX) = (key2, key1) if not list == None: print ('--------------RECORDS FOUND IN ' + indexname + ' IN RANGE \'' + str(MIN) + '\', \'' + str(MAX) + '\'--------------') for i in list: lines = db.retrieve(i[0].keys[i[1]], database) db.printRecords(lines)
def nodes_list(request): nodes = retrieve('nodes') or [] return JsonResponse({"data": [node for node in nodes]})
def all(cls): target_class = globals()[cls.__name__] result = db.retrieve('select * from {}'.format((cls.__name__ + 's').lower())) return [target_class(data) for data in result]
def treefind(value): res = db.find(value, indexname) if not res == None: lines = db.retrieve(res[0].keys[res[1]], database) print ('Records found in ' + indexname) db.printRecords(lines)
#Insert Users print("\nInserting Users") for entry in users: db.insertUser(entry) printTable(db, tables[5]) #============================================================# #Update #============================================================# print("\nUpdating Tables") #Updating Parking Permits ID = 2 print("\nParking Permits") print("Updating Approved") print("Before:", db.retrieve(tables[0], "Permit_Number", 2)) db.updateParkingPermit("Approved", "Approved", 2) print("After:", db.retrieve(tables[0], "Permit_Number", 2)) #Updating Parking Violations ID = 3 print("\nParking Violations") print("Updating Vehicle_Type") print("Before:", db.retrieve(tables[1], "Citation_Number", 3)) db.updateParkingViolation("Vehicle_Type", "Two Wheeler", 3) print("After:", db.retrieve(tables[1], "Citation_Number", 3)) #Updating other Violations ID = 1 print("\nOther Violations") print("Updating Violation_Type") print("Before:", db.retrieve(tables[2], "Citation_Number", 1)) db.updateOtherViolation("Violation_Type", "Smoking", 1)
def event_stream(): for data in db.retrieve( stream, location ): for line in data.split( '\n' ): yield 'data: {0}\n'.format( line ) yield '\n'