-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
50 lines (40 loc) · 1.44 KB
/
Copy pathapi.py
File metadata and controls
50 lines (40 loc) · 1.44 KB
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
"""API layer - allow user to query oldest artists & move them."""
import argparse
import psycopg2
import psycopg2.extras
def main():
"""Main."""
action = 's'
while(action != 'q'):
print("Artist Queue Menu:")
print("\tg - get artists you haven't listened to in a while")
print("\tq - get out")
action = input('> ')
print()
if action == 'q':
print("Bye then")
elif action == 'g':
print("How many artists would you like to be reminded of?")
n = input('> ')
print()
print("""\tHere are your %s artists:""" % n)
get_least_recently_played_artists(int(n))
print()
else:
print("Hmmm, something seems to have gone awry. Please enter one of the menu options:")
print()
action = 's'
def get_least_recently_played_artists(n=5):
"""Get the n least recently played artists. Defaults to 5."""
conn = psycopg2.connect("dbname=artistqdb host=localhost user=postgres")
cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
cur.execute("""SELECT *
FROM artist_queue
ORDER BY last_scrobble_date
LIMIT %s""", str(n))
data = cur.fetchall()
for row in data:
print("""- %s \t(last listen: %s)"""
% (row['artist'], row['last_scrobble_date']))
if __name__ == "__main__":
main()