def lazy_setup(): ''' !! CAREFULL !! Lazy setup to create the database connection ''' db.connect() create_tables()
def create_tables(): if not database.tables_created(): database.create_tables() flash("Tables were created", category='info') else: flash("Tables already exist!", category='error') return redirect(url_for('ticks.index'))
def menu(): connection = database.connect() database.create_tables(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: ') rating = int(input('Enter rating score (0-100): ')) databse.add_bean(connection, name, method, rating) elif user_input == '2': beans = database.get_all_beans(connection) for bean in beans: print(f"{bean[1]} ({bean[2]}) - {bean[3]}/100") elif user_input == '3': name = input('Enter bean name to find: ') beans = database.get_beans_by_name(connection, name) for bean in beans: print(f"{bean[1]} ({bean[2]}) - {bean[3]}/100") elif user_input == '4': name = input('Enter bean name to find: ') best_method = database.get_best_preparation(connection, name) print(f"the best preparation for {name} is: {best_methof[2]}") else: print('Invalid Input')
def menu(): connection = database.connect() database.create_tables(connection) user_input = input(MENU_PROMPT) while (user_input != "5"): if user_input == "1": name = input("Enter bean name: ") method = input("Ender how you prepared it: ") rating = int(input("Enter score (0-100): ")) database.add_bean(connection, name, method, rating) elif user_input == "2": beans = database.get_all_beans(connection) for bean in beans: print(f"{bean[1]} ({bean[2]}) - {bean[3]}/100") elif user_input == "3": name = input("Enter bean name: ") beans = database.get_beans_by_name(connection, name) for bean in beans: print(f"{bean[1]} ({bean[2]}) - {bean[3]}/100") elif user_input == "4": name = input("Enter bean name: ") best_method = database.get_best_preparation_for_bean( connection, name) print( f"The best preparation method for {name} is : {best_method[2]}" ) else: print("Invalid input or exit. Try again :)") user_input = input(MENU_PROMPT)
def main(): database.create_tables() banner() print(' ~ MENU ~ ') print('1. AUTO MODE') print(' ~ MANUAL ~ ') print('2. STORE SHOP ONLY') print('3. STORE SHOP DETAIL ONLY') print('4. STORE REVIEWS & REPLIES ONLY') print(' ~ PATCHES ~ ') print('5. STORE SHOP REVIEW RATE') print('CAUTION : YOU MUST HAVE SHOP DATA FIRST ! ') option = input('OPTION : ') # target_url = input("Input a crawling target URL (eg.\"http://www.ipeen.com.tw/search/ilan/000/1-0-0-0/\"):") launch = Fire() if option is '1': launch.auto_pilot() elif option is '2': launch.shop_data() elif option is '3': launch.shop_detail() elif option is '4': launch.shop_review_reply() elif option is '5': launch.shop_review_rate() else: return -1
def test_get_all_beans(self): database.create_tables(self.connection) database.add_bean(self.connection, "Test Bean", "Percolator", 100) beans = database.get_all_beans(self.connection) self.assertEqual(beans[0][1], "Test Bean") self.assertEqual(beans[0][2], "Percolator") self.assertEqual(beans[0][3], 100)
def main(): with get_cursor() as connection: database.create_tables(connection) while (selection := input(MENU)) != "6": try: MENU_OPTIONS[selection]() except KeyError: print("Invalid options")
def main(): """Execute the main code that calls all functions This code should call the above functions to read the files "relations.csv", "locatons.csv" and "index.html", and generate "report.csv" as described in the assignment specifications. """ db = sqlite3.connect(DATABASE_NAME) create_tables(db)
def menu(): with get_connection() as connection: database.create_tables(connection) while (selection := input(MENU_PROMPT)) != "6": try: MENU_OPTIONS[selection]() except KeyError: print("Выбрана несуществующая опция, попробуйте еще раз!")
def menu(): with get_connection() as connection: database.create_tables(connection) while (selection := input(MENU_PROMPT)) != "6": try: MENU_OPTIONS[selection]() except KeyError: print("Invalid input selected. Please try again.")
def update_database(movies): # implement updating of database here print("Started filling database") database.before_request_handler() database.create_tables() for m in movies: movie = movies[m] database.add_trip(m, movie['Locations'], movie['Title'], movie['Poster'], movie['Summary'], 'Berlin', '2017-02-02') database.after_request_hander() print("Finished filling database")
def test_read_stock_2(self): database.create_tables(self.db) with open("index2.html", encoding='utf-8') as f: main.read_stock(self.db, f) cursor = self.db.cursor() cursor.execute("SELECT * FROM products") result = cursor.fetchall() self.assertEqual(len(result), 6) self.assertSequenceEqual((4, "Zipped Jacket", 95, 56.73, "$"), result[4]) self.assertSequenceEqual((5, "Silk Summer Top", 63, 36.56,'£'), result[5])
def test_read_stock_1(self): database.create_tables(self.db) with open("index.html", encoding='utf-8') as f: main.read_stock(self.db, f) cursor = self.db.cursor() cursor.execute("SELECT * FROM products") result = cursor.fetchall() self.assertEqual(len(result), 20) self.assertSequenceEqual((2, "Yellow Wool Jumper", 81, 175.31, "$"), result[2]) self.assertSequenceEqual((6, "Dark Denim Top", 78, 90.31, "$"), result[6])
def test_read_relations_1(self): database.create_tables(self.db) with open("relations.csv") as f: main.read_relations(self.db, f) cursor = self.db.cursor() cursor.execute("SELECT * FROM relations") result = cursor.fetchall() self.assertEqual(20, len(result)) self.assertSequenceEqual((1, 2), result[1][1:]) self.assertSequenceEqual((8, 2), result[8][1:])
def test_get_multiple_beans_by_name(self): database.create_tables(self.connection) database.add_bean(self.connection, "Test Bean", "Percolator", 100) database.add_bean(self.connection, "Test Bean", "Espresso", 80) beans = database.get_beans_by_name(self.connection, "Test Bean") self.assertEqual(beans[0][1], "Test Bean") self.assertEqual(beans[1][1], "Test Bean") self.assertEqual(beans[0][2], "Percolator") self.assertEqual(beans[1][2], "Espresso")
def test_database_insert_beans(self): database.create_tables(self.connection) database.add_bean(self.connection, "Test Bean", "Percolator", 100) with self.connection: cursor = self.connection.execute("SELECT * FROM beans;") results = cursor.fetchone() self.assertEqual(results[1], "Test Bean") self.assertEqual(results[2], "Percolator") self.assertEqual(results[3], 100)
def menu(): """Contact Book User Interface""" with create_connection() as connection: create_tables(connection) while (selection := input(MENU_PROMPT)) != "11": try: MENU_OPTIONS[selection]() except KeyError: print("Invalid selection, please try again.\n")
def Main(): connection = database.connect() database.create_tables(connection) while (main_menu_input := input(MENU_TEXT)) != "6": if main_menu_input == "1": name = input("Name : ") address = input("Address : ") city = input("City : ") state_us = input("State : ") zipcode = (input("Zipcode : ")) database.add_handyman(connection, name, address, city, state_us, zipcode) elif main_menu_input == "2": all_db = database.get_all_handyman(connection) for i in all_db: print(f"ID# :\tNames and Addresses") print( "----------------------------------------------------------" ) print( f"{i[0]}\tName : {i[1]}\n\tAddress: {i[2]}\n\tCity : {i[3]}\t\tState : {i[4]}\tZip : {i[5]}\n\n" ) elif main_menu_input == "3": pattern = input("Search by name : ") names_search = database.search_handyman_by_name( connection, pattern) if names_search != []: print("\n\nID# :\tName and Addresses") print( "---------------------------------------------------------" ) for i in names_search: print( f"{i[0]}\t{i[1]}\n\t{i[2]}\n\t{i[3]} {i[4]}, {i[5]}\n\n" ) else: print("\n\nNothing found!\n\n") elif main_menu_input == "4": zipcode = (input("Search by zipcode : ")) names_search = database.search_handyman_by_zip(connection, zipcode) if names_search != []: print("\n\nID# : \tNames and Addresses") print( "---------------------------------------------------------" ) for i in names_search: print( f"{i[0]}\t{i[1]}\n\t{i[2]}\n\t{i[3]} {i[4]}, {i[5]}\n\n" ) else: print("\n\nNothing found!\n\n") elif main_menu_input == "5": id_ = input("ID number to delete : ") database.del_by_id(connection, id_) print("Deleted ID # ", id_)
def test_read_locations_1(self): database.create_tables(self.db) with open("locations.csv") as f: main.read_locations(self.db, f) cursor = self.db.cursor() cursor.execute("SELECT * FROM locations") result = cursor.fetchall() self.assertEqual(len(result), 3) self.assertSequenceEqual((0, "12", "George Street", "Sydney", "NSW"), result[0]) self.assertSequenceEqual((1, "24", "Mary Street", "Brisbane", "QLD"), result[1]) self.assertSequenceEqual((2, "43", "Queen Street", "Melbourne", "VIC"), result[2])
def setUp(self): # init an in-memory database self.db = sqlite3.connect(':memory:') self.db.row_factory = sqlite3.Row database.create_tables(self.db) self.users, self.images = database.sample_data(self.db) if 'beaker.session' in request.environ: del request.environ['beaker.session'] request.environ['beaker.session'] = MockBeakerSession({})
def setUp(self): session_opts = { 'session.type': 'memory', } beaker_app = beaker.middleware.SessionMiddleware(main.app, session_opts) db = sqlite3.connect(DATABASE_NAME) database.create_tables(db) self.users, self.images = database.sample_data(db) self.app = TestApp(beaker_app) bottle.debug() # force debug messages in error pages returned by webtest
def menu(): load_dotenv() db_connection_config=[os.environ["host"],os.environ["database"],os.environ["user"],os.environ["password"]] connection = psycopg2.connect(db_connection_config) database.create_tables(connection) while(selection := input(MENU_PROMPT)) != "6": try: MENU_OPTIONS[selection](connection) except KeyError: print("Invalid input selected. Please try again.")
def test_read_locations_2(self): database.create_tables(self.db) my_locations = """id,number,street,city,state 0,2,"Peter Rd",Adelaide,SA 1,31,"Pitt Ave",Perth,WA""" main.read_locations(self.db,StringIO(my_locations)) cursor = self.db.cursor() cursor.execute("SELECT * FROM locations") result = cursor.fetchall() self.assertEqual(len(result), 2) self.assertSequenceEqual((0, "2", "Peter Rd", "Adelaide", "SA"), result[0]) self.assertSequenceEqual((1, "31", "Pitt Ave", "Perth", "WA"), result[1])
def __init__(self, minimize=False): """Initialize main window, systemtray, global hotkey, and signals. Args: minimize: True, minimize to system tray. False, bring window to front. """ super(MainWindow, self).__init__() self.setWindowTitle(APP_NAME) self.setWindowIcon(QtGui.QIcon(utils.resource_filename('icons/clipmanager.ico'))) # Remove minimize and maximize buttons from window title self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint| QtCore.Qt.CustomizeWindowHint| QtCore.Qt.WindowCloseButtonHint) # Connect to database and create tables self.db = database.create_connection(STORAGE_PATH) database.create_tables() # Create main widget that holds contents of clipboard history self.main_widget = MainWidget(self) self.setCentralWidget(self.main_widget) # Create system tray icon if not QtGui.QSystemTrayIcon.isSystemTrayAvailable(): logging.warn('cannot find a system tray.') QtGui.QMessageBox.warning(self, 'System Tray', 'Cannot find a system tray.') self.tray_icon = systemtray.SystemTrayIcon(self) self.tray_icon.activated.connect(self._on_icon_activated) self.tray_icon.show() # Return OS specific global hot key binder and set it self.key_binder = hotkey.Binder(self) self._set_hot_key() # Toggle window from system tray right click menu self.connect(self.tray_icon, QtCore.SIGNAL('toggle-window()'), self._on_toggle_window) # Open settings dialog from right click menu on system tray and view self.connect(self.tray_icon, QtCore.SIGNAL('open-settings()'), self._on_open_settings) self.connect(self.main_widget, QtCore.SIGNAL('open-settings()'), self._on_open_settings) # Show window if not minimize: self._on_toggle_window()
def main(): vendor = data_vendor.DataVendor() vendor.start_receive() database.create_tables() sched = scheduler.Scheduler(vendor) sched.create_job(database.add_all_into_data, seconds=config['scheduler']['database']['interval']) sched.create_job(alarm.update, seconds=config['scheduler']['alarm']['interval']) while True: sleep(1)
def test_read_relations_2(self): database.create_tables(self.db) my_relations = """product,location 0,1 1,0 2,1""" main.read_relations(self.db, StringIO(my_relations)) cursor = self.db.cursor() cursor.execute("SELECT * FROM relations") result = cursor.fetchall() self.assertEqual(3, len(result)) self.assertSequenceEqual((0, 1), result[0][1:]) self.assertSequenceEqual((1, 0), result[1][1:]) self.assertSequenceEqual((2, 1), result[2][1:])
def menu(): database_uri = input(DATABASE_PROMPT) if not database_uri: load_dotenv() database_uri = os.environ["DATABASE_URI"] connection = psycopg2.connect(database_uri) database.create_tables(connection) while (selection := input(MENU_PROMPT)) != "6": try: MENU_OPTIONS[selection](connection) except KeyError: print("Invalid input selected. Please try again.")
def _create_db(self): """ private method to open a new DB and create the gemini schema. """ # open up a new database if os.path.exists(self.args.db): os.remove(self.args.db) self.conn = sqlite3.connect(self.args.db) self.conn.isolation_level = None self.c = self.conn.cursor() self.c.execute('PRAGMA synchronous = OFF') self.c.execute('PRAGMA journal_mode=MEMORY') # create the gemini database tables for the new DB database.create_tables(self.c)
def menu(): connection = database.connect() database.create_tables(connection) while (user_input := input(MENU_PROMPT)) != "5": if user_input == "1": prompt_add_new_bean(connection) elif user_input == "2": prompt_see_all_beans(connection) elif user_input == "3": prompt_find_bean(connection) elif user_input == "4": prompt_find_best_method(connection) else: print("Invalid input")
def _create_db(self): """ private method to open a new DB and create the gemini schema. """ # open up a new database if os.path.exists(self.args.db): os.remove(self.args.db) self.conn = sqlite3.connect(self.args.db) self.conn.isolation_level = None self.c = self.conn.cursor() self.c.execute("PRAGMA synchronous = OFF") self.c.execute("PRAGMA journal_mode=MEMORY") # create the gemini database tables for the new DB database.create_tables(self.c)
def menu(): connection = database.connect() database.create_tables(connection) while (user_input := input(MENU_PROMPT)) != "6": #print(user_input) if user_input == "1": nod = input("Cuir nod ann: ") teideal = input("Cuir teideal ann: ") udar = input("Cuir udar ann: ") bp = input("Cuir bliain phróiseála ann: ") database.add_book(connection, nod, teideal, udar, bp) elif user_input == "2": pass books = database.get_all_books(connection) # for book in books: print(book) # elif user_input == "3": pass teideal = input("Cuir isteach teideal leabhair a ba mhaith leat: ") books = database.get_books_by_teideal(connection, teideal) for book in books: print(book) # elif user_input == "4": pass # name = input("Cuir isteach nod an leabhair: ") # books = database.get_books_by_nod(connection,nod) # # for book in books: # print(book) # # for book in books: # print(book) # elif user_input == "5": id = input("Cuir isteach an id: ") book = database.delete_item(connection, id) else: print("Invalid input please try again")
def menu(): database_uri = input(DATABASE_PROMPT) if not database_uri: load_dotenv() database_uri = str( f"host={os.environ['HOST']} user={os.environ['USER']} " f"dbname={os.environ['DBNAME']} password={os.environ['PASSWD']}") connection = psycopg2.connect(database_uri) database.create_tables(connection) while (selection := input(MENU_PROMPT)) != "6": try: MENU_OPTIONS[selection](connection) except KeyError: print("Invalid input selected. Please try again.")
def signup(): if (request.method == 'POST'): connection = database.connect() database.create_tables(connection) fName = request.form['fName'] lName = request.form['lName'] username = request.form['username'] password = request.form['password'] unique = database.add_user(connection, fName, lName, username, password) if unique: return render_template('index.html', unique=unique) else: notunique = True return render_template('index.html', notunique=notunique) return render_template('index.html')
def menu(): connection = database.connect() database.create_tables(connection) while (user_input := input(MENU_PROMPT)) != "5": print(user_input) if user_input == "1": prompt_add_new_score(connection) elif user_input == "2": prompt_see_all_scores(connection) elif user_input == "3": prompt_find_score(connection) elif user_input == "4": prompt_get_highest_score_for_scores(connection) else: print("Invalid input, please try again!")
def _create_db(self): """ private method to open a new DB and create the gemini schema. """ # open up a new database db_path = self.args.db if not hasattr(self.args, 'tmp_db') else self.args.tmp_db if os.path.exists(db_path): os.remove(db_path) self.conn = sqlite3.connect(db_path) self.conn.isolation_level = None self.c = self.conn.cursor() self.c.execute('PRAGMA synchronous = OFF') self.c.execute('PRAGMA journal_mode=MEMORY') # create the gemini database tables for the new DB database.create_tables(self.c) database.create_sample_table(self.c, self.args)
def merge_db_chunks(args): # open up a new database if os.path.exists(args.db): os.remove(args.db) main_conn = sqlite3.connect(args.db) main_conn.isolation_level = None main_curr = main_conn.cursor() main_curr.execute('PRAGMA synchronous = OFF') main_curr.execute('PRAGMA journal_mode=MEMORY') # create the gemini database tables for the new DB gemini_db.create_tables(main_curr, gemini_load_chunk.get_extra_effects_fields(args) if args.vcf else []) databases = [] for database in args.chunkdbs: databases.append(database) for idx, database in enumerate(databases): db = database[0] append_variant_info(main_curr, db) # we only need to add these tables from one of the chunks. if idx == 0: append_sample_genotype_counts(main_curr, db) append_sample_info(main_curr, db) append_resource_info(main_curr, db) append_version_info(main_curr, db) append_vcf_header(main_curr, db) append_gene_summary(main_curr, db) append_gene_detailed(main_curr, db) else: update_sample_genotype_counts(main_curr, db) if args.index: gemini_db.create_indices(main_curr) main_conn.commit() main_curr.close()
def _create_db(self, effect_fields=None): """ private method to open a new DB and create the gemini schema. """ # open up a new database db_path = self.args.db if not hasattr(self.args, 'tmp_db') else self.args.tmp_db if os.path.exists(db_path): os.remove(db_path) self.c, self.metadata = database.create_tables(db_path, effect_fields or []) session = self.c if session.bind.name == "sqlite": self.c.execute('PRAGMA synchronous=OFF') self.c.execute('PRAGMA journal_mode=MEMORY') # create the gemini database tables for the new DB database.create_sample_table(self.c, self.metadata, self.args)
answer.delete_instance() NAMES = [ 'Tatiana-Est%C3%A9vez', 'M%C3%A5rten-Mickos', 'Mar%C3%ADa-Sefidari', 'Sae-Min-Ahn-%EC%95%88%EC%84%B8%EB%AF%BC', 'Ratnakar-Sadasyula-%E0%B0%B0%E0%B0%A4%E0%B1%8D%E0%B0%A8%E0%B0%BE%E0%B0%95%E0%B0%B0%E0%B1%8D-%E0%B0%B8%E0%B0%A6%E0%B0%B8%E0%B1%8D%E0%B0%AF%E0%B1%81%E0%B0%B2', 'Eivind-Kj%C3%B8rstad', 'Diana-Cre%C8%9Bu', 'Adri%C3%A1n-Lamo', 'Diana-Tan-%E9%99%88%E4%B8%BD%E6%A2%85', 'Jane-Chin-%E9%99%B3%E7%9B%88%E9%8C%A6', 'Emily-Nakano-Co-%E8%AE%B8%E6%83%A0%E7%BE%8E' ] database.create_tables() old_time = datetime.datetime.now() - datetime.timedelta(days=7) for name in NAMES: plist = database.Profile.select().where( database.Profile.uname == name) if len(plist) == 0: print name, "user already deleted" elif len(plist) > 1: print "Multiuser :( ", name else: print "Deleting profile %s" % name delete_answers(plist[0].answers) if os.path.isfile('profiles/%s.html' % name): os.remove('profiles/%s.html' % name) plist[0].delete_instance() profiles = database.Profile.select().where(
def main(): # http://bugs.python.org/issue7980 - Need to load strptime from main thread # so that it does not complain later in the process datetime.strptime('2010-01-01 00:00:00.000000', '%Y-%m-%d %H:%M:%S.%f') options, args, parser = command_line_handler() cherrypy.tree.mount(Unicorn(), '/', { '/static': { 'tools.staticdir.on': True, 'tools.staticdir.dir': static_dir, 'tools.response_headers.on': True, 'tools.response_headers.headers': [ ('Cache-Control', 'max-age=3600, must-revalidate'), ('Proxy-Connection', 'close') ] } }) cherrypy.server.socket_host = options.ip_address cherrypy.server.socket_port = options.port db.set_up( options.db_user, options.db_password, options.db_name, options.db_host, options.db_port ) if options.reset: print 'Resetting trailerpark database' db.tear_down( options.db_user, options.db_password, options.db_name, options.db_host, options.db_port ) db.create_tables( options.db_user, options.db_password, options.db_name, options.db_host, options.db_port ) if options.stop: try: with open(options.pid_file, 'r') as f: pid = int(f.read()) print 'Stutting down service with PID %d' % pid os.kill(pid, signal.SIGTERM) os.remove(options.pid_file) sys.exit(1) except IOError: print 'No PID file found, aborting shutdown.' sys.exit(1) if options.daemon: from cherrypy.process.plugins import Daemonizer, PIDFile if os.path.exists(options.pid_file): print 'Cannot start process - PID file already exists: %s' % options.pid_file sys.exit(1) # Daemonise the process Daemonizer(cherrypy.engine).subscribe() # -- Manage the pid: this will create the pid file on start-up and delete on shutdown PIDFile(cherrypy.engine, options.pid_file).subscribe() if hasattr(cherrypy.engine, 'signal_handler'): cherrypy.engine.signal_handler.subscribe() if hasattr(cherrypy.engine, 'console_control_handler'): cherrypy.engine.console_control_handler.subscribe() try: cherrypy.engine.start() except IOError: print 'Unable to bind to address ({0}, {1}'.format(options.ip_address, cherrypy.port) sys.exit(1) cherrypy.engine.wait(cherrypy.process.wspbus.states.STARTED) cherrypy.engine.block() # Wait until the app is started before proceeding
sys.stdout.write('\rDone Parsing Answer id %d (%d)' % (answer.id, len(users))) sys.stdout.flush() def create_directory(directory): try: os.mkdir(directory, 0o700) except OSError as error: if error.errno != errno.EEXIST: raise if __name__ == '__main__': # Configuring Database DATABASE.connect() create_tables() parser = argparse.ArgumentParser(description = 'Quora Crawling Bot') parser.add_argument('-n', '--max_crawl', nargs='?', default=1000, type=int, help='Number of maximum requests to make') parser.add_argument('--no_profile', action='store_true', help='Do not Crawl Profiles') parser.add_argument('--no_answer', action='store_true', help='Do not Crawl Answers') args = parser.parse_args() # Filling Database with Top Writers 2016 with open('top_writers_2016.json', 'r') as fstream: writer_list = json.load(fstream) with open('other_writers.json', 'r') as fstream: writer_list += json.load(fstream)
import database as db import config db.create_tables(config.db)
def setUp(self): self.client = app.test_client() database.create_tables()
import sqlite3 import sys import document, label, term import database # Give path to CSV file as argument if __name__ == "__main__": conn = sqlite3.connect('docs.db') database.create_tables(conn) path_to_csv = sys.argv[1] # Fetch details of all documents and write to db document.write_docs_to_db(path_to_csv, conn) # Read from db and create a label index label.write_labels_to_db(conn) # Fetch terms from 'docs' table and create a 'terms' table term.write_terms_to_db(conn) # compute idf and write them to 'terms' table idfs = term.compute_idf(conn) term.write_idf_to_db(idfs, conn) # compute tfidf for each term in each document and write to 'docs' table tfidf_vectors = document.compute_tfidf(conn) document.write_tfidf_vectors_to_db(tfidf_vectors, conn) # Compute and write centroids of labels to db label.write_label_centroids(conn)
def create_tables(): database.create_tables() return redirect("%s#%s" % (request.referrer, blueprint.name))