def run(self): while True: b = b'' tmp = conn.recv(4096) print("Server received data:", tmp) b = b + tmp print("b is: ", b) #print(tmp) d = json.loads(b.decode('utf-8')) print("d is:", d) choice = int(d[0]) #[1,['shreya',3]] if choice == 1: key = d[1][0] value = d[1][1] replicate = d[2][0] dictionary[key] = value insert(key, value, "server3", replicate) modify_mappings() #print("Dictionary on server side: ",dictionary) MESSAGE = "Value added!" put_watch("server2") print_all("server3") conn.send(MESSAGE.encode('utf-8')) #[2,'shreya'] if choice == 2: client_key = d[1] MESSAGE = str(select(client_key, "server3")) conn.send(MESSAGE.encode('utf-8')) #MESSAGE =input("Multithreaded Python server : Enter Response from Server/Enter exit:") '''if MESSAGE == 'exit': break''' if choice == 3: MESSAGE = "Exiting!" conn.send(MESSAGE.encode('utf-8')) tcpServer.close()
con = db.connect() cur = con.cursor() #Create table if not exists insert_data.create_table(cur) except DatabaseError as error: print(error) else: #Check if there are already rows in table #If there are already rows, do nothing cur.execute('SELECT EXISTS (SELECT 1 FROM stocks)') rows = cur.fetchone()[0] if not rows: #Fetch data from API data = fetch_2019_data() #If data was retreived if data: try: #Dump data into table and add percent_change column #to the table insert_data.insert(data, cur) insert_data.percent_change_column(cur) print('Data inserted to table') con.commit() except DatabaseError as error: print(error) print('There were no commits') else: print('Table already initialized') finally: if con is not None: con.close()
def first_page() -> str: task = request.form['task_name'] exp = request.form['exp_date'] exp = exp.replace('T', ' ') f1.insert(task, exp) return render_template('created.html', created_task=task)
import insert_data import precompute_greeks # will insert all data in the settings.path_to_data_folder insert_data.insert("^SPX") # insert_data.insert("^RUT") # insert_data.insert("SPY") # insert_data.insert("^VIX") # precompute_greeks.precompute("^SPX") # precompute_greeks.precompute("^RUT") # precompute_greeks.precompute("SPY")
import insert_data import precompute_greeks # will insert all data from the folder stated in the settings.path_to_data_folder symbols = ["^RUT", "^SPX"] for symbol in symbols: insert_data.insert(symbol) precompute_greeks.precompute(symbol)
Price real, primary key(ProductId))""".format(table_name) create(db_name, table_name, sql) elif command.lower() == 'i': print("\033[1;37;40m \n Inserting data. Please enter the name of the entity you would like to add data to.") table_name = input("\033[0;32;40m Table name >> ") print("\033[1;37;40m \n Please enter the name of the new record.") name = input("\033[0;32;40m Name >> ") print("\033[1;37;40m \n Please enter the new price.") price = input("\033[0;32;40m Price >> ") print("\033[0;37;40m") insert(db_name, name, price, table_name) elif command.lower() == 'u': print("\033[1;37;40m \n Updating data. Please enter the name of the entity you would like to update data in.") table_name = input("\033[0;32;40m Table name >> ") print("\033[1;37;40m \n Please enter the ID of the product you would like to update.") product_id = input("\033[0;32;40m Id >> ") print("\033[1;37;40m \n Please enter the new name.") name = input("\033[0;32;40m Name >> ") print("\033[1;37;40m \n Please enter the new price.") price = input("\033[0;32;40m Price >> ") print("\033[0;37;40m")