-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdatabase.py
735 lines (689 loc) · 26.2 KB
/
database.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
import os
import supabase
from datetime import datetime, timedelta
SUPABASE_URL = os.environ.get("SUPABASEURL")
SUPABASE_KEY = os.environ.get("SUPABASEKEY")
client = supabase.create_client(SUPABASE_URL, SUPABASE_KEY)
def load_users_from_db():
# Fetch data from Supabase table
data = client.table('users').select('*').execute()
user_dicts = []
for row in data.data:
user_dict = {
"id": row['id'],
"username": row['username'],
"email": row['email']
}
user_dicts.append(user_dict)
return user_dicts
def load_users_from_username(name):
# Fetch data from Supabase table
data = client.table('users').select('*').eq("username", name).execute()
user_dicts = []
for row in data.data:
user_dict = {
"id": row['id'],
"username": row['username'],
"email": row['email']
}
user_dicts.append(user_dict)
return user_dicts
def load_users_from_email(email):
# Fetch data from Supabase table
data = client.table('users').select('*').eq("email", email).execute()
user_dicts = []
for row in data.data:
user_dict = {
"id": row['id'],
"username": row['username'],
"email": row['email'],
"password": row['password']
}
user_dicts.append(user_dict)
return user_dicts
def insert_user(username, email, password):
# Insert data into Supabase table
client.table('users').insert([{"username": username, "email": email, "password": password}]).execute()
def get_user_by_id(id):
# Fetch data from Supabase table
data = client.table('users').select('*').eq("id", id).execute()
user_dicts = []
for row in data.data:
user_dict = {
"id": row['id'],
"username": row['username'],
"email": row['email'],
"password": row['password']
}
user_dicts.append(user_dict)
return user_dicts
def get_user_name(name):
# Fetch data from Supabase table
data = client.table('users').select('*').eq("username", name).execute()
user_dicts = []
for row in data.data:
user_dict = {
"id": row['id'],
"username": row['username'],
}
user_dicts.append(user_dict)
return user_dicts
def get_user_id(name):
# Fetch data from Supabase table
data = client.table('users').select('*').eq("username", name).execute()
user_dicts = []
for row in data.data:
user_dict = {
"id": row['id'],
}
user_dicts.append(user_dict)
return user_dicts
def get_user_by_email(email):
data = client.table('users').select('*').eq("email", email).single().execute()
return data.data
#############################################
######## MOVIES #############################
#############################################
def insert_movies(title, director, genre, p_year, v_date, rating, rewatch, tv_show, poster, parent_id, cinema):
# Insert data into Supabase table
client.table('lista').insert({"movie": title, "director": director, "genre": genre, "p_year": p_year, "v_date": v_date, "rating": rating, "rewatch": rewatch, "tv_show": tv_show, "poster": poster, "parent_id": parent_id, "cinema": cinema}).execute()
def get_movies(parent_id):
# Fetch data from Supabase table
data = client.table('lista').select('*').eq("parent_id", parent_id).execute()
lista_dicts = []
for row in data.data:
movie_dict = {
"id": row['lista_id'],
"movie": row['movie'],
"director": row['director'],
"genre": row['genre'],
"p_year": row['p_year'],
"v_date": datetime.strptime(row['v_date'], "%Y-%m-%d").date(),
"rating": row['rating'],
"rewatch": row['rewatch'],
"tv_show": row['tv_show'],
"poster": row['poster'],
"cinema": row['cinema']
}
lista_dicts.append(movie_dict)
return lista_dicts
def get_monthly_movies(parent_id, month):
start_date = datetime(year=datetime.now().year, month=month, day=1)
end_date = start_date + timedelta(days=31) # Assuming 31 days maximum for a month
# Execute the query
response = client.table('lista') \
.select('*') \
.eq('parent_id', parent_id) \
.gte('v_date', start_date.strftime('%Y-%m-%d')) \
.lt('v_date', end_date.strftime('%Y-%m-%d')) \
.execute()
lista_dicts = []
for row in response.data:
movie_dict = {
"id": row['lista_id'],
"movie": row['movie'],
"director": row['director'],
"genre": row['genre'],
"p_year": row['p_year'],
"v_date": row['v_date'],
"rating": row['rating'],
"rewatch": row['rewatch'],
"tv_show": row['tv_show'],
"poster": row['poster'],
"cinema": row['cinema']
}
lista_dicts.append(movie_dict)
return lista_dicts
def remove_movie_by_id(movie_id):
# Remove data from Supabase table
client.table('lista').delete().eq('lista_id', movie_id).execute()
def update_movie(lista_id, movie, director, p_year, rating, poster):
# Update data in Supabase table
client.table('lista').update({"movie": movie, "director": director, "p_year": p_year, "rating": rating, "poster": poster}).eq('lista_id', lista_id).execute()
def get_movies_groupby_director(parent_id):
data = client.table('lista') \
.select('*') \
.eq('parent_id', parent_id) \
.order('director') \
.execute()
# Process the results
lista_dicts = []
for row in data.data:
lista_dicts.append({
"id": row['lista_id'],
"movie": row['movie'],
"director": row['director'],
"genre": row['genre'],
"p_year": row['p_year'],
"v_date": row['v_date'],
"rating": row['rating'],
"rewatch": row['rewatch'],
"tv_show": row['tv_show'],
"poster": row['poster']
})
return lista_dicts
def get_directors(parent_id):
data = client.table('lista') \
.select('director') \
.eq('parent_id', parent_id) \
.order('director') \
.execute()
# Process the results
distinct_directors = set()
lista_dicts = []
for row in data.data:
distinct_directors.add(row['director'])
for director in distinct_directors:
lista_dicts.append({
"name": director
})
return lista_dicts
def get_movies_groupby_genre(parent_id):
data = client.table('lista') \
.select('*') \
.eq('parent_id', parent_id) \
.order('genre') \
.execute()
# Process the results
lista_dicts = []
for row in data.data:
lista_dicts.append({
"id": row['lista_id'],
"movie": row['movie'],
"director": row['director'],
"genre": row['genre'],
"p_year": row['p_year'],
"v_date": row['v_date'],
"rating": row['rating'],
"rewatch": row['rewatch'],
"tv_show": row['tv_show'],
"poster": row['poster']
})
return lista_dicts
def get_genres(parent_id):
data = client.table('lista') \
.select('genre') \
.eq('parent_id', parent_id) \
.order('genre') \
.execute()
# Process the results
distinct_genres = set()
lista_dicts = []
for row in data.data:
distinct_genres.add(row['genre'])
for genre in distinct_genres:
lista_dicts.append({
"name": genre
})
return lista_dicts
def get_movies_groupby_year(parent_id):
data = client.table('lista') \
.select('*') \
.eq('parent_id', parent_id) \
.order('p_year') \
.execute()
# Process the results
lista_dicts = []
for row in data.data:
lista_dicts.append({
"id": row['lista_id'],
"movie": row['movie'],
"director": row['director'],
"genre": row['genre'],
"p_year": row['p_year'],
"v_date": row['v_date'],
"rating": row['rating'],
"rewatch": row['rewatch'],
"tv_show": row['tv_show'],
"poster": row['poster']
})
return lista_dicts
def get_years(parent_id):
data = client.table('lista') \
.select('p_year') \
.eq('parent_id', parent_id) \
.order('p_year') \
.execute()
# Process the results
distinct_years = set()
lista_dicts = []
for row in data.data:
distinct_years.add(row['p_year'])
for year in distinct_years:
lista_dicts.append({
"name": year
})
return lista_dicts
def get_movies_groupby_rating(parent_id):
data = client.table('lista') \
.select('*') \
.eq('parent_id', parent_id) \
.order('rating') \
.execute()
# Process the results
lista_dicts = []
for row in data.data:
lista_dicts.append({
"id": row['lista_id'],
"movie": row['movie'],
"director": row['director'],
"genre": row['genre'],
"p_year": row['p_year'],
"v_date": row['v_date'],
"rating": row['rating'],
"rewatch": row['rewatch'],
"tv_show": row['tv_show'],
"poster": row['poster']
})
return lista_dicts
def get_ratings(parent_id):
data = client.table('lista') \
.select('rating') \
.eq('parent_id', parent_id) \
.order('rating') \
.execute()
# Process the results
distinct_ratings = set()
lista_dicts = []
for row in data.data:
distinct_ratings.add(row['rating'])
for rating in distinct_ratings:
lista_dicts.append({
"name": rating
})
return lista_dicts
def get_highest_rating():
start_date = datetime(year=datetime.now().year, month=datetime.now().month - 1, day=1)
end_date = start_date + timedelta(days=62) # Assuming 31 days maximum for a month
# Execute the query
data = client.table('lista') \
.select('movie', 'director', 'p_year', 'poster') \
.gte('rating', 9) \
.gte('v_date', start_date.strftime('%Y-%m-%d')) \
.lt('v_date', end_date.strftime('%Y-%m-%d')) \
.execute()
distinct_movies = set()
lista_dicts = []
for row in data.data:
distinct_movies.add((row['movie'], row['director'], row['p_year'], row['poster']))
for movie in distinct_movies:
lista_dicts.append({
"movie": movie[0],
"director": movie[1],
"p_year": movie[2],
"poster": movie[3]
})
return lista_dicts
#############################################
######## FRIENDS ############################
#############################################
def insert_friends(user_id, f_username, parent_id):
# Insert data into Supabase table
client.table('friends').insert({"user_id": user_id, "f_username": f_username, "parent_id": parent_id}).execute()
def get_friends(parent_id):
# Fetch data from Supabase table
data = client.table('friends').select('*').eq("parent_id", parent_id).execute()
friends_dicts = []
for row in data.data:
friend_dict = {
"id": row['friend_id'],
"user_id": row['user_id'],
"f_username": row['f_username']
}
friends_dicts.append(friend_dict)
return friends_dicts
#############################################
####### TOKENS ##############################
#############################################
def insert_token(user_id, token, date):
client.table('tokens') \
.insert([{'token': token, 'user_id': user_id, 'created_at': date}]) \
.execute()
def get_token(token):
data = client.table('tokens').select('*').eq("token", token).single().execute()
return data.data
def delete_token(token):
client.table('tokens').delete().eq('token', token).execute()
def update_user_password(user_id, password):
client.table('users').update({"password": password}).eq('id', user_id).execute()
#from sqlalchemy import create_engine, text
#db_connection_string = os.environ.get("SECRET_DB_CONNECTION_STRING")
#
#engine = create_engine(db_connection_string,
# #connect_args= {
# # "ssl": {
# # "ssl_ca": "/etc/ssl/cert.pem"
# # }
# # }
# )
#
#def load_users_from_db():
# with engine.connect() as conn:
# rows = conn.execute(text("SELECT * FROM users"))
# user_dicts = []
# for row in rows:
# user_dict = {}
# user_dict["id"] = row[0]
# user_dict["username"] = row[1]
# user_dict["email"] = row[2]
# user_dicts.append(user_dict)
# return user_dicts
#
#def load_users_from_username(name):
# with engine.connect() as conn:
# # define a SQL query with a parameter
# query = text('SELECT * FROM users WHERE username = :username').bindparams(username=name)
# # execute the query with a parameter value
# result = conn.execute(query)
#
# user_dicts = []
# for row in result:
# user_dict = {}
# user_dict["id"] = row[0]
# user_dict["username"] = row[1]
# user_dict["email"] = row[2]
# user_dicts.append(user_dict)
# return user_dicts
#
#def load_users_from_email(email):
# with engine.connect() as conn:
# # define a SQL query with a parameter
# query = text('SELECT * FROM users WHERE email = :email').bindparams(email=email)
# # execute the query with a parameter value
# result = conn.execute(query)
# user_dicts = []
# for row in result:
# user_dict = {}
# user_dict["id"] = row[0]
# user_dict["username"] = row[1]
# user_dict["email"] = row[2]
# user_dict["password"] = row[3]
# user_dicts.append(user_dict)
# return user_dicts
#
#def insert_user(username, email, password):
# with engine.connect() as conn:
# query = text('INSERT INTO users (username, email, password) VALUES (:username, :email, :password)').bindparams(username=username, email=email, password=password)
# conn.execute(query)
#
#def get_user_by_id(id):
# with engine.connect() as conn:
# # define a SQL query with a parameter
# query = text('SELECT * FROM users WHERE id = :id').bindparams(id=id)
# # execute the query with a parameter value
# result = conn.execute(query)
# user_dicts = []
# for row in result:
# user_dict = {}
# user_dict["id"] = row[0]
# user_dict["username"] = row[1]
# user_dict["email"] = row[2]
# user_dict["password"] = row[3]
# user_dicts.append(user_dict)
# return user_dicts
#
#def insert_movies(title, director, genre, p_year, v_date, rating, rewatch, tv_show, poster, parent_id, cinema):
# with engine.connect() as conn:
# query = text('INSERT INTO lista (movie, director, genre, p_year, v_date, rating, rewatch, tv_show, poster, parent_id, cinema) \
# VALUES (:movie, :director, :genre, :p_year, :v_date, :rating, :rewatch, :tv_show, :poster, :parent_id, :cinema)'
# ).bindparams(movie=title, director=director, genre=genre, p_year=p_year, v_date=v_date, rating=rating, rewatch=rewatch, tv_show=tv_show, poster=poster, parent_id=parent_id, cinema=cinema)
# conn.execute(query)
#
#def get_movies(parent_id):
# with engine.connect() as conn:
# query = text('SELECT * FROM lista WHERE parent_id = :parent_id').bindparams(parent_id=parent_id)
# result = conn.execute(query)
# lista_dicts = []
# for row in result:
# lista_dict = {}
# lista_dict["id"] = row[0]
# lista_dict["movie"] = row[1]
# lista_dict["director"] = row[2]
# lista_dict["genre"] = row[3]
# lista_dict["p_year"] = row[4]
# lista_dict["v_date"] = row[5]
# lista_dict["rating"] = row[6]
# lista_dict["rewatch"] = row[7]
# lista_dict["tv_show"] = row[8]
# lista_dict["poster"] = row[9]
# lista_dict["cinema"] = row[11]
# lista_dicts.append(lista_dict)
# return lista_dicts
#
#def get_monthly_movies(parent_id, month):
# with engine.connect() as conn:
# query = text('SELECT * FROM lista WHERE parent_id = :parent_id and MONTH(v_date) = :month').bindparams(parent_id=parent_id, month=month)
# result = conn.execute(query)
# lista_dicts = []
# for row in result:
# lista_dict = {}
# lista_dict["id"] = row[0]
# lista_dict["movie"] = row[1]
# lista_dict["director"] = row[2]
# lista_dict["genre"] = row[3]
# lista_dict["p_year"] = row[4]
# lista_dict["v_date"] = row[5]
# lista_dict["rating"] = row[6]
# lista_dict["rewatch"] = row[7]
# lista_dict["tv_show"] = row[8]
# lista_dict["poster"] = row[9]
# lista_dicts.append(lista_dict)
# return lista_dicts
#
#def get_user_name(name):
# with engine.connect() as conn:
# query = text('SELECT * FROM users WHERE username = :username').bindparams(username=name)
# result = conn.execute(query)
# user_dicts = []
# for row in result:
# user_dict = {}
# user_dict["id"] = row[0]
# user_dict["username"] = row[1]
# user_dicts.append(user_dict)
# return user_dicts
#
#def get_user_id(name):
# with engine.connect() as conn:
# query = text('SELECT * FROM users WHERE username = :username').bindparams(username=name)
# result = conn.execute(query)
# user_dicts = []
# for row in result:
# user_dict = {}
# user_dict["id"] = row[0]
# user_dicts.append(user_dict)
# return user_dicts
#
#def insert_friends(user_id, f_username, parent_id):
# with engine.connect() as conn:
# query = text('INSERT INTO friends (user_id, f_username, parent_id) VALUES (:user_id,:f_username, :parent_id)').bindparams(user_id=user_id, f_username=f_username ,parent_id=parent_id)
# conn.execute(query)
#
#def get_friends(parent_id):
# with engine.connect() as conn:
# query = text('SELECT * FROM friends WHERE parent_id = :parent_id').bindparams(parent_id=parent_id)
# result = conn.execute(query)
# friends_dicts = []
# for row in result:
# friends_dict = {}
# friends_dict["id"] = row[0]
# friends_dict["user_id"] = row[1]
# friends_dict["f_username"] = row[2]
# friends_dicts.append(friends_dict)
# return friends_dicts
#
#def remove_movie_by_id(lista_id):
# with engine.connect() as conn:
# query = text('DELETE FROM lista WHERE lista_id = :lista_id').bindparams(lista_id=lista_id)
# conn.execute(query)
#
#def update_movie(lista_id, movie, director, p_year, rating, poster):
# with engine.connect() as conn:
# query = text('UPDATE lista SET movie=:movie, director=:director, p_year=:p_year, rating=:rating, poster=:poster WHERE lista_id = :lista_id').bindparams(lista_id=lista_id, movie=movie, director=director, p_year=p_year, rating=rating, poster=poster)
# conn.execute(query)
#
#def get_movies_groupby_director(parent_id):
# with engine.connect() as conn:
# query = text('SELECT * FROM lista WHERE parent_id = :parent_id ORDER BY director').bindparams(parent_id=parent_id)
# result = conn.execute(query)
# lista_dicts = []
# for row in result:
# lista_dict = {}
# lista_dict["id"] = row[0]
# lista_dict["movie"] = row[1]
# lista_dict["director"] = row[2]
# lista_dict["genre"] = row[3]
# lista_dict["p_year"] = row[4]
# lista_dict["v_date"] = row[5]
# lista_dict["rating"] = row[6]
# lista_dict["rewatch"] = row[7]
# lista_dict["tv_show"] = row[8]
# lista_dict["poster"] = row[9]
# lista_dicts.append(lista_dict)
# return lista_dicts
#
#def get_directors(parent_id):
# with engine.connect() as conn:
# query = text('SELECT DISTINCT director FROM lista WHERE parent_id = :parent_id ORDER BY director').bindparams(parent_id=parent_id)
# result = conn.execute(query)
# lista_dicts = []
# for row in result:
# lista_dict = {}
# lista_dict["name"] = row[0]
# lista_dicts.append(lista_dict)
# return lista_dicts
#
#def get_movies_groupby_genre(parent_id):
# with engine.connect() as conn:
# query = text('SELECT * FROM lista WHERE parent_id = :parent_id ORDER BY genre').bindparams(parent_id=parent_id)
# result = conn.execute(query)
# lista_dicts = []
# for row in result:
# lista_dict = {}
# lista_dict["id"] = row[0]
# lista_dict["movie"] = row[1]
# lista_dict["director"] = row[2]
# lista_dict["genre"] = row[3]
# lista_dict["p_year"] = row[4]
# lista_dict["v_date"] = row[5]
# lista_dict["rating"] = row[6]
# lista_dict["rewatch"] = row[7]
# lista_dict["tv_show"] = row[8]
# lista_dict["poster"] = row[9]
# lista_dicts.append(lista_dict)
# return lista_dicts
#
#def get_genres(parent_id):
# with engine.connect() as conn:
# query = text('SELECT DISTINCT genre FROM lista WHERE parent_id = :parent_id ORDER BY genre').bindparams(parent_id=parent_id)
# result = conn.execute(query)
# lista_dicts = []
# for row in result:
# lista_dict = {}
# lista_dict["name"] = row[0]
# lista_dicts.append(lista_dict)
# return lista_dicts
#
#def get_movies_groupby_year(parent_id):
# with engine.connect() as conn:
# query = text('SELECT * FROM lista WHERE parent_id = :parent_id ORDER BY p_year').bindparams(parent_id=parent_id)
# result = conn.execute(query)
# lista_dicts = []
# for row in result:
# lista_dict = {}
# lista_dict["id"] = row[0]
# lista_dict["movie"] = row[1]
# lista_dict["director"] = row[2]
# lista_dict["genre"] = row[3]
# lista_dict["p_year"] = row[4]
# lista_dict["v_date"] = row[5]
# lista_dict["rating"] = row[6]
# lista_dict["rewatch"] = row[7]
# lista_dict["tv_show"] = row[8]
# lista_dict["poster"] = row[9]
# lista_dicts.append(lista_dict)
# return lista_dicts
#
#def get_years(parent_id):
# with engine.connect() as conn:
# query = text('SELECT DISTINCT p_year FROM lista WHERE parent_id = :parent_id ORDER BY p_year').bindparams(parent_id=parent_id)
# result = conn.execute(query)
# lista_dicts = []
# for row in result:
# lista_dict = {}
# lista_dict["name"] = row[0]
# lista_dicts.append(lista_dict)
# return lista_dicts
#
#def get_movies_groupby_rating(parent_id):
# with engine.connect() as conn:
# query = text('SELECT * FROM lista WHERE parent_id = :parent_id ORDER BY rating').bindparams(parent_id=parent_id)
# result = conn.execute(query)
# lista_dicts = []
# for row in result:
# lista_dict = {}
# lista_dict["id"] = row[0]
# lista_dict["movie"] = row[1]
# lista_dict["director"] = row[2]
# lista_dict["genre"] = row[3]
# lista_dict["p_year"] = row[4]
# lista_dict["v_date"] = row[5]
# lista_dict["rating"] = row[6]
# lista_dict["rewatch"] = row[7]
# lista_dict["tv_show"] = row[8]
# lista_dict["poster"] = row[9]
# lista_dicts.append(lista_dict)
# return lista_dicts
#
#def get_ratings(parent_id):
# with engine.connect() as conn:
# query = text('SELECT DISTINCT rating FROM lista WHERE parent_id = :parent_id ORDER BY rating').bindparams(parent_id=parent_id)
# result = conn.execute(query)
# lista_dicts = []
# for row in result:
# lista_dict = {}
# lista_dict["name"] = row[0]
# lista_dicts.append(lista_dict)
# return lista_dicts
#
#def get_user_by_email(email):
# with engine.connect() as conn:
# query = text('SELECT * FROM users WHERE email = :email').bindparams(email=email)
# result = conn.execute(query)
# user = result.fetchone()
# return user
#
#def insert_token(token, user_id, date):
# with engine.connect() as conn:
# query = text('INSERT INTO tokens (token, user_id, created_at) VALUES (:token, :user_id, :created_at)').bindparams(token=token, user_id=user_id, created_at=date)
# conn.execute(query)
#
#def get_token(token):
# with engine.connect() as conn:
# query = text('SELECT * FROM tokens WHERE token = :token').bindparams(token=token)
# result = conn.execute(query)
# token = result.fetchone()
# return token
#
#def delete_token(token):
# with engine.connect() as conn:
# query = text('DELETE FROM tokens WHERE token = :token').bindparams(token=token)
# conn.execute(query)
#
#def update_user_password(user_id, password):
# with engine.connect() as conn:
# query = text('UPDATE users SET password = :password WHERE id = :user_id').bindparams(password=password, user_id=user_id)
# conn.execute(query)
#
#def get_highest_rating():
# with engine.connect() as conn:
# query = text('SELECT DISTINCT movie, director, p_year, poster FROM lista WHERE rating >= 9 AND v_date >= DATE_SUB(CURDATE(), INTERVAL 2 MONTH)')
# result = conn.execute(query)
# lista_dicts = []
# for row in result:
# lista_dict = {}
# lista_dict["movie"] = row[0]
# lista_dict["director"] = row[1]
# lista_dict["p_year"] = row[2]
# lista_dict["poster"] = row[3]
# lista_dicts.append(lista_dict)
# return lista_dicts