-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
56 lines (47 loc) · 1.24 KB
/
config.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
import requests
import json
from datetime import datetime
import pytz
import sys
import os
import mysql.connector
mysql_user = os.getenv("MYSQL_USER")
mysql_pwd = os.getenv("MYSQL_PWD")
class Connect():
def __enter__(self):
cnx = mysql.connector.connect(
host="codeforcer-db.cxjbhuumzbdw.ap-southeast-1.rds.amazonaws.com",
port=3306,
user=f"{mysql_user}",
password=f"{mysql_pwd}",
database="codeforcer"
)
self.cnx = cnx
return cnx
def __exit__(self, type, value, traceback):
self.cnx.close()
logo = "https://bit.ly/cf-logo-dis"
emo = {
'tick':"\U00002705",
'x':"\U0000274E",
'pistol':'\N{PISTOL}',
'ok':'\N{OK HAND SIGN}',
'cry':"\U0001F622"
}
def fetch(url):
global c,e
log_time = datetime.now(pytz.timezone('Asia/Singapore'))
response = requests.get(url)
try:
if response.status_code == 200:
c = response.content
c = json.loads(c)
e = False
else:
print(f"{log_time} CF API req returned {response.status_code}")
except:
e = True
print(f"{log_time} Errors encountered")
print(sys.exc_info()[0])
pass
return c,e