Add rest of project files

This commit is contained in:
2020-04-29 12:38:41 -04:00
parent 3b01915ec6
commit 052490c0fc
20 changed files with 158 additions and 0 deletions

8
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

1
.idea/.name generated Normal file
View File

@@ -0,0 +1 @@
groupme-facts-bot

13
.idea/groupme-facts-bot.iml generated Normal file
View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="pytest" />
</component>
</module>

View File

@@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

7
.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (avan-facts)" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/groupme-facts-bot.iml" filepath="$PROJECT_DIR$/.idea/groupme-facts-bot.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

0
app/__init__.py Normal file
View File

8
app/fact_bot.py Normal file
View File

@@ -0,0 +1,8 @@
from app import fact_service, groupme
if __name__ == '__main__':
# Get Groupme api token to post with
groupme_client = groupme.get_client()
# Get Random Fact
fact = fact_service.get_random_fact()

4
app/fact_service.py Normal file
View File

@@ -0,0 +1,4 @@
def get_random_fact():
ret_fact = None
return ret_fact

18
app/groupme.py Normal file
View File

@@ -0,0 +1,18 @@
from groupy import Client
from util import api_keys
GROUPME_CLIENT = None
def get_client():
if GROUPME_CLIENT is None:
init_client()
return GROUPME_CLIENT
def init_client():
global GROUPME_CLIENT
GROUPME_CLIENT = Client.from_token(api_keys.GROUPME)
if not list(GROUPME_CLIENT.groups.list_all()):
raise Exception("Invalid groupme token or not apart of any groups.")

3
model/__init__.py Normal file
View File

@@ -0,0 +1,3 @@
from model import db_service
from model import text_db

15
model/db_service.py Normal file
View File

@@ -0,0 +1,15 @@
from abc import abstractmethod
class DbService:
def __init__(self) -> None:
super().__init__()
@abstractmethod
def get_fact(self):
pass
@abstractmethod
def get_multiple_facts(self, count=5):
pass

26
model/text_db.py Normal file
View File

@@ -0,0 +1,26 @@
import random
from model.db_service import DbService
from util import common
class TextDb(DbService):
def __init__(self) -> None:
super().__init__()
self.FACTS_LIST = None
def load_facts_from_file(self):
facts_file = open(f"{common.get_project_root()}/resources/facts.txt", mode="r+")
self.FACTS_LIST = facts_file.readlines()
assert self.FACTS_LIST
def get_fact(self):
if self.FACTS_LIST is None:
self.load_facts_from_file()
return random.choice(self.FACTS_LIST)
def get_multiple_facts(self, count=5):
if self.FACTS_LIST is None:
self.load_facts_from_file()
return random.sample(self.FACTS_LIST, k=count)

View File

@@ -0,0 +1,11 @@
Charles Darwin's personal pet tortoise didn't die until recently.
The average person will spend six months of their life waiting for red lights to turn green.
A bolt of lightning contains enough energy to toast 100,000 slices of bread.
President Lyndon B. Johnson owned a water-surfing car.
Cherophobia is the word for the irrational fear of being happy.
You can hear a blue whale's heartbeat from two miles away.
Nearly 30,000 rubber ducks were lost a sea in 1992 and are still being discovered today.
There's a Manhattan-specific ant.
The inventor of the frisbee was turned into a frisbee after he died.
There's a bridge exclusively for squirrels.
Subway footlongs aren't always a foot long.

0
tests/__init__.py Normal file
View File

15
tests/test_text_db.py Normal file
View File

@@ -0,0 +1,15 @@
from model.text_db import TextDb
class TestTestDb:
def test_get_fact(self):
text_db_service = TextDb()
random_fact = text_db_service.get_fact()
assert random_fact is not None
assert random_fact != ""
def test_get_multiple_facts(self):
text_db_service = TextDb()
random_facts_list = text_db_service.get_multiple_facts()
assert random_facts_list is not None
assert len(random_facts_list) > 0

0
util/__init__.py Normal file
View File

3
util/api_keys.py Normal file
View File

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

6
util/common.py Normal file
View File

@@ -0,0 +1,6 @@
from pathlib import Path
def get_project_root() -> Path:
"""Returns project root folder."""
return Path(__file__).parent.parent