def __init__(self, from_conf, to_conf, db_sql_path): self.from_db = DB(from_conf) self.to_db = DB(to_conf) self.sql_array = [] sql_file = open(db_sql_path, 'r') q = "" for line in sql_file: line = line.strip() if line != "" and not line.startswith("--"): q += " " + line if q.endswith(";"): self.sql_array.append(q) q = ""
def initialize_dump(self): # self.stop_thread() for dbname in os.listdir(self.DUMP_DIR): if dbname.endswith('.sql'): dbname = dbname.replace(".sql", "") self.server_sql.create_db(dbname) db_config = self.config db_config['database'] = dbname db = DB(db_config) db.upload_sql(self.DUMP_DIR + self.DIR_SEP + dbname + ".sql") shutil.move(self.DUMP_DIR + self.DIR_SEP + dbname + ".sql", self.STRUCTURE_DIR + self.DIR_SEP) del (db) q = "select * from db where db_name='%s'" % dbname result = self.nebula_sql.select(q) if (len(result) == 0): q = "insert into db (db_name) values('%s')" % dbname id = self.nebula_sql.insert(q) else: id = result[0]['db_id'] q = "INSERT INTO `log`( `cloud_id`, `db_id`) SELECT cloud_id,'%s' from cloud WHERE type = 'main'" % id self.nebula_sql.insert(q)
def main(request): database = DB() list = database.getOrderList() car = database.getCarList() for elem in list: print elem return render(request, 'main_page.html', {'list': list, 'car': car})
def __init__(self): self.list = list() self.comments = [] # 评论结果 self.comments_userurl = [] # 从评论里面爬取到的用户url self.likes = [] # 赞爬取结果 self.queue = Queue() # 爬取队列对象 self.db = DB()
def main(request): database = DB() msgs = [] if 'fromLength' in request.GET and 'toLength' in request.GET \ and request.GET['fromLength'] != '' and request.GET['toLength'] != '': list = database.getOrderListByLength(int(request.GET['fromLength']), int(request.GET['toLength'])) msgs.append('by travel length') elif 'car_id' in request.GET and request.GET['car_id'] != '0': list = database.getOrderListByDriverID(int(request.GET['car_id'])) msgs.append('by driver name') elif 'excludeWord' in request.GET and request.GET['excludeWord'] != '': list = database.getListExcluded(request.GET['excludeWord']) msgs.append('without : ' + request.GET['excludeWord']) elif 'includeWord' in request.GET and request.GET['includeWord'] != '': list = database.getListIncluded(request.GET['includeWord']) msgs.append('with : ' + request.GET['includeWord']) else: list = database.getOrderList() car = database.getCarList() return render(request, 'main_page.html', { 'msgs': msgs, 'list': list, 'car': car })
def transporter(self, phone, phone_other, name, price, product_name, image_path, password, id, cate, description): thread = threading.Thread(target=DB.upload_product_image, args=( DB(), cate, image_path, phone, phone_other, name, price, product_name, password, id, description)) thread.start() thread.join() self.actively_reg()
def setTime(request): database = DB() if 'eventTime' in request.GET: database.setEventTime(request.GET['eventTime']) return redirect( reverse('index') + '?message=Time changed to ' + str(request.GET['eventTime'])) return redirect(reverse('index'))
def random_host(self, cloud_id): q = "SELECT * FROM cloud where cloud_id <> '%s' ORDER BY RAND() LIMIT 1;" % cloud_id result = self.nebula_sql.select(q) db = DB(self.get_config(result[0])) if (db.connection_status): return result[0] else: print "Connection to %s failed" % result[0]['host'] return False
def initialize_database(request): database = DB() database.initialization() # User.objects.initialize() # Product.objects.initialize() # Department.objects.initialize() return redirect('/')
def register_sub_server(self, host, username, password): config = {"host": host, "user": username, "password": password} db = DB(config) if db.connection_status(): q = "insert into cloud (host,username,password,type)values('%s','%s','%s','%s')" % ( host, username, password, "sub") self.nebula_sql.insert(q) return True else: return False
def __init__(self): self.DUMP_DIR = "dump" self.STRUCTURE_DIR = "structure" self.DIR_SEP = "/" self.NEBULA = False hostname = socket.gethostname() ip_addr = socket.gethostbyname(hostname) self.config = {"host": ip_addr, "user": "******", "password": "******"} self.server_sql = DB(self.config) nebula_config = self.config nebula_config['database'] = "nebula" self.nebula_sql = DB(nebula_config) self.update_main_ip(ip_addr)
def main(): db = DB("test.db") #db.genRandomUsers(200) result = db.dbExecute("select count(*) from users") print("Total entries:", result[0][0], end="") db.dbCloseConnection()
def addSale(request): database = DB() if request.method == 'GET': customers = database.getUsers() departments = database.getDepartments() products = database.getProducts() return render(request,'addSale.html', {'customers':customers, 'departments':departments, 'products':products}) elif request.method == 'POST': database.saveSale(request.POST['userId'],request.POST['productId'],request.POST['departmentId'], request.POST['saleType'],request.POST['saleDescription']) return redirect(reverse('index') + '?message=Added Sale')
def Business(self, product, quantity, phone): self.last_step_dialog() print("location:", self.location, '\n' "Product name:", product, '\n' "quantity:", quantity, '\n' "Total amount:", self.total_amount, '\n' "Phone number:", phone) if self.category_tp != "admin": from helped import connection_status as CS if CS.Network.internet(CS.Network()): self.spin_active = True thread = threading.Thread(target=DB.upload_data, args=( DB(), self.customer_phone, phone, self.location, quantity, self.total_amount, product)) thread.start() thread.join() toast("Ordered successfully!", 10) self.spin_active = False else: self.spin_active = False toast("Sorry try again!", 5) else: from helped import connection_status as CS if CS.Network.internet(CS.Network()): self.spin_active = True thread = threading.Thread(target=DB.upload_data_admin, args=( DB(), self.customer_phone, phone, self.location, quantity, self.total_amount, product)) thread.start() thread.join() toast("Ordered successfully!", 10) self.spin_active = False else: self.spin_active = False toast("Sorry try again!", 5)
def editSale(request, id): database = DB() if request.method == 'GET': customers = database.getUsers() departments = database.getDepartments() products = database.getProducts() sale = database.getSale(id) print sale return render(request,'editSale.html', {'customers':customers, 'departments':departments, 'products':products, 'sale': sale }) else: database.updateSale(id, request.POST['userId'],request.POST['productId'],request.POST['departmentId'], request.POST['saleType'],request.POST['saleDescription']) return redirect(reverse('index') + '?message=Changed Sale')
def capture_register(self): self.show_facial_register_GUI_signal.emit() name_text = self.name_line.text() password_text = self.password_line.text() self.register_account_pwd_signal.emit(name_text, password_text) DATABASE = DB() signup = Signup() face, facecode = signup.get_face() DATABASE.registration(name_text, 'student', facecode, password_text) em = QErrorMessage(self) em.setWindowTitle("success") em.showMessage("Success!")
def refresh_show(self): message_type = self.comboBox.currentText() self.pushButton.setText(message_type) database = DB() print(signup.login_user) if message_type == 'Personal': display = database.message_looking(signup.login_user) self.textEdit.setPlainText(display) if message_type == 'Group': display = database.group_message_looking(signup.login_user) self.textEdit.setPlainText(display) if message_type == 'ALL': display = database.message_looking('all') self.textEdit.setPlainText(display)
def Signing_in_admin_function(self, phone, password): if DB.Signing_in_admin(DB(), phone, password): self.admin_name = DB.name_admin self.remember_me_admin(phone, password, self.admin_name) if not self.admin_true: self.listen_db(phone) sm = self.root sm.current = "admin_main" else: if self.admin_true: toast("no internet connection") self.spin_active = False else: self.spin_active = False toast("oops! phone number or password in correct or internet connection")
def check_login(account, pwd): DATABASE = DB() password = DATABASE.password_looking(account)[0] print(account) print(password) if pwd == password: #print("login") signup.login_user = account print(signup.login_user) personal_pane.show() login_pane.hide() else: login_pane.show_error_animation()
def add(request): database = DB() if request.method == 'GET': address = database.getAddressList() car = database.getCarList() client = database.getClientList() return render(request, 'add_page.html', { 'address': address, 'car': car, 'client': client }) elif request.method == 'POST': database.saveOrder(request.POST['start_id'], request.POST['finish_id'], request.POST['car_id'], request.POST['client_id'], request.POST['entry-day-time']) return redirect('/')
def listView(request): database = DB() if 'fromAge' in request.GET and 'toAge' in request.GET: list = database.getSalesListByAge(int(request.GET['fromAge']), int(request.GET['toAge'])) elif 'departmentId' in request.GET: list = database.getSalesListByDepartmentID(int(request.GET['departmentId'])) elif 'excludeWord' in request.GET: list = database.getListExcluded(request.GET['excludeWord']) elif 'containsString' in request.GET: list = database.getListExcluded(request.GET['containsString']) else: list = database.getSalesList() departments = database.getDepartments() return render(request,'listpage.html',{'list':list, 'departments':departments})
def initialize_database(request): Address.objects.initialize() Car.objects.initialize() Client.objects.initialize() database = DB() TaxiOrder.model.objects.all().delete() from django.db import connection cur = connection.cursor() cur.execute("ALTER TABLE taxi_order AUTO_INCREMENT = 1") with open('order.csv', 'rb') as csvfile: passengers = csv.reader(csvfile, quotechar=',') for pas in passengers: car = Car.objects.get(id=int(pas[2])) client = Client.objects.get(id=int(pas[3])) start = Address.objects.get(id=int(pas[0])) finish = Address.objects.get(id=int(pas[1])) database.saveOrder(start, finish, car, client, pas[4]) return redirect('/')
def edit(request, id): database = DB() if request.method == 'GET': address = database.getAddressList() car = database.getCarList() client = database.getClientList() order = database.getOrder(id) return render(request, 'edit_page.html', { 'address': address, 'car': car, 'client': client, 'order': order }) else: database.updateOrder(id, request.POST['start_id'], request.POST['finish_id'], request.POST['car_id'], request.POST['client_id'], request.POST['entry-day-time']) return redirect('/')
def __init__(self): super().__init__() self.db = DB() self.title = "Word List" #self.winIcon() self.width = 600 self.height = 550 if sys.platform.startswith('win'): sizeObject = QtWidgets.QDesktopWidget().screenGeometry(-1) h_width = sizeObject.width() // 2 h_height = sizeObject.height() // 2 top = h_height - (self.height // 2) left = h_width - (self.width // 2) else: top = 0 left = 0 self.top = top self.left = left self.initWindow() self.show()
def __init__(self): super().__init__() self.db = DB() self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) self.title = "Capture Translate" #self.winIcon() self.width = 600 self.height = 550 if sys.platform.startswith('win'): sizeObject = QtWidgets.QDesktopWidget().screenGeometry(-1) h_width = sizeObject.width() // 2 h_height = sizeObject.height() // 2 top = h_height - (self.height // 2) left = h_width - (self.width // 2) else: top = 0 left = 0 self.top = top self.left = left self.initWindow()
import requests from sqlalchemy import create_engine, Table, Column, String, Float, MetaData from sqlalchemy.sql import select from Database import Database as DB from Providers import VisualCrossing db = DB('sqlite:///weather.sqlite3') db.AddTable("weather", date=str, mint=float, maxt=float, location=str, humidity=float) db.Create() provider = VisualCrossing() data = provider.Get('Volgograd,Russia', '2020-09-20', '2020-09-29') db.Insert("weather", data) selectResult = db.Select("weather") for row in selectResult: print(row)
new_links = 0 for page in pages: percent = round((index / count) * 100, 2) Log.log("Process progress: " + str(percent) + "% " + str(index) + "/" + str(count)) new_links += self.process(page[1]) Common.Wait() index += 1 Log.log("Process complete (" + str(new_links) + " new links)") def process(self, url): current_link = url Log.log("Current link is '" + current_link + "'") links = Parser.get_app_links_from_page(current_link) if links != -1: new_links = [] for link in links: insert_result = db.insert_app(link) if insert_result == 1: new_links.append(link) Log.log("Found " + str(len(links)) + " links") Log.log("New links: " + str(len(new_links)) + " " + str(new_links)) return len(new_links) else: Log.log("Page not found!") return 0 db = DB() pp = PageParser(db) pp.process_all()
def triggerOn(request): database = DB() database.enableTrigger() return redirect('/')
def triggerOff(request): database = DB() database.disableTrigger() return redirect('/')
def remove(request, id): database = DB() database.removeOrder(id) return redirect('/')