def socket_connection(self): host = '10.20.3.83' port = 34000 sockett = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sockett.bind((host, port)) sockett.listen(1) connection, address = sockett.accept() print('Connected by ', address) boolean = 'true' while boolean: values = connection.recv(4096) datum = json.loads(values) if datum[0] > 0: self.insert_value(datum) if values: print(datum[0]) print(type(datum[0])) if datum[0] == -1: connection.send(values) connection.close() break print(boolean) connection.send(values) sockett.listen(1) connection, address = sockett.accept() connection.close() print('finish')
def update_slot_to_free(self): connection = db_connection.connect() cursor = connection.cursor() try: cursor.execute("select slot from vehicle_details where vehicle_number='{}'".format(self.vehical_entry.get())) slot = cursor.fetchone() if slot == None or slot[0] != int(self.slot_entry.get()): messagebox.showerror("Error", "Sorry, you have not booked this slot.", parent=self.toplevel_free_slot) return cursor.execute("update slot SET booked_status='Available' where slot_number={}".format(self.slot_entry.get())) connection.commit() self.vehical_entry.delete(0, END) self.slot_entry.delete(0, END) messagebox.showinfo("Successful", "Slot is free now..", parent=self.toplevel_free_slot) except Exception as e: connection.rollback() messagebox.showerror("Error", e, parent=self.toplevel_free_slot) print(e) connection.close()
def savePesticides(list): connection = Pesticide.connection cursor = Pesticide.cursor sql = "INSERT INTO tarimsal(isim, fiyat, hastalik, dozaj, kullanim, tip) VALUES (%s, %s, %s, %s, %s, %s)" values = list cursor.executemany(sql, values) try: connection.commit() except mysql.connector.Error as err: pass finally: connection.close()
def executemysqlquery(self, query): """ docstring """ connection = mysql.connector.connect(cfg.mysql["host"], cfg.mysql["user"], cfg.mysql["password"]) cursor = connection.cursor(dictionary=True) cursor.execute(query) results = cursor.fetchall() cursor.close() connection.close() return results
def updatePesticidePrice(isim, fiyat): connection = Pesticide.connection cursor = Pesticide.cursor isim = isim fiyat = fiyat sql = "UPDATE tarimsal SET fiyat= %s WHERE isim = %s" values = (fiyat, isim) cursor.execute(sql, values) try: connection.commit() except mysql.connector.Error as err: pass finally: connection.close()
def deletePesticide(isim): connection = Pesticide.connection cursor = connection.cursor() isim = isim value = str(isim) sql = """delete from tarimsal where isim = %s""" cursor.execute(sql, (value,)) try: connection.commit() except mysql.connector.Error as err: pass finally: connection.close()
def remove_table(): try: connection = create_server_connection() cursor = connection.cursor() mySql_insert_query = """DELETE FROM perfilcores""" cursor.execute(mySql_insert_query) connection.commit() print("Record removed successfully perfilcores table") except mysql.connector.Error as error: print("Failed to remove MySQL table {}".format(error)) finally: if connection.is_connected(): cursor.close() connection.close() print("MySQL connection is closed")
def updatePesticideDisease(isim, hastalik): connection = Pesticide.connection cursor = Pesticide.cursor isim = isim hastalik = hastalik sql = "UPDATE tarimsal SET hastalik= %s WHERE isim = %s" values = (hastalik, isim) cursor.execute(sql, values) try: connection.commit() except mysql.connector.Error as err: pass finally: connection.close()
def save_form_data(self): connection = db_connection.connect() cursor = connection.cursor() try: cursor.execute("insert into vehicle_details(full_name, vehicle_number, phone_number, gender, slot) values ('{}', '{}', {}, '{}', '{}')".format((self.fnameEntry.get()+" "+ self.lnameEntry.get()), self.velicle_num_Entry.get(), int(self.telnumEntry.get()), self.gender.get(), self.availabel_slot)) connection.commit() cursor.execute("update slot SET booked_status='Booked' where slot_number={}".format(self.availabel_slot)) connection.commit() messagebox.showinfo("Successful", "Slot Booked successfully..", parent=self.toplevel) except Exception as e: connection.rollback() messagebox.showerror("Error", e, parent=self.toplevel) print(e) connection.close() self.resetForm()
def insert_varibles_into_table(codigo_item, seq_cor, desc_cor, anilox, densidade, tv, lab): try: connection = create_server_connection() cursor = connection.cursor() mySql_insert_query = """INSERT INTO perfilcores (codigo_item, seq_cor, desc_cor, anilox, densidade, tv, lab) VALUES (%s, %s, %s, %s, %s, %s, %s) """ record = (codigo_item, seq_cor, desc_cor, anilox, densidade, tv, lab) print(record) cursor.execute(mySql_insert_query, record) connection.commit() print("Record inserted successfully into perfilcores table") except mysql.connector.Error as error: print("Failed to insert into MySQL table {}".format(error)) finally: if connection.is_connected(): cursor.close() connection.close() print("MySQL connection is closed")
def authenticate(self): self.__username = self.username_entry.get() self.__password = self.password_entry.get() if len(self.__username) <= 0: messagebox.showerror("Invalid Credentials", "Please enter the username", parent=self.master) self.username_entry.delete(0, END) self.username_entry.focus() return if len(self.__password) <= 0: messagebox.showerror("Invalid Credentials", "Please enter the password", parent=self.master) self.password_entry.delete(0, END) self.password_entry.focus() return connection = db_connection.connect() cursor = connection.cursor() try: cursor.execute("SELECT * from users where username='******'".format(self.__username)) data = cursor.fetchone() print(data) if data == None or data[2] != self.__password: messagebox.showerror("Invalid Credentials", "Your credentials are invalid. Please try again.") self.username_entry.delete(0, END) self.password_entry.delete(0, END) self.username_entry.focus() return connection.close() except Exception as e: connection.rollback() messagebox.showerror("Error", e, parent=self.master) print(e) return print("Username", self.__username, "is logged in into the system..") Remove.remove_all_widgets(self.loginFrame) self.homePortal()
def insert_varibles_into_table(recurso, etapa, seq_fila, op, cod_item, desc_item, cod_clicheria, iniprog, fimprog, mrp): try: connection = create_server_connection() cursor = connection.cursor() mySql_insert_query = """INSERT INTO pcpfila (recurso, etapa, seq_fila, op, codigo_item, descricao_item, cod_clicheria, inicioprog, fimprog, mrp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s) """ record = (recurso, etapa, seq_fila, op, cod_item, desc_item, cod_clicheria, iniprog, fimprog, mrp) print(record) cursor.execute(mySql_insert_query, record) connection.commit() print("Record inserted successfully into fila table") except mysql.connector.Error as error: print("Failed to insert into MySQL table {}".format(error)) finally: if connection.is_connected(): cursor.close() connection.close() print("MySQL connection is closed")
def homePortal(self): self.vehicle_records = list() connection = db_connection.connect() cursor = connection.cursor() try: cursor.execute("select * from vehicle_details where DATE(time_stamp)='{}'".format(date.today())) data = cursor.fetchall() if len(data) > 0: for i in data: temp = [] temp.append(i[0]) temp.append(i[1]) temp.append(i[2]) todays_date = str(i[6]).split(' ')[0] temp.append(todays_date) temp.append(i[5]) self.vehicle_records.append(temp) except Exception as e: connection.rollback() messagebox.showerror("Error", e, parent=self.master) print(e) connection.close() heading = Label(self.master, text="Vehicle Parking Management System", font="verdana 22 bold", bg=self.color) heading.grid(row=0, column=0, padx=(250,0), pady=20) self.navFrame = LabelFrame(self.master, text="") self.navFrame.grid(row=1, column=0, padx=(250,0), pady=50) self.vehicle_entry_portal_btn = Button(self.navFrame, text="Vehicle Entry", font=self.font , bg="#ff55ff", fg="#fff", command=lambda: self.vehicle_entry()) self.vehicle_entry_portal_btn.grid(row=0, column=0, padx=20, pady=20) self.veiw_slot_portal_btn = Button(self.navFrame, text="View Available Slots", font=self.font , bg="#ff55ff", fg="#fff", command=lambda: self.view_available_slots()) self.veiw_slot_portal_btn.grid(row=0, column=1, padx=20, pady=20) self.free_slot_btn = Button(self.navFrame, text="Free Slot", font=self.font , bg="#ff55ff", fg="#fff", command=lambda: self.free_slot()) self.free_slot_btn.grid(row=0, column=2, padx=20, pady=20) self.logout_btn = Button(self.navFrame, text="Logout", bg="#ff55ff", font=self.font , fg="#fff", command= lambda: self.logout()) self.logout_btn.grid(row=0, column=3, padx=20, pady=20) self.refresh_btn = Button(self.navFrame, text="Refresh", bg="#ff55ff", font=self.font , fg="#fff", command= lambda: self.homePortal()) self.refresh_btn.grid(row=0, column=3, padx=20, pady=20) self.tableFrame = LabelFrame(self.master, text="", bg="#5a9bad") self.tableFrame.grid(row=2, column=0, padx=(200, 0), sticky="nsew") self.heading = Label(self.tableFrame, text="Today's Records", bg="#5a9bad", fg="#fff", font="Verdana 14 bold") self.heading.grid(row=0, column=0, pady=10, columnspan=2) self.tv = ttk.Treeview(self.tableFrame, style="mystyle.Treeview", columns=(1, 2, 3, 4, 5), show="headings",height=25, selectmode="none") self.tv.grid(row=1, column=0) # changing font size of heading and body of tree view self.style = ttk.Style() self.style.configure('Treeview.Heading', font=("verdana bold", 12)) self.style.configure("mystyle.Treeview", highlightthickness=1, bd=1, font=('verdana', 11)) # Modify the font of the body self.style.layout("mystyle.Treeview", [('mystyle.Treeview.treearea', {'sticky': 'nswe'})]) # Remove the borders self.verscrlbar = ttk.Scrollbar(self.tableFrame, orient="vertical", command=self.tv.yview) self.verscrlbar.grid(row=1, column=1, rowspan=30, sticky='ns') self.tv.configure(yscrollcommand=self.verscrlbar.set) self.tv.column(1, width=100, anchor='c') self.tv.column(2, width=400) self.tv.column(3, width=200, anchor='c') self.tv.column(4, width=250, anchor='c') self.tv.column(5, width=150, anchor='c') self.tv.heading(1, text="ID") self.tv.heading(2, text="Owner's Name") self.tv.heading(3, text="Car Number") self.tv.heading(4, text="Date") self.tv.heading(5, text="Booked Slot") for i in self.vehicle_records: self.tv.insert("", 'end', values= i)
'type': 'Feature', 'geometry': { 'type': 'LineString', 'coordinates': line['coordonnee'], }, 'properties': { 'times': line['date'], 'style': { 'color': line['color'] if 'color' in line else 'red', 'weight': line['weight'] if 'weight' in line else 5 } } } for line in lines ] plugins.TimestampedGeoJson({ 'type': 'FeatureCollection', 'features': features, }, period='P1D', add_last_point=True).add_to(m)""" m.save('testMapAnimation.html') # on enregistre la map dans un html. except Error as e: print("Probleme de connexion à la base de données.", e) if connection.is_connected(): cursor.close() connection.close() print("Connection à la base de données fermée.")
app["category"] = json.dumps(app["category"]) del dom, page except urllib2.URLError, e: debug("Start open page for pkg[%s]: 404 not found it." % pkg) app["type"] = 1 return app debug("Start...") connection = connection.MySQLConnection(**dbconfig) cursor = connection.cursor() cursor.execute("SET NAMES utf8") cursor.execute("SELECT pkg FROM appinfo WHERE type = 0 LIMIT 50") appinfo = cursor.fetchall() debug("Find %d appinfos." % len(appinfo)) threads = [] for pkg in appinfo: thread = Thread(target=updateApp, args=(pkg[0],)) # thread.setDaemon(True) thread.start() threads.append(thread) for thread in threads: thread.join() connection.commit() cursor.close() connection.close()
try: connection = mysql.connector.connect(host=host, user=user, database=wcsDatabase, password=password) cursor = connection.cursor() for door in doors: current_routes = current_route(door) print(current_routes) next_routes = next_route(door) print(next_routes) current_stops = current_stop(door) print(current_stops) # previous_stop is called within current_stop except Exception as e: print(e) finally: connection.close() time.sleep(1) atexit.register = connection.close()