Solving circular dependency problem
This commit is contained in:
parent
c1eaa827fd
commit
6f584d1187
3 changed files with 40 additions and 37 deletions
|
|
@ -3,7 +3,7 @@ import os
|
||||||
import syslog
|
import syslog
|
||||||
import random
|
import random
|
||||||
import json
|
import json
|
||||||
from main import Connector
|
from connector import Connector
|
||||||
|
|
||||||
def init_streamobject(conn):
|
def init_streamobject(conn):
|
||||||
syslog.syslog(syslog.LOG_INFO, "Loading Stream object...")
|
syslog.syslog(syslog.LOG_INFO, "Loading Stream object...")
|
||||||
|
|
|
||||||
38
src/connector.py
Normal file
38
src/connector.py
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
import os
|
||||||
|
import syslog
|
||||||
|
import json
|
||||||
|
import redis
|
||||||
|
import tweepy
|
||||||
|
|
||||||
|
class Connector():
|
||||||
|
def __init__(self):
|
||||||
|
syslog.syslog(syslog.LOG_INFO, "Loading Consul connector...")
|
||||||
|
# TODO: Add token
|
||||||
|
self.dbconn = redis.Redis(
|
||||||
|
host=os.getenv("REDIS_HOST"),
|
||||||
|
port=os.getenv("REDIS_PORT"),
|
||||||
|
password=os.getenv("REDIS_CREDENTIALS")
|
||||||
|
)
|
||||||
|
|
||||||
|
self.api = Connector.init_api(self.dbconn)
|
||||||
|
|
||||||
|
def init_api(dbconn):
|
||||||
|
# Syslog report
|
||||||
|
syslog.syslog(syslog.LOG_INFO, "Loading Twitter API connector...")
|
||||||
|
|
||||||
|
return tweepy.Client(
|
||||||
|
bearer_token=dbconn.hget("api", "bearer").decode("utf-8"),
|
||||||
|
consumer_key=dbconn.hget("api", "consumer_key").decode("utf-8"),
|
||||||
|
consumer_secret=dbconn.hget("api", "consumer_secret").decode("utf-8"),
|
||||||
|
access_token=dbconn.hget("api", "access_token").decode("utf-8"),
|
||||||
|
access_token_secret=dbconn.hget("api","access_token_secret").decode("utf-8")
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_reply_bank(self):
|
||||||
|
return json.loads(self.dbconn.get('reply_bank').decode("utf-8"))
|
||||||
|
|
||||||
|
def get_victims(self):
|
||||||
|
return json.loads(self.dbconn.get('reply_bank').decode("utf-8")).victims
|
||||||
|
|
||||||
|
def get_bearer(self):
|
||||||
|
return self.dbconn.hget("api", "bearer").decode("utf-8")
|
||||||
37
src/main.py
37
src/main.py
|
|
@ -1,44 +1,9 @@
|
||||||
import tweepy
|
import tweepy
|
||||||
import os
|
import os
|
||||||
import syslog
|
import syslog
|
||||||
import json
|
|
||||||
import redis
|
|
||||||
from BotYamPoster import BotYamPoster
|
from BotYamPoster import BotYamPoster
|
||||||
from BotYamPoster import init_streamobject
|
from BotYamPoster import init_streamobject
|
||||||
|
from connector import Connector
|
||||||
|
|
||||||
class Connector():
|
|
||||||
def __init__(self):
|
|
||||||
syslog.syslog(syslog.LOG_INFO, "Loading Consul connector...")
|
|
||||||
# TODO: Add token
|
|
||||||
self.dbconn = redis.Redis(
|
|
||||||
host=os.getenv("REDIS_HOST"),
|
|
||||||
port=os.getenv("REDIS_PORT"),
|
|
||||||
password=os.getenv("REDIS_CREDENTIALS")
|
|
||||||
)
|
|
||||||
|
|
||||||
self.api = Connector.init_api(self.dbconn)
|
|
||||||
|
|
||||||
def init_api(dbconn):
|
|
||||||
# Syslog report
|
|
||||||
syslog.syslog(syslog.LOG_INFO, "Loading Twitter API connector...")
|
|
||||||
|
|
||||||
return tweepy.Client(
|
|
||||||
bearer_token=dbconn.hget("api", "bearer").decode("utf-8"),
|
|
||||||
consumer_key=dbconn.hget("api", "consumer_key").decode("utf-8"),
|
|
||||||
consumer_secret=dbconn.hget("api", "consumer_secret").decode("utf-8"),
|
|
||||||
access_token=dbconn.hget("api", "access_token").decode("utf-8"),
|
|
||||||
access_token_secret=dbconn.hget("api","access_token_secret").decode("utf-8")
|
|
||||||
)
|
|
||||||
|
|
||||||
def get_reply_bank(self):
|
|
||||||
return json.loads(self.dbconn.get('reply_bank').decode("utf-8"))
|
|
||||||
|
|
||||||
def get_victims(self):
|
|
||||||
return json.loads(self.dbconn.get('reply_bank').decode("utf-8")).victims
|
|
||||||
|
|
||||||
def get_bearer(self):
|
|
||||||
return self.dbconn.hget("api", "bearer").decode("utf-8")
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
syslog.syslog(syslog.LOG_INFO, "BOT-YAM - VERSION 2.1.2 >>>>")
|
syslog.syslog(syslog.LOG_INFO, "BOT-YAM - VERSION 2.1.2 >>>>")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue