async def on_message(message): """This method execute when a new message come""" # check if the message is from the bot itself, don't change this if message.author == client.user: return # print new incoming message print('Message from {0.author}: {0.content}'.format(message)) time = datetime.datetime.now() time = time.strftime("%Y-%m-%d %I:%M %p") create_table() add_message(message.author.name, message.content, message.author.guild.name, str(time)) all_messages = get_all_messages() df = pd.DataFrame(all_messages) # this is your dataframe # check if the message content matches with any of the keywords if str(message.content).startswith("?"): if message.content in keywords: pdf_file = get_output(query=message.content) print("PDF:", pdf_file) with open(pdf_file, 'rb') as f: await message.channel.send( file=File(f, os.path.basename(pdf_file))) # await message.channel.send("a = " + str(a) + " b = "+str(b)) else: await message.channel.send("Ticker doesn't exist.")
def populate_db(db_connection, list): db.create_table(db_connection) # convert list elements to tuple rows = [(elm, ) for elm in list] db.insert_rows(db_connection, rows)
def create_acc(self): num = str(400000) + str(random.randint(100_000_000, 999_999_999)) num_list = [int(i) for i in num] for i in range(0, len(num_list), 2): num_list[i] = num_list[i] * 2 for i in range(len(num_list)): if num_list[i] > 9: num_list[i] -= 9 for i in range(10): total = sum(num_list) + i if total % 10 == 0: checksum = i break else: total = sum(num_list) self.card_no = num + str(checksum) self.pin = str(random.randint(1000, 9999)) print("Your card has been created") print("Your card number:") print(self.card_no) print("Your card PIN:") print(self.pin) database.create_table(connection) database.insert_card(connection, self.card_no, self.pin) connection.commit()
def create_tables(conn): """ create the files and updates table if not already created :param conn: Connection object :param database: path where to create and save the DB :return: """ # int for primary key sql_create_files_table = """CREATE TABLE IF NOT EXISTS files ( id integer PRIMARY KEY, local text NOT NULL, tab_ou_tech text NOT NULL, status int NOT NULL );""" sql_create_updates_table = """CREATE TABLE IF NOT EXISTS updates ( id integer PRIMARY KEY, file_id string NOT NULL, measure_time text NOT NULL, last_update_in_s int NOT NULL, FOREIGN KEY (file_id) REFERENCES files (id) );""" # creates tables table if not available database.create_table(conn, sql_create_files_table) # creates updates table if not available database.create_table(conn, sql_create_updates_table)
def menu(): connection = connect() create_table(connection) user_input = input(MENU_PROMPT) while user_input != "5": if user_input == "1": name = input("Enter Bean Name: ") method = input("Enter How you've Prepared It: ") rating = int(input("Enter Your Rating Score: ")) add_bean(connection, name, method, rating) elif user_input == "2": beans = get_all_beans(connection) for bean in beans: print(f"{bean[1]} {bean[2]} {bean[3]}") elif user_input == "3": name = input("Enter bean Name to find: ") beans = get_beans_by_name(connection, name) for bean in beans: print(f"{bean[1]} {bean[2]} {bean[3]}") elif user_input == "4": name = input("Enter Bean name to find: ") best_method = get_preparation_for_beans(connection, name) print( f"The Best Preparation method for {name} is: {best_method[2]}") user_input = input(MENU_PROMPT)
def get_history_table(coin, con): print('Get ' + coin[0] + ' history') db.create_table(coin[0], con) site = requests.get(coin[1]) historical = BeautifulSoup(site.content, 'html.parser') try: table = historical.find_all('table')[2] except IndexError: print("Error getting " + coin[0] + " data: DDoS protection by Cloudflare") table = None data = [] if table: rows = table.find_all('tr') for row in rows: items = [] counted_rows = row.find_all('td') for element in counted_rows: items.append(element.text.strip()) if items: date = items[0] date = time.mktime(datetime.datetime.strptime(date, '%b %d, %Y').timetuple()) price = items[3].replace("$", "") price = price.replace(",", "") price = float(price) ratio = (date, price) data.append(ratio) data.reverse() return data
def get_history_table(coin, con): print('Get ' + coin[0] + ' history') db.create_table(coin[0], con) site = requests.get(coin[1]) historical = BeautifulSoup(site.content, 'html.parser') table = historical.find_all('table')[2] data = [] rows = table.find_all('tr') for row in rows: items = [] counted_rows = row.find_all('td') for element in counted_rows: items.append(element.text.strip()) if items: date = items[0] date = time.mktime( datetime.datetime.strptime(date, '%b %d, %Y').timetuple()) price = items[3].replace("$", "") price = price.replace(",", "") price = float(price) ratio = (date, price) data.append(ratio) return data
def __init__(self, bot): self.bot = bot self.conn = self.bot.conn create_table(self.conn, 'twitter') # Run background task self.twitter_task.start()
def create(args): """Invoked with the `create` command line argument. Creates a new table (phonebook) in the given database. Throws an exception if the table already exists in the database.""" database.create_table(args.b, args.db) print "Created phonebook %s in the %s database." % (args.b, args.db)
def getContent(): url = "http://ris.szpl.gov.cn/" one_hand = "credit/showcjgs/ysfcjgs.aspx" second_hand = "credit/showcjgs/esfcjgs.aspx" req = urllib2.Request(url + one_hand) content = urllib2.urlopen(req).read() #返回的就是网页的源码,没有做任何防爬虫的处理,zf网站,呵呵 #print content date = re.compile( r'<SPAN class=titleblue><span id=\"lblCurTime5\">(.*)</span>') reg = re.compile(r'<td width="14%"><b>(\d+)</b>') result = reg.findall(content) current_date = date.findall(content) reg2 = re.compile(r'<td align="right"><b>(.*?)</b>') yishou_area = reg2.findall(content) print current_date[0] print '一手商品房成交套数:%s' % result[0] print '一手商品房成交面积: %s' % yishou_area[0] sec_req = urllib2.Request(url + second_hand) sec_content = urllib2.urlopen(sec_req).read() sec_quantity = re.compile(r'<td width="30%">(\d+)</td>') sec_result = sec_quantity.findall(sec_content) second_area = re.findall(r'<td align="right">(.*?)</td>', sec_content) print '二手商品房成交套数:%s' % sec_result[1] print '二手商品房成交面积: %s' % second_area[2] database.create_table() database.insert(current_date[0], result[0], yishou_area[0], sec_result[1], second_area[2])
def GoToInputRequest(_data): requestedDT = _data["dt"] if not noDB: # Check database if not exists then this method creates it. database.create_db(c, "pysoc_server"); # Check table if not exists then this method creates it. database.create_table(c, "client_name", "pysoc_server"); clientDictList = [] # All client information that will be sent to client. clientNameList = DatabaseGetAllClientNameMod1(c, db) # All client name from `client_name` table in database. tableNameList = DatabaseGetAllTableName(c, db) # All tables in database. for i in clientNameList: clientName = i.get("client_name") face_temp = (database.get_first_doc_value(c, str(requestedDT), "dt", "face", "{}_face".format(clientName), dbN)); pitch_temp = (database.get_first_doc_value(c, str(requestedDT), "dt", "pitch", "{}_pitch".format(clientName), dbN)); presence_temp = (database.get_first_doc_value(c, str(requestedDT), "dt", "presence", "{}_presence".format(clientName), dbN)); volume_temp = (database.get_first_doc_value(c, str(requestedDT), "dt", "volume", "{}_volume".format(clientName), dbN)); if type(face_temp) is not list: i["face"] = face_temp if type(pitch_temp) is not list: i["pitch"] = pitch_temp if type(presence_temp) is not list: i["presence"] = presence_temp if type(volume_temp) is not list: i["volume"] = volume_temp clientDictList.append(i) emit("inputSend", clientDictList)
def setUp(self): database.create_table() database.store_report( "Testhost", str(dumps({ "keyfield1": "valuefield1", "keyfield2": "valuefield2" })), "12345", "2018-07-20", self.test_config)
def test_adding_250_rows_in_parallel_to_new_db_cf(): create_table() assert row_count() == 0 insert_rows_in_parallel_cf(generate_example_rows(250)) assert row_count() == 250
def setup_db(): """Establishes a connection to our database and creates our url table if it does not yet exist. Returns the connection to the database file.""" conn = db.setup_sql(db.MYLOCATION) if conn == None: #Could not establish connection, so quit sys.exit() if not db.table_exists(db.MYTABLE, conn): #create table if not yet created db.create_table(db.MYTABLE, conn) return conn
def test_adding_500_rows_in_parallel_to_new_db_wal_mode_enabled(): # After creating the database, enable WAL mode. # https://www.sqlite.org/pragma.html#pragma_journal_mode create_table(enable_wal_mode=True) assert row_count() == 0 insert_rows_in_parallel(generate_example_rows(500)) assert row_count() == 500
def index(): if request.method == 'POST': url = request.form['url'] database.create_table() x_url = URL.insert_url(url) hasid = hashids.encode(x_url) short_url = request.host_url + hasid return render_template('index.html', short_url=short_url) return render_template('index.html')
def __init__(self, position): """This class controlls the game""" self.rooms = [] self.create_variables() self.create_items() self.create_rooms() self.list_of_commands() self.long_sentences() self.pos = position database.create_table()
async def id_step(message: types.Message, state: FSMContext): try: data = await state.get_data() lang = data.get('lang') if message.text == '/start': markup = types.InlineKeyboardMarkup() markup.add( types.InlineKeyboardButton(text='лаЛЃЛЂ ' + "ЪЄиЪЄ║", callback_data='лаЛЃЛЂ')) markup.add( types.InlineKeyboardButton(text='мџл░ли ' + "ЪЄ░ЪЄ┐", callback_data='мџл░ли')) await message.answer(lang_phrases(1, 10), reply_markup=markup, parse_mode=HTML) await States.lang.set() elif message.text == '/delete': await delete(message) else: id = message.text i_d = data.get('id') id2 = await get_id_by_lesson(int(id)) if int(id) == int(i_d) or int(id) == int(id2): customer = await customers(id) name = '' try: name = await get_name(customer) except Exception as e: await bot.send_message(877012379, 'id_step ' + str(e)) await state.update_data(name=name) await state.update_data(id=id) create_table() insert(message.chat.id, id, lang, name.strip()) inline_markup = types.InlineKeyboardMarkup() inline_markup.add( types.InlineKeyboardButton(lang_phrases(lang, 4), callback_data='da')) inline_markup.add( types.InlineKeyboardButton(lang_phrases(lang, 5), callback_data='net')) await message.answer(lang_phrases(lang, 3).format(str(name)), reply_markup=inline_markup, parse_mode=HTML) await States.grade.set() else: markup = types.InlineKeyboardMarkup() markup.add( types.InlineKeyboardButton(lang_phrases(lang, 7), callback_data='again')) await message.answer(lang_phrases(lang, 8), parse_mode=HTML, reply_markup=markup) await States.lang.set() except Exception as e: await bot.send_message(877012379, str(e))
def setUp(self): if glob.glob('*.db'): raise Exception(".db files exist on setUp!") # Create test database and table database.create_database(TEST_DB) database.create_table(TEST_PB, TEST_DB) # Add some test records add_records() self.parser = phonebook.parse()
def test_adding_5_rows_in_parallel_to_new_db(): # Create a new `messages` sqlite3 table, # dropping it if one already exists. create_table() assert row_count() == 0 # Run 5 parallel instances of `insert_rows` # by way of `insert_rows_in_parallel` insert_rows_in_parallel(generate_example_rows(5)) assert row_count() == 5
async def on_ready(): print('Logged in as') print(client.user.name) print(client.user.id) print('------') database.create_table() print(str(database.connect)) print("hello") print(database.show_table()) a = await client.get_user_info('223212153207783435') print(a) await client.change_presence(game=game)
def test_adding_10000_rows_sequentially_then_100_rows_in_parallel(): create_table() assert row_count() == 0 for example_row in generate_example_rows(10000): insert_row(example_row) assert row_count() == 10000 insert_rows_in_parallel(generate_example_rows(100)) assert row_count() == 10100
def firststep(conn): """ ingest a directory of music for database construction USAGE + this is the prerequisite for all analyses/identification + run this function to get a nicely-built music database + which will be used as the reference for audio matching WHAT IT DOES + sql database contruction + read all mp3 files from a local dir + read metadata + convert mp3 to wav + compute spectrograms and fingerprints + record all info in the database GOOD FOR + lazy guys like me who don't want to contruct db manually """ # create tables if non-exist d.create_table(conn) log.info("database created") # construct database for file in os.listdir("./music/mp3"): if file.endswith(".mp3"): pathfile = "./music/mp3/" + file # read metadata tup = c.meta(pathfile) d.add_song(tup, conn) # convert mp3 to wav c.convert(pathfile) log.info('all metadata recorded in the database') log.info('all audio converted to wav') for file in os.listdir("./music/wav"): if file.endswith(".wav"): pathfile = "./music/wav/" + file # compute spectrogram and fingerprints framerate, f, t, spect = a.spectrogram(pathfile) fingerprints1 = a.fingerprint(f, spect) fingerprints2 = a.fingerprint2(f, spect, framerate) song_id = d.select_songid(file, conn) log.info('audio file no. %s recorded in the database', song_id) # add fingerprints to database d.add_fingerprint(file, t, fingerprints1, fingerprints2, conn) # update fingerprinted status d.update_fingerprinted(song_id, conn) print('Done! Please check out your database ❤')
def query(): city_query = request.args.get('city') user = session.get('user') query_time = datetime.datetime.now() if request.args.get('query') == "Query" and len(city_query) != 0: create_table() try: weather_str = get_city_weather(city_query) print(weather_str + "database") return render_template('index.html', weather_str=weather_str) except TypeError: try: day, location, weather, low, weather_str = get_weather( city_query) user_id = user[0] username = user[1] insert_history(user_id, city_query, weather_str, query_time) return render_template('index.html', weather_str=weather_str) except TypeError: try: day, location, weather, low, weather_str = get_weather( city_query) return render_template('index.html', weather_str=weather_str) except ValueError: error = '无该城市天气信息' return render_template('index.html', error=error) elif request.args.get('history') == "History": try: user_id = user[0] username = user[1] history = query_history(user_id) return render_template('index.html', history=history) except TypeError: error = '请先登录' return render_template('index.html', error=error) elif request.args.get('help') == "Help": help = "help" return render_template("index.html", help=help) elif request.args.get('update') == "help": city = city_query.split(' ')[0] print(city + "1") update = city_query.split(' ')[1] print(city + "\n" + update) update_data = update_weather(city, update) print(update_data, "2") return render_template('index.html', update_data=update_data) else: error = '请输入正确的城市名' return render_template('index.html', error=error)
def addButt(self): if self.sr == 0: #无历史记录 self.add_record_new() else: #有历史记录 self.add_record() self.sr = 0 #重置判决值 #判断是否是第一次使用,若是,则新建数据表 if self.input_count == 0: database.create_table() self.input_count + 1 else: self.input_count + 1 print(self.input_count)
def recreate(database, args): database.create_table( "fuel", """ id INTEGER PRIMARY KEY, name TEXT NOT NULL UNIQUE, price INTEGER NOT NULL """) # Создаем таблицу транзакций database.create_table( "trans", """ id INTEGER PRIMARY KEY, dtime DATETIME DEFAULT CURRENT_TIMESTAMP, odometer INTEGER NOT NULL, fuel_id INTEGER NOT NULL, amount INTEGER NOT NULL, FOREIGN KEY (fuel_id) REFERENCES fuel(id) """) # Данные, получаемые из таблицы: # id, дата, название заправки, # расстояние пройденное до текущего дня, # расстояние проеденное до предыдущего дня, # цена галлона, # количество галлонов, # цена заправки, # пробег на одном галлоне, # стоимость одной милю, # пробег между заправками, # стоимость одного дня condition = "t.fuel_id = f.id" condition += " AND tt.id = (SELECT MAX(id) FROM trans WHERE id < t.id)" condition += " AND nt.id = (SELECT MIN(id) FROM trans WHERE id > t.id)" database.create_view("v_trans", "trans t, trans tt, trans nt, fuel f", """t.id, t.dtime, nt.dtime as next_dtime, tt.dtime as prev_dtime, f.name, t.odometer, tt.odometer as last_odometer, t.odometer - tt.odometer as mbs, f.price, t.amount, t.amount * f.price / 100 as cost, (t.odometer - tt.odometer) / t.amount as mpg, t.amount * f.price / (t.odometer - tt.odometer) as mile_price """, condition, re_create=True)
def menu(): connection = database.connect() database.create_table(connection) while (user_input := input(MENU_PROMPT)) != "5": if user_input == "1": prompt_add_new_hero(connection) elif user_input == "2": prompt_see_all_heroes(connection) elif user_input == "3": prompt_find_hero(connection) elif user_input == "4": prompt_find_best_hero(connection) else: print("invalid input. please try again.")
def insert_data_onClick(self): # Create the table to insert data (if it doesn't exist yet) connect_db = database.create_connection(self.db) database.create_table(connect_db, self.db_name) database.close_connection(connect_db) # Insert the data from the csv file into the table created connect_db = database.create_connection(self.db) database.insert_data_on_database(connect_db, self.db_name, self.filename) database.close_connection(connect_db) ########### Test Query ########### connect_db = database.create_connection(self.db) database.search_data_test(connect_db, self.db_name) database.close_connection(connect_db)
def menu(): connection = db.connect() db.create_table(connection) while (choice := input(prompt)) != '7': if choice == '1': contents = db.table_content_view(connection) #print('The Table Contents Are :') print('Id Name Age Pay') for content in contents: print(f'{content[0]} {content[1]} {content[2]} {content[3]}') print('\n') elif choice == '2': name = input('Please provide the employees Name : ') names = db.select_single_value(connection, name) print('Id Name Age Pay') for same_name in names: print( f'{same_name[0]} {same_name[1]} {same_name[2]} {same_name[3]}' ) print('\n') elif choice == '3': name = input('New Employees Name : ') age = input('His/Her age : ') pay = input('His/Her pay :') db.insert_in_table(connection, name, age, pay) elif choice == '4': name = input('Name of employee : ') pay = input('His/Her new pay : ') db.value_update(connection, name, pay) elif choice == '5': name = input('Employees name to be deleted : ') db.row_delete(connection, name) elif choice == '6': chart_data = db.visualize_data(connection) charts.return_chart(chart_data) plt.show()
def start(path: str, database: str = "mydatabase", user: str = "postgres", password: str = "12345", host: str = "127.0.0.1", port: str = "5432", n: int = 0) -> None: """ Gets the name of the file with path to it and optional parameters The body of service Creates psql connection and database Then reads .csv or .xlsx file, gets column names and types from it Then adds data if the table with such name already exists Creates the table and adds the data inside if the table with such name doesn't exist :param path: the name of the file with path to it :param database: name of the database :param user: name of psql user :param password: password of psql user :param host: host :param port: port :param n: number of row with headers """ register_adapter(np.int64, psycopg2._psycopg.AsIs) connection = create_connection("postgres", user, password, host, port) create_database_query = "CREATE DATABASE " + database create_database(connection, create_database_query) connection = create_connection(database, user, password, host, port) table, table_name = read_file(path, n) cursor = connection.cursor() cursor.execute( "select * from information_schema.tables where table_name=%s", (table_name, )) columns, data, types = preprocess(table) if bool(cursor.rowcount): insert(columns, data, table_name, connection) connection.commit() else: create_table(types, table_name, connection) insert(columns, data, table_name, connection) connection.commit()
def choose_option(option): if option == 1: database.create_database() elif option == 2: database.show_databases() elif option == 3: database.used_database() elif option == 4: database.create_table() elif option == 5: database.add_column() elif option == 6: database.show_tables() elif option == 9: print("Thanks for using BYE!") sys.exit() else: print("Choose number from 1 to 9")
def getContent(): url = "http://ris.szpl.gov.cn/" one_hand = "credit/showcjgs/ysfcjgs.aspx" second_hand = "credit/showcjgs/esfcjgs.aspx" # req=urllib2.Request(url+one_hand) # content=urllib2.urlopen(req).read() #返回的就是网页的源码,没有做任何防爬虫的处理,zf网站,呵呵 #print content headers = { 'User-Agent': 'Mozilla/5.0 (WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36' } content = requests.get(url=url + one_hand, headers=headers).text date = re.compile( r'<SPAN class=titleblue><span id=\"lblCurTime5\">(.*)</span>') reg = re.compile(r'<td width="14%"><b>(\d+)</b>') result = reg.findall(content) current_date = date.findall(content) reg2 = re.compile(r'<td align="right"><b>(.*?)</b>') yishou_area = reg2.findall(content) print(current_date[0]) print('一手商品房成交套数:%s' % result[0]) print('一手商品房成交面积: %s' % yishou_area[0]) # sec_req=urllib2.Request(url+second_hand) # sec_content=urllib2.urlopen(sec_req).read() sec_content = requests.get(url + second_hand).text sec_quantity = re.compile(r'<td width="30%">(\d+)</td>') sec_result = sec_quantity.findall(sec_content) second_area = re.findall(r'<td align="right">(.*?)</td>', sec_content) print('二手商品房成交套数:%s' % sec_result[1]) print('二手商品房成交面积: %s' % second_area[2]) database.create_table() database.insert(current_date[0], result[0], yishou_area[0], sec_result[1], second_area[2])
def main(): service, user_id, label_ids, status = GmailCredential() if status: all_email_ids = ListMessagesWithLabels(service, user_id, label_ids) msg_id = all_email_ids[0] database.drop_table() database.create_table() print("Building the email Databse") print("") print("-" * 98) for count in tqdm(range(500)): GetMessage(service, user_id, all_email_ids[count], count) # time.sleep(1) # sys.stdout.write("-") # sys.stdout.flush() # sys.stdout.write("]\n") # this ends the progress ba print("-" * 98) print("") print("Latest 100 emails has been feteched from GMAIL !!!!!")
def get_db(): db = getattr(g, '_database', None) if db is None: db = g._database = create_table() return db
# and put the information into a dictionary for item in all: d = {} d["Title"] = item.find("div",{"class","cassetteitem_content-title"}).text d["Locality"] = item.find("li",{"class","cassetteitem_detail-col1"}).text d["Price"] = item.find("span",{"class","cassetteitem_other-emphasis ui-text--bold"}).text.replace("\n","").replace(" ","") # finding number of rooms is more complicated in this situation, because categories need to be decoded rooms = item.find("table",{"class","cassetteitem_other"}).text if 'ワンルーム' in rooms: d["Rooms"] = 1 elif '1K' in rooms: d["Rooms"] = 1 elif '2K' in rooms: d["Rooms"] = 2 else: d["Rooms"] = "Unknown" # need to dig inside tables to find the relevant number table = item.find_all("table",{"class","cassetteitem_other"})[0] nums = re.findall(r'\d+(?:\.\d+)?', str(table)) d["Size"] = nums[-6]+" m2" # d["Link"] = item.find("td",{"class","ui-text--midium ui-text--bold"}).text l.append(d) # goes back through all of the houses in the list of dictionaries and enters the respective information into database database.create_table() for d in l: database.insert(d["Title"],d["Locality"],d["Size"],d["Rooms"],d["Price"])
def print_usage(): print('Incorrect number of arguments.') print('Script can be invoked like:') print(' ~:$ python3 manage.py adduser username:password') print(' ~:$ python3 manage.py userdel username:password') print(' ~:$ python3 manage.py getusers') print(' ~:$ python3 manage.py load_default') sys.exit(1) if __name__ == '__main__': if len(sys.argv) == 2 and sys.argv[1] == 'load_default': connection = database.connect() for table_name in 'users', 'tasks': database.drop_table(connection, table_name) database.create_table(connection, table_name) database.load_default(connection, table_name) connection.close() elif len(sys.argv) == 2 and sys.argv[1] == 'getusers': connection = database.connect() for user, password in database.get_user_credentials(connection): print('user:password -> {0}:{1}'.format(user, password)) connection.close() elif len(sys.argv) == 3 and sys.argv[1] == 'adduser': connection = database.connect() database.insert_user(connection, sys.argv[2]) connection.close() elif len(sys.argv) == 3 and sys.argv[1] == 'userdel': connection = database.connect() database.delete_user(connection, sys.argv[2]) connection.close()
#!/usr/bin/python import psycopg2 import sys from database import create_db, create_table, set_initial_price from bitfinex import get_last, get_previous from validate_data import validate_data from seperate_data import percentage_over_periods try: conn = psycopg2.connect("dbname=divergence25 user=bkawk") except psycopg2.OperationalError as err: print(err) create_db('divergence25') create_table('divergence25', 'price') def main(): qty = 1000 most_recent = get_last('BTCUSD')[0] # Previous below also needs adding to the database too! previous = get_previous('BTCUSD', most_recent, qty) for i in previous: try: time = int(i[0]) open = int(i[1]) close = int(i[2]) high = int(i[3]) low = int(i[4]) volume = int(i[5])
#! /usr/bin/python import database as db import parse as p if __name__ == "__main__": # Parse HTML and store header and records path = "leaderboard.html" soup = p.get_html_from_path(path) header = p.get_header_from_html(soup) records = p.get_records_from_html(soup) # Create PostgreSQL database connection and a cursor object conn = db.create_connection() cursor = conn.cursor() # Initialize table information table_schema = 'public' table_name = 'battingleaders' column_names = header # Create table and insert records db.create_table(cursor,table_schema,table_name,column_names) db.insert_records(cursor,table_schema,table_name,column_names,records) # Commit executions and close connection conn.commit() conn.close()
import database con = database.set_up_db("check.db"); cur= con.cursor() database.create_table(cur) database.insert_comment(cur, "Isha", "Trying hard") print(database.get_comments(cur)) # database.drop_all_tables(cur) con.commit() con.close()