Initial implementation of Avan fact bot

This commit is contained in:
2020-04-29 20:48:25 -04:00
parent b7bba2d263
commit 0a35519a72
5 changed files with 52 additions and 10 deletions

View File

@@ -1,8 +1,16 @@
from app import fact_service, groupme from app import fact_service, groupme
from util import constants
if __name__ == '__main__': if __name__ == '__main__':
# Get Groupme api token to post with # Get Groupme api token to post with
groupme_client = groupme.get_client() groupme_client = groupme.get_client()
# Get specific group from groupme
fact_bot = groupme.get_bot(constants.BOT_NAME)
# Get Random Fact # Get Random Fact
fact = fact_service.get_random_fact() fact = fact_service.get_random_fact()
# Post fact in Group
# groupme_client.
message = fact_bot.post(text=fact)

View File

@@ -1,4 +1,15 @@
from model.text_db import TextDb
def get_random_fact(): def get_random_fact():
ret_fact = None ret_fact = None
db_service = TextDb()
ret_fact = db_service.get_fact()
return ret_fact
def get_multiple_random_facts():
ret_fact = None
db_service = TextDb()
ret_fact = db_service.get_multiple_facts()
return ret_fact return ret_fact

View File

@@ -1,8 +1,13 @@
from groupy import Client from groupy import Client
from util import api_keys from util import constants
GROUPME_CLIENT = None GROUPME_CLIENT: Client = None
def init_client():
global GROUPME_CLIENT
GROUPME_CLIENT = Client.from_token(constants.GROUPME)
def get_client(): def get_client():
@@ -11,8 +16,25 @@ def get_client():
return GROUPME_CLIENT return GROUPME_CLIENT
def init_client(): def get_group(group_name):
global GROUPME_CLIENT found_group = Exception("Input group not found")
GROUPME_CLIENT = Client.from_token(api_keys.GROUPME) if GROUPME_CLIENT is None:
if not list(GROUPME_CLIENT.groups.list_all()): init_client()
raise Exception("Invalid groupme token or not apart of any groups.") group_list = GROUPME_CLIENT.groups.list(per_page=50)
for ret_group in group_list:
if group_name.casefold() == ret_group.name.casefold():
found_group = ret_group
break
return found_group
def get_bot(bot_name):
found_bot = Exception("Input bot not found")
if GROUPME_CLIENT is None:
init_client()
bot_list = GROUPME_CLIENT.bots.list()
for ret_bot in bot_list:
if bot_name.casefold() == ret_bot.name.casefold():
found_bot = ret_bot
break
return found_bot

View File

@@ -8,8 +8,8 @@ class DbService:
@abstractmethod @abstractmethod
def get_fact(self): def get_fact(self):
pass raise NotImplementedError
@abstractmethod @abstractmethod
def get_multiple_facts(self, count=5): def get_multiple_facts(self, count=5):
pass raise NotImplementedError

View File

@@ -1,3 +1,4 @@
import os import os
BOT_NAME = os.environ.get("BOT_NAME")
GROUPME = os.environ.get("GROUPME_KEY") GROUPME = os.environ.get("GROUPME_KEY")