forked from wfsyre/tribe-workout-bots
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdatabase_connection.py
705 lines (646 loc) · 24.8 KB
/
database_connection.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
import os
import urllib.parse
import urllib.request
import psycopg2
from psycopg2 import sql
from slack_api import *
from flask import Flask, request, jsonify, make_response
app = Flask(__name__)
def add_num_posts(mention_id, event_time, name):
# "UPDATE wreck_data SET num_posts=num_posts+1, WHERE name = 'William Syre' AND last_time != "
try:
urllib.parse.uses_netloc.append("postgres")
url = urllib.parse.urlparse(os.environ["DATABASE_URL"])
conn = psycopg2.connect(
database=url.path[1:],
user=url.username,
password=url.password,
host=url.hostname,
port=url.port
)
cursor = conn.cursor()
# get all of the people who's workout scores are greater than -1 (any non players have a workout score of -1)
cursor.execute(sql.SQL(
"UPDATE wreck_data SET num_posts=num_posts+1 WHERE slack_id = %s"),
[mention_id[0]])
if cursor.rowcount == 0:
cursor.execute(sql.SQL("INSERT INTO wreck_data VALUES (%s, 0, 0, 0, now(), %s, %s)"),
[name, mention_id[0], event_time])
send_debug_message("%s is new to Wreck" % name)
conn.commit()
cursor.close()
conn.close()
return True
except (Exception, psycopg2.DatabaseError) as error:
send_debug_message(error)
return True
def collect_stats(datafield, rev):
try:
urllib.parse.uses_netloc.append("postgres")
url = urllib.parse.urlparse(os.environ["DATABASE_URL"])
conn = psycopg2.connect(
database=url.path[1:],
user=url.username,
password=url.password,
host=url.hostname,
port=url.port
)
cursor = conn.cursor()
# get all of the people who's workout scores are greater than -1 (any non players have a workout score of -1)
cursor.execute(sql.SQL(
"SELECT * FROM wreck_data WHERE workout_score > -1.0"), )
leaderboard = cursor.fetchall()
leaderboard.sort(key=lambda s: s[datafield], reverse=rev) # sort the leaderboard by score descending
string1 = "Leaderboard:\n"
for x in range(0, len(leaderboard)):
string1 += '%d) %s with %.1f points \n' % (x + 1, leaderboard[x][0], leaderboard[x][datafield])
cursor.close()
conn.close()
return string1
except (Exception, psycopg2.DatabaseError) as error:
send_debug_message(error)
def get_group_info():
url = "https://slack.com/api/users.list?token=" + os.getenv('BOT_OAUTH_ACCESS_TOKEN')
json = requests.get(url).json()
return json
def get_emojis():
url = 'https://slack.com/api/emoji.list?token=' + os.getenv('OAUTH_ACCESS_TOKEN')
json = requests.get(url).json()
return json
def add_to_db(names, addition, num_workouts, ids): # add "addition" to each of the "names" in the db
cursor = None
conn = None
num_committed = 0
try:
urllib.parse.uses_netloc.append("postgres")
url = urllib.parse.urlparse(os.environ["DATABASE_URL"])
conn = psycopg2.connect(
database=url.path[1:],
user=url.username,
password=url.password,
host=url.hostname,
port=url.port
)
cursor = conn.cursor()
for x in range(0, len(names)):
print("starting", names[x])
cursor.execute(sql.SQL(
"SELECT workout_score FROM wreck_data WHERE slack_id = %s"), [str(ids[x])])
score = cursor.fetchall()[0][0]
score = int(score)
if score != -1:
cursor.execute(sql.SQL(
"UPDATE wreck_data SET num_workouts=num_workouts+%s, workout_score=workout_score+%s, last_post="
"now() WHERE slack_id = %s"),
[str(num_workouts), str(addition), ids[x]])
conn.commit()
send_debug_message("committed %s with %s points" % (names[x], str(addition)))
print("committed %s" % names[x])
num_committed += 1
else:
send_debug_message("invalid workout poster found " + names[x])
except (Exception, psycopg2.DatabaseError) as error:
send_debug_message(str(error))
finally:
if cursor is not None:
cursor.close()
conn.close()
return num_committed
def subtract_from_db(names, subtraction, ids): # subtract "subtraction" from each of the "names" in the db
cursor = None
conn = None
num_committed = 0
try:
urllib.parse.uses_netloc.append("postgres")
url = urllib.parse.urlparse(os.environ["DATABASE_URL"])
conn = psycopg2.connect(
database=url.path[1:],
user=url.username,
password=url.password,
host=url.hostname,
port=url.port
)
cursor = conn.cursor()
for x in range(0, len(names)):
cursor.execute(sql.SQL(
"UPDATE wreck_data SET workout_score = workout_score - %s WHERE slack_id = %s"),
[subtraction, ids[x]])
conn.commit()
send_debug_message("subtracted %s" % names[x])
num_committed += 1
except (Exception, psycopg2.DatabaseError) as error:
send_debug_message(str(error))
finally:
if cursor is not None:
cursor.close()
conn.close()
return num_committed
def reset_scores(): # reset the scores of everyone
cursor = None
conn = None
try:
urllib.parse.uses_netloc.append("postgres")
url = urllib.parse.urlparse(os.environ["DATABASE_URL"])
conn = psycopg2.connect(
database=url.path[1:],
user=url.username,
password=url.password,
host=url.hostname,
port=url.port
)
cursor = conn.cursor()
cursor.execute(sql.SQL(
"UPDATE wreck_data SET num_workouts = 0, workout_score = 0, last_post = now() WHERE workout_score != -1"
))
# cursor.execute(sql.SQL(
# "DELETE FROM tribe_workouts"
# ))
conn.commit()
except (Exception, psycopg2.DatabaseError) as error:
send_debug_message(str(error))
finally:
if cursor is not None:
cursor.close()
conn.close()
def reset_talkative(): # reset the num_posts of everyone
cursor = None
conn = None
try:
urllib.parse.uses_netloc.append("postgres")
url = urllib.parse.urlparse(os.environ["DATABASE_URL"])
conn = psycopg2.connect(
database=url.path[1:],
user=url.username,
password=url.password,
host=url.hostname,
port=url.port
)
cursor = conn.cursor()
cursor.execute(sql.SQL(
"UPDATE wreck_data SET num_posts = 0 WHERE workout_score != -1"))
conn.commit()
except (Exception, psycopg2.DatabaseError) as error:
send_debug_message(str(error))
finally:
if cursor is not None:
cursor.close()
conn.close()
def add_reaction_info_date(date, yes, drills, injured, no):
# "UPDATE wreck_data SET num_posts=num_posts+1, WHERE name = 'William Syre' AND last_time != "
try:
urllib.parse.uses_netloc.append("postgres")
url = urllib.parse.urlparse(os.environ["DATABASE_URL"])
conn = psycopg2.connect(
database=url.path[1:],
user=url.username,
password=url.password,
host=url.hostname,
port=url.port
)
# cursor = conn.cursor()
# cursor.execute(sql.SQL("SELECT * FROM reaction_info WHERE date = %s"), [date])
# if cursor.rowcount == 0:
# cursor.execute(
# sql.SQL("INSERT INTO reaction_info (date, yes, no, drills, injured) VALUES (%s, %s, %s, %s, %s)"),
# [date.strftime("%Y-%B-%d"), yes, no, drills, injured])
# conn.commit()
# cursor.close()
# conn.close()
# return True
# else:
# conn.commit()
# cursor.close()
# conn.close()
# send_debug_message("Found a repeat calendar post")
# return False
except (Exception, psycopg2.DatabaseError) as error:
send_debug_message(error)
def add_reaction_info_ts(ts):
# "UPDATE wreck_data SET num_posts=num_posts+1, WHERE name = 'Sam Loop' AND last_time != "
try:
urllib.parse.uses_netloc.append("postgres")
url = urllib.parse.urlparse(os.environ["DATABASE_URL"])
conn = psycopg2.connect(
database=url.path[1:],
user=url.username,
password=url.password,
host=url.hostname,
port=url.port
)
# cursor = conn.cursor()
# cursor.execute(sql.SQL("UPDATE reaction_info SET timestamp = %s WHERE timestamp IS NULL"),
# [ts])
# if cursor.rowcount == 1:
# conn.commit()
# cursor.close()
# conn.close()
# return True
# else:
# conn.commit()
# cursor.close()
# conn.close()
# return False
except (Exception, psycopg2.DatabaseError) as error:
send_debug_message(error)
def check_reaction_timestamp(ts):
try:
urllib.parse.uses_netloc.append("postgres")
url = urllib.parse.urlparse(os.environ["DATABASE_URL"])
conn = psycopg2.connect(
database=url.path[1:],
user=url.username,
password=url.password,
host=url.hostname,
port=url.port
)
# cursor = conn.cursor()
# cursor.execute(sql.SQL("SELECT * FROM reaction_info WHERE timestamp = %s"), [ts])
# if cursor.rowcount == 1:
# stuff = cursor.fetchall()
# conn.commit()
# cursor.close()
# conn.close()
# print(stuff)
# return stuff
# else:
# conn.commit()
# cursor.close()
# conn.close()
# return []
except (Exception, psycopg2.DatabaseError) as error:
send_debug_message(error)
return []
def count_practice(id, date, number):
try:
urllib.parse.uses_netloc.append("postgres")
url = urllib.parse.urlparse(os.environ["DATABASE_URL"])
conn = psycopg2.connect(
database=url.path[1:],
user=url.username,
password=url.password,
host=url.hostname,
port=url.port
)
# cursor = conn.cursor()
# # get all of the people who's workout scores are greater than -1 (any non players have a workout score of -1)
# cursor.execute(sql.SQL("UPDATE tribe_attendance SET attendance_code = %s, date_responded=now() where slack_id = %s and practice_date = %s"), [number, id, date])
# if cursor.rowcount == 1:
# conn.commit()
# cursor.close()
# conn.close()
# send_debug_message("marked <@" + str(id) + "> as " + str(number) + " for practice on " + date)
# else:
# conn.commit()
# cursor.close()
# conn.close()
except (Exception, psycopg2.DatabaseError) as error:
send_debug_message(error)
def add_dummy_responses(date):
try:
urllib.parse.uses_netloc.append("postgres")
url = urllib.parse.urlparse(os.environ["DATABASE_URL"])
conn = psycopg2.connect(
database=url.path[1:],
user=url.username,
password=url.password,
host=url.hostname,
port=url.port
)
cursor = conn.cursor()
cursor.execute(sql.SQL("SELECT slack_id, name FROM wreck_data WHERE workout_score != -1"))
stuff = cursor.fetchall()
print("This is the stuff")
print(stuff)
# for slack_id, real_name in stuff:
# cursor.execute(sql.SQL("INSERT INTO tribe_attendance VALUES(%s, %s, -1, %s, now())"),
# [real_name, slack_id, date])
# conn.commit()
# cursor.close()
# conn.close()
except (Exception, psycopg2.DatabaseError) as error:
send_debug_message(error)
def get_unanswered(date):
try:
urllib.parse.uses_netloc.append("postgres")
url = urllib.parse.urlparse(os.environ["DATABASE_URL"])
conn = psycopg2.connect(
database=url.path[1:],
user=url.username,
password=url.password,
host=url.hostname,
port=url.port
)
# cursor = conn.cursor()
# # get all of the people who's workout scores are greater than -1 (any non players have a workout score of -1)
# cursor.execute(sql.SQL("SELECT slack_id FROM tribe_attendance WHERE practice_date = %s and attendance_code = -1"), [date])
# unanswered = cursor.fetchall()
# print(unanswered)
# return unanswered
except (Exception, psycopg2.DatabaseError) as error:
send_debug_message(error)
return []
def get_practice_attendance(date):
try:
urllib.parse.uses_netloc.append("postgres")
url = urllib.parse.urlparse(os.environ["DATABASE_URL"])
conn = psycopg2.connect(
database=url.path[1:],
user=url.username,
password=url.password,
host=url.hostname,
port=url.port
)
# cursor = conn.cursor()
# # get all of the people who's workout scores are greater than -1 (any non players have a workout score of -1)
# cursor.execute(sql.SQL("SELECT name FROM tribe_attendance WHERE practice_date = %s AND attendance_code = 1"), [date])
# injured = cursor.fetchall()
# injured = [x[0] for x in injured]
# cursor.execute(sql.SQL("SELECT name FROM tribe_attendance WHERE practice_date = %s AND attendance_code = -1"), [date])
# unanswered = cursor.fetchall()
# unanswered = [x[0] for x in unanswered]
# cursor.execute(sql.SQL("SELECT name FROM tribe_attendance WHERE practice_date = %s AND attendance_code = 2"), [date])
# drills = cursor.fetchall()
# drills = [x[0] for x in drills]
# cursor.execute(sql.SQL("SELECT name FROM tribe_attendance WHERE practice_date = %s AND attendance_code = 3"), [date])
# playing = cursor.fetchall()
# playing = [x[0] for x in playing]
# cursor.execute(sql.SQL("SELECT name FROM tribe_attendance WHERE practice_date = %s AND attendance_code = 0"), [date])
# missing = cursor.fetchall()
# missing = [x[0] for x in missing]
# toRet = {'playing': playing, 'injured': injured, 'drills': drills, 'unanswered': unanswered, "missing": missing}
# print(toRet)
# return toRet
except (Exception, psycopg2.DatabaseError) as error:
send_debug_message(error)
return {'failure': []}
def add_workout(name, slack_id, workout_type):
cursor = None
conn = None
try:
urllib.parse.uses_netloc.append("postgres")
url = urllib.parse.urlparse(os.environ["DATABASE_URL"])
conn = psycopg2.connect(
database=url.path[1:],
user=url.username,
password=url.password,
host=url.hostname,
port=url.port
)
# cursor = conn.cursor()
# cursor.execute(sql.SQL("INSERT INTO tribe_workouts VALUES (%s, %s, %s, now())"), [str(name), str(slack_id), str(workout_type)])
# conn.commit()
# send_debug_message("Committed " + name + " to the workout list")
except (Exception, psycopg2.DatabaseError) as error:
send_debug_message(str(error))
finally:
if cursor is not None:
cursor.close()
conn.close()
def get_workouts_after_date(date, type, slack_id):
cursor = None
conn = None
workouts = []
try:
urllib.parse.uses_netloc.append("postgres")
url = urllib.parse.urlparse(os.environ["DATABASE_URL"])
conn = psycopg2.connect(
database=url.path[1:],
user=url.username,
password=url.password,
host=url.hostname,
port=url.port
)
# cursor = conn.cursor()
# cursor.execute(sql.SQL("SELECT * from tribe_workouts WHERE slack_id=%s and workout_date BETWEEN %s and now() and workout_type=%s"),
# [slack_id, date, "!" + type])
# workouts = cursor.fetchall()
# conn.commit()
except (Exception, psycopg2.DatabaseError) as error:
send_debug_message(str(error))
finally:
if cursor is not None:
cursor.close()
conn.close()
return workouts
def get_group_workouts_after_date(date, type):
cursor = None
conn = None
workouts = []
print(date, type)
try:
urllib.parse.uses_netloc.append("postgres")
url = urllib.parse.urlparse(os.environ["DATABASE_URL"])
conn = psycopg2.connect(
database=url.path[1:],
user=url.username,
password=url.password,
host=url.hostname,
port=url.port
)
# cursor = conn.cursor()
# cursor.execute(sql.SQL("SELECT * from tribe_workouts WHERE workout_date BETWEEN %s and now() and workout_type=%s"),
# [date, "!" + type])
# workouts = cursor.fetchall()
# conn.commit()
except (Exception, psycopg2.DatabaseError) as error:
send_debug_message(str(error))
finally:
if cursor is not None:
cursor.close()
conn.close()
return workouts
def add_tracked_poll(title, slack_id, ts, options, channel, anonymous):
send_debug_message(anonymous)
send_debug_message(channel)
option_string = '{' + ', '.join(['\"' + x + '\"' for x in options]) + '}'
send_debug_message(option_string)
cursor = None
conn = None
try:
urllib.parse.uses_netloc.append("postgres")
url = urllib.parse.urlparse(os.environ["DATABASE_URL"])
conn = psycopg2.connect(
database=url.path[1:],
user=url.username,
password=url.password,
host=url.hostname,
port=url.port
)
# cursor = conn.cursor()
# cursor.execute(sql.SQL("INSERT INTO tribe_poll_data VALUES (%s, %s, %s, %s, %s, %s)"),
# [ts, slack_id, title, option_string, channel, anonymous])
# conn.commit()
# send_debug_message("Committed " + title + " to the poll list")
except (Exception, psycopg2.DatabaseError) as error:
send_debug_message(str(error))
finally:
if cursor is not None:
cursor.close()
conn.close()
def add_poll_reaction(ts, options_number, slack_id):
cursor = None
conn = None
try:
urllib.parse.uses_netloc.append("postgres")
url = urllib.parse.urlparse(os.environ["DATABASE_URL"])
conn = psycopg2.connect(
database=url.path[1:],
user=url.username,
password=url.password,
host=url.hostname,
port=url.port
)
# cursor = conn.cursor()
# cursor.execute(sql.SQL("UPDATE tribe_poll_responses SET response_num=%s where slack_id=%s AND ts=%s"),
# [options_number, slack_id, ts])
# conn.commit()
# send_debug_message("Committed <@" + slack_id + ">'s response to the poll responses")
except (Exception, psycopg2.DatabaseError) as error:
send_debug_message(str(error))
finally:
if cursor is not None:
cursor.close()
conn.close()
def add_poll_dummy_responses(ts):
try:
urllib.parse.uses_netloc.append("postgres")
url = urllib.parse.urlparse(os.environ["DATABASE_URL"])
conn = psycopg2.connect(
database=url.path[1:],
user=url.username,
password=url.password,
host=url.hostname,
port=url.port
)
# cursor = conn.cursor()
# cursor.execute(sql.SQL("SELECT slack_id, name FROM wreck_data WHERE workout_score != -1"))
# stuff = cursor.fetchall()
# print("This is the stuff")
# print(stuff)
# for slack_id, real_name in stuff:
# cursor.execute(sql.SQL("INSERT INTO tribe_poll_responses VALUES(%s, %s, %s, -1)"),
# [ts, real_name, slack_id])
# conn.commit()
# cursor.close()
# conn.close()
except (Exception, psycopg2.DatabaseError) as error:
send_debug_message(error)
def get_poll_data(ts):
try:
urllib.parse.uses_netloc.append("postgres")
url = urllib.parse.urlparse(os.environ["DATABASE_URL"])
conn = psycopg2.connect(
database=url.path[1:],
user=url.username,
password=url.password,
host=url.hostname,
port=url.port
)
# cursor = conn.cursor()
# cursor.execute(sql.SQL("SELECT title, options FROM tribe_poll_data WHERE ts = %s"), [ts])
# poll_data = cursor.fetchall()
# title = poll_data[0][0]
# options = poll_data[0][1]
# cursor.execute(sql.SQL("SELECT real_name, response_num FROM tribe_poll_responses WHERE ts = %s"), [ts])
# poll_responses = cursor.fetchall()
# conn.commit()
# cursor.close()
# conn.close()
data = {}
for option in options:
data[option] = []
data['No Answer'] = []
for real_name, response_num in poll_responses:
if response_num != -1:
data[options[response_num]].append(real_name)
else:
data['No Answer'].append(real_name)
return title, data
except (Exception, psycopg2.DatabaseError) as error:
send_debug_message(error)
return None
def clear_poll_data():
try:
urllib.parse.uses_netloc.append("postgres")
url = urllib.parse.urlparse(os.environ["DATABASE_URL"])
conn = psycopg2.connect(
database=url.path[1:],
user=url.username,
password=url.password,
host=url.hostname,
port=url.port
)
# cursor = conn.cursor()
# cursor.execute(sql.SQL("DELETE FROM tribe_poll_responses"))
# cursor.execute(sql.SQL("DELETE FROM tribe_poll_data"))
# conn.commit()
# cursor.close()
# conn.close()
except (Exception, psycopg2.DatabaseError) as error:
send_debug_message(error)
def get_poll_unanswered(ts):
try:
urllib.parse.uses_netloc.append("postgres")
url = urllib.parse.urlparse(os.environ["DATABASE_URL"])
conn = psycopg2.connect(
database=url.path[1:],
user=url.username,
password=url.password,
host=url.hostname,
port=url.port
)
# cursor = conn.cursor()
# # get all of the people who's workout scores are greater than -1 (any non players have a workout score of -1)
# cursor.execute(sql.SQL("SELECT slack_id FROM tribe_poll_responses WHERE ts = %s and response_num = -1"), [ts])
# unanswered = cursor.fetchall()
# conn.commit()
# cursor.close()
# conn.close()
# print(unanswered)
# return unanswered
except (Exception, psycopg2.DatabaseError) as error:
send_debug_message(error)
return []
def get_poll_owner(ts):
try:
urllib.parse.uses_netloc.append("postgres")
url = urllib.parse.urlparse(os.environ["DATABASE_URL"])
conn = psycopg2.connect(
database=url.path[1:],
user=url.username,
password=url.password,
host=url.hostname,
port=url.port
)
# cursor = conn.cursor()
# # get all of the people who's workout scores are greater than -1 (any non players have a workout score of -1)
# cursor.execute(sql.SQL("SELECT slack_id FROM tribe_poll_data WHERE ts = %s"),
# [ts])
# owner = cursor.fetchall()
# conn.commit()
# cursor.close()
# conn.close()
# print(owner)
# return owner[0][0]
except (Exception, psycopg2.DatabaseError) as error:
send_debug_message(error)
return []
def delete_poll(timestamp):
try:
urllib.parse.uses_netloc.append("postgres")
url = urllib.parse.urlparse(os.environ["DATABASE_URL"])
conn = psycopg2.connect(
database=url.path[1:],
user=url.username,
password=url.password,
host=url.hostname,
port=url.port
)
# cursor = conn.cursor()
# cursor.execute(sql.SQL("DELETE FROM tribe_poll_data WHERE ts = %s"), [timestamp])
# cursor.execute(sql.SQL("DELETE FROM tribe_poll_responses WHERE ts = %s"), [timestamp])
# conn.commit()
# cursor.close()
# conn.close()
except (Exception, psycopg2.DatabaseError) as error:
send_debug_message(error)