-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.py
40 lines (24 loc) · 837 Bytes
/
query.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
import os
import sys
import database as db
def main():
print("Connecting to database...")
conn, cursor = db.connect_to_db()
# song_info = select_song(cursor)
# print(song_info)
history_info = select_history(cursor)
print(history_info)
print("Closing connection...")
db.close_db_cursor_and_conn(conn, cursor)
def select_song(cursor):
song_query = "SELECT ID, song_name, artist1_id, artist2_id, first_played FROM `songs` WHERE song_name='Mr Loverman'"
cursor.execute(song_query)
song_info = cursor.fetchall()
return song_info
def select_history(cursor):
history_query = "SELECT ID, song_id, played_at FROM `history` WHERE song_id='8012'"
cursor.execute(history_query)
history_info = cursor.fetchall()
return history_info
if __name__ == "__main__":
main()