def create_room(idroom, name, idowner, username): # simpan ke database db, cursor = connectDB() cursor.execute("""INSERT INTO room (id, name, idowner, username) VALUES (%s, %s, %s, %s)""", (idroom, name, idowner, username)) db.commit() self.publish('chat.on_room_created', 'success') return "success"
def delete_room(idroom): # hapus room db, cursor = connectDB() cursor.execute("""DELETE FROM room WHERE id={0}""".format(idroom)) db.commit() self.publish('chat.on_room_deleted', 'success') return "success"
def MenuAddItemPost(): mycol = connectDB('Menu') menu = Menu() menu.dish = request.form["dish"] menu.dishName = request.form["dishName"] menu.dishSize = request.form["dishSize"] menu.dishPrice = request.form["dishPrice"] dictmenu = (menu.__dict__) mycol.insert(dictmenu) return render_template('addmenu.html')
def CheckPermissions(username, requriedPermissions): #ÄNDRA TILL tokenID här! mycol = connectDB('Employees') query = {"username": username} #ÄNDRA TILL tokenID här! employee = mycol.find_one(query) if employee['permissions'] == requriedPermissions: return True else: return False
def employeelogin(): mycol = connectDB('Employees') if request.method == 'POST': query = {"username": request.form['username']} employee = mycol.find_one(query) if employee == None: return render_template('customerror.html') session.pop('user', None) if request.form['password'] == employee['password']: session['user'] = request.form['username'] return redirect(url_for('dashboard')) return render_template('employeeloginpage.html')
def RegisterEmployeesPost(): mycol = connectDB('Employees') e = Employee() e.firstname = request.form["Firstname"] e.lastname = request.form["Lastname"] e.email = request.form["Email"] e.permissions = request.form["Permissions"] e.username = request.form["Username"] e.password = request.form["Password"] e.tokenID = "empty" dicte = (e.__dict__) mycol.insert(dicte) return render_template('registeremployees.html')
def RegisterCustomersPost(): mycol = connectDB('Customers') customer = Customer() customer.firstname = request.form["Firstname"] customer.lastname = request.form["Lastname"] customer.email = request.form["Email"] customer.address = request.form["Adress"] customer.postcode = request.form["Postcode"] customer.city = request.form["City"] customer.username = request.form["Username"] customer.password = request.form["Password"] dictcustomer = (customer.__dict__) mycol.insert(dictcustomer) return render_template('registercustomer.html')
def getWordInfo(word): _, _, _, wordDB, *_ = connectDB(host) if wordDB['word'].find_one({"word": word}): data = wordDB['word'].find_one({"word": word}) return data['syn'], data['atn'] n_syn, n_atn = crawlNaver(word) syn = n_syn atn = n_atn ts = set(syn) ts.discard(word) syn = list(ts) ts = set(atn) ts.discard(word) atn = list(ts) wordDB['word'].insert_one({ 'word': word, 'syn': syn, 'atn': atn }) return syn, atn
def setUp(self): # A and B are similar Aps = [[0.5, 0.5], [1, 1.5], [2, 2.5], [3.5, 3.5], [5.2, 4.5], [7.5, 6.5], [7.9, 8]] Bps = [[0.6, 0.5], [1.05, 1.45], [2.1, 2.4], [2.8, 4], [3.5, 5.5], [5, 5.7], [7.8, 5.7], [8.1, 6.5], [8.1, 8]] # C intersects B sligthly Cps = [[7.8, 6.1], [8.5, 5.5], [9.1, 4.5], [9.5, 3.3], [9.8, 1.7]] # D's bounding box doesn't intersect Dps = [[11, 1], [11, 2], [11, 3], [10.5, 4.5], [10, 5], [10.5, 5.5], [11, 6]] time = datetime.now() dt = timedelta(1000) def pt_arr_to_track(pts): seg = Segment(map(lambda p: Point(None, p[0], p[1], time + dt), pts)) return Track(name="TripA", segments=[seg]) self.tripA = pt_arr_to_track(Aps) self.tripA.toTrip(name="A") self.tripB = pt_arr_to_track(Bps) self.tripB.toTrip(name="B") self.tripC = pt_arr_to_track(Cps) self.tripC.toTrip(name="C") self.tripD = pt_arr_to_track(Dps) self.tripD.toTrip(name="D") conn = db.connectDB() cur = conn.cursor() cur.execute(drop) cur.execute(schema) conn.commit() self.conn = conn self.cur = cur
from db import connectDB import pandas as pd host = 'localhost' ds_size = 10000 test_rate = 0.1 if __name__ == '__main__': _, _, _, _, vecDB, *_ = connectDB(host) li = list(vecDB['data'].find().limit(ds_size)) ls = list(vecDB['snu'].find()) print(1) test_size = int(len(li) * test_rate) test_size_s = int(len(ls) * test_rate) test_ds = [] train_ds = [] for i in range(test_size): try: if len(li[i]['nounlist']) > 50 or len(li[i]['verblist']) > 30: continue if li[i]['fact']: ds_one = [5.0] else: ds_one = [1.0] ds_one += li[i]['subject'] ds_one += li[i]['mainverb'] for j in li[i]['nounlist']: ds_one += j for j in range((50 - len(li[i]['nounlist'])) * 200): ds_one.append(0) for j in li[i]['verblist']:
from telethon.tl.functions.channels import JoinChannelRequest from telethon.sync import events from telethon import functions, types from telethon.tl.types import PeerChannel, PeerUser from telethon.tl.types import MessageMediaPhoto from telethon.utils import get_input_photo, resolve_bot_file_id, pack_bot_file_id import telethon import app_functions as funcs import requests import db # from rules import filterMessage import sys import os from responses import responses db.connectDB() client_name = 'client' bot_name = 'bot' API_ID = 1945628 API_HASH = '2c96a07930fe107684ab108250886d49' BOT_TOKEN = '' client = TelegramClient(client_name, API_ID, API_HASH) bot = TelegramClient(bot_name, API_ID, API_HASH) client.start() bot.start(bot_token=BOT_TOKEN) @bot.on(events.NewMessage)
def list_room(): db, cursor = connectDB(True) cursor.execute("""SELECT * FROM room""") rows = cursor.fetchall() return json.dumps(rows, ensure_ascii=False)
def GetMenu(): mycol = connectDB('Menu') return render_template('menuindex.html', menu=mycol.find())
def GetCustomers(): mycol = connectDB('Customers') return render_template('customersindex.html', allcustomers=mycol.find())
def ordermenu(): mycol = connectDB('Menu') return render_template('ordermenu.html', menu=mycol.find())
def before_request(): g.db = db.connectDB()