-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbconnnect.py
94 lines (69 loc) · 2.74 KB
/
dbconnnect.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import pandas as pd
import sqlite3
import csv
from TTS import TTS
class Database:
conn = sqlite3.connect("info.db")
cursor = conn.cursor()
row_list = [["event_id", "event_name", "event_date", "start_time", "end_time", "location", "description"],
[1, "Ash Ketchum", 1970-1-1, 2340,2340, "here", "N/A"],
[2, "Gary Oak", 1970-1-1,2340,2340, "here", "N/A" ],
[3, "Brock Lesner", 1970-1-1, 2340,2340, "here", "N/A"]]
with open('database.csv', 'w', newline='') as file:
writer = csv.writer(file)
writer.writerows(row_list)
file.close()
data = pd.read_csv ("database.csv")
df = pd.DataFrame(data)
# Connect to SQL Server (Microsoft Azure Support)
# conn = pyodbc.connect('Driver={SQL Server};'
# 'Server=info;'
# 'Database=test_database;'
# 'Trusted_Connection=yes;')
# cursor = conn.cursor()
# Create Table
cursor.execute("DROP TABLE EVENTS")
cursor.execute('''
CREATE TABLE EVENTS (
event_id INT PRIMARY KEY,
event_name VARCHAR(255),
event_date DATE,
start_time INT,
end_time INT,
location VARCHAR(255),
description TEXT)
''');
# cInsert DataFrame to Table
for row in df.itertuples():
cursor.execute('''
INSERT INTO EVENTS (event_id, event_name, event_date, start_time, end_time, location, description)
VALUES (?,?,?,?,?,?,?)
''',
(row.event_id,
row.event_name,
row.event_date,
row.start_time,
row.end_time,
row.location,
row.description
))
# conn = sqlite3.connect('info.db')
def event_adder_conn(event_name, event_date, start_time, end_time, location, description):
c = Database.conn.cursor()
c.execute("INSERT INTO events (event_name, event_date, start_time, end_time, location, description) VALUES (?, ?, ?, ?, ?, ?)", (event_name, event_date, start_time, end_time, location, description))
Database.conn.commit()
# event_name = input("Enter the event name: ")
# event_date = input("Enter the event date (YYYY-MM-DD): ")
# start_time = input("Enter the start time (HH:MM:SS): ")
# end_time = input("Enter the end time (HH:MM:SS): ")
# location = input("Enter the location: ")
# description = input("Enter a description: ")
cursor.execute("SELECT * FROM events")
result = cursor.fetchall()
for row in result:
print(row)
print("\n")
conn.commit()
conn.close()
# print(df)
# print("Hello World")