-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
87 lines (73 loc) · 2.32 KB
/
models.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
#first attempts using classes
import os
import requests
from users import insert_user
from bot_functions import (PrintException, getCon)
ACCESS_TOKEN = os.environ['ACCESS_TOKEN']
class Sender:
def __init__(self, recipient_id):
self.psid = recipient_id
try:
# URL = "".join(["https://graph.facebook.com/v2.6/", recipient_id, "?fields=first_name,last_name,profile_pic&access_token=", ACCESS_TOKEN])
URL = "".join(["https://graph.facebook.com/v12.0/", recipient_id, "?fields=first_name,last_name,profile_pic&access_token=", ACCESS_TOKEN])
r = requests.get(url = URL)
data = r.json()
print("recipient_id: " + str(recipient_id))
self.first_name = data['first_name']
self.last_name = data['last_name']
self.full_name = " ".join([data['first_name'],data['last_name']])
self.profile_pic = data['profile_pic']
except:
PrintException()
print("DATA RETURNED BY FB: " + str(data))
self.first_name = None
self.last_name = None
self.full_name = None
self.profile_pic = None
def get_firstname(self):
return self.first_name
def get_lastname(self):
return self.last_name
def get_fullname(self):
return self.full_name
def get_profile_pic(self):
return self.profile_pic
def adduser(self, con):
insert_user(self.full_name, self.first_name, self.last_name, self.psid, con)
class GlobalVar:
def __init__(self, name):
self.name = name
def insert(self, columns):
try:
self.columns = "(" + (", ".join(columns)) + ")"
self.values = tuple(columns.values())
con = getCon()
cur = con.cursor()
print('''INSERT INTO %s %s VALUES %s''' % (self.name, self.columns, self.values))
con.commit()
con.close()
except:
PrintException()
def update(self, columns):
try:
self.columns = r" = '%s', ".join(columns) + r" = '%s'" #quotes around %s as these will ensure postgresql recieves them as strings and not columns
self.values = tuple(columns.values())
con = getCon()
cur = con.cursor()
cur.execute('''UPDATE %s SET %s''' % (self.name, self.columns % self.values))
con.commit()
con.close()
return f"{self.name} updated successfully."
except:
PrintException()
def get(self):
try:
con = getCon()
cur = con.cursor()
cur.execute(f'''SELECT * FROM {self.name}''')
row = cur.fetchone()
con.close()
print(row)
return row
except:
PrintException()