-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_init.py
57 lines (39 loc) · 1.03 KB
/
db_init.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""
This script initializes a database to fill in the data scraped
DATABASE NAME: flights
Module: ITC - Data Mining
Project: Flight_Scraper
Authors: Itamar Bergfreund & Dor Meir
Last Updated: 19.04.2020
"""
import mysql.connector
import config_db as CFG
def database_init():
"""This function creates a database on you local host"""
db = mysql.connector.connect(
host=CFG.host,
user=CFG.user,
password=CFG.pwd
)
cur = db.cursor()
try:
cur.execute("CREATE DATABASE {}".format(CFG.database))
except mysql.connector.Error as err:
print("Failed to create database: {}".format(err))
db.commit()
def db_create_cursor():
"""creates connection with database and creates a cursor
:return db, cur
"""
db = mysql.connector.connect(
host=CFG.host,
user=CFG.user,
password=CFG.pwd,
database=CFG.database)
cur = db.cursor()
return db, cur
def main():
database_init()
db_create_cursor()
if __name__ == '__main__':
main()