-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
72 lines (60 loc) · 2.19 KB
/
config.py
File metadata and controls
72 lines (60 loc) · 2.19 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# -*- coding: utf-8 -*-
import tweepy
import logging
import os
import sys
import psycopg2
logger = logging.getLogger()
class BotHelper:
def __init__(self):
self.conn = psycopg2.connect(user = "USER",
password = "PASSWORD",
host = "HOST",
port = "PORT",
database = "DB")
self.cursor = self.conn.cursor()
self.consumer_key = os.getenv("CONSUMER_KEY")
self.consumer_secret = os.getenv("CONSUMER_SECRET")
self.access_token = os.getenv("ACCESS_TOKEN")
self.access_token_secret = os.getenv("ACCESS_TOKEN_SECRET")
self.winner = False
self.alive_players = 0
def version(self):
self.cursor.execute("SELECT version();")
record = self.cursor.fetchone()
print("You are connected to - ", record,"\n")
def close(self):
if(self.conn):
self.cursor.close()
self.conn.close()
def query_all(self, query):
try:
self.cursor.execute(query)
db_result = self.cursor.fetchall()
return db_result
except (Exception, psycopg2.Error) as error :
print ("Error while connecting to PostgreSQL", error)
self.close()
sys.exit(1)
def create_api(self):
# Auth to twittter api
auth = tweepy.OAuthHandler(self.consumer_key, self.consumer_secret)
auth.set_access_token(self.access_token, self.access_token_secret)
# Create api object
api = tweepy.API(auth, wait_on_rate_limit=True,
wait_on_rate_limit_notify=True)
# Verify keys are correct
try:
api.verify_credentials()
except Exception as e:
logger.error("Error creating API", exc_info=True)
raise e
logger.info("API created")
return api
def strike_text(self, text):
result = ''
for c in text:
result = result + '\u0336' + c
return result
if __name__ == "__main__":
pass