Skip to content

Commit

Permalink
moved files to python package
Browse files Browse the repository at this point in the history
  • Loading branch information
markusressel committed May 21, 2019
1 parent b523176 commit c0b5dc3
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 13 deletions.
3 changes: 3 additions & 0 deletions infinitewisdom.yaml
Expand Up @@ -6,6 +6,9 @@ InfiniteWisdom:
image_polling_timeout: 1
inline_badge_size: 16
bot_token: "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11"
persistence:
type: "local"
path: "/tmp"
image_analysis:
type: "tesseract"
auth_file: "./my-auth-file.json"
Expand Down
Empty file added infinitewisdom/__init__.py
Empty file.
File renamed without changes.
15 changes: 9 additions & 6 deletions bot.py → infinitewisdom/bot.py
Expand Up @@ -23,11 +23,12 @@
from telegram import InlineQueryResultPhoto, ChatAction, Bot, Update
from telegram.ext import CommandHandler, Filters, InlineQueryHandler, MessageHandler, Updater

from analysis import GoogleVision, Tesseract
from config import Config
from const import IMAGE_ANALYSIS_TYPE_TESSERACT, IMAGE_ANALYSIS_TYPE_GOOGLE_VISION
from persistence import LocalPersistence
from stats import INSPIRE_TIME, INLINE_TIME, START_TIME
from infinitewisdom.analysis import GoogleVision, Tesseract
from infinitewisdom.config import Config
from infinitewisdom.const import IMAGE_ANALYSIS_TYPE_TESSERACT, IMAGE_ANALYSIS_TYPE_GOOGLE_VISION, \
PERSISTENCE_TYPE_LOCAL
from infinitewisdom.persistence import LocalPersistence
from infinitewisdom.stats import INSPIRE_TIME, INLINE_TIME, START_TIME

logging.basicConfig(level=logging.WARNING, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
LOGGER = logging.getLogger(__name__)
Expand All @@ -41,7 +42,9 @@ class InfiniteWisdomBot:

def __init__(self):
self._config = Config()
self._persistence = LocalPersistence()

if self._config.PERSISTENCE_TYPE == PERSISTENCE_TYPE_LOCAL:
self._persistence = LocalPersistence()

if self._config.IMAGE_ANALYSIS_TYPE.value == IMAGE_ANALYSIS_TYPE_TESSERACT:
self._image_analyser = Tesseract()
Expand Down
24 changes: 21 additions & 3 deletions config.py → infinitewisdom/config.py
Expand Up @@ -19,7 +19,9 @@

import yaml

from const import ALLOWED_CONFIG_FILE_PATHS, ALLOWED_CONFIG_FILE_EXTENSIONS, CONFIG_FILE_NAME, CONFIG_NODE_ROOT
from infinitewisdom.const import ALLOWED_CONFIG_FILE_PATHS, ALLOWED_CONFIG_FILE_EXTENSIONS, CONFIG_FILE_NAME, \
CONFIG_NODE_ROOT, \
CONFIG_NODE_IMAGE_ANALYSIS, CONFIG_NODE_PERSISTENCE, DEFAULT_LOCAL_PERSISTENCE_FOLDER_PATH, PERSISTENCE_TYPE_LOCAL


class ConfigEntry:
Expand Down Expand Up @@ -74,18 +76,34 @@ class Config:
],
default='Send /inspire for more inspiration :) Or use @InfiniteWisdomBot in a group chat and select one of the suggestions.')

PERSISTENCE_TYPE = ConfigEntry(
yaml_path=[
CONFIG_NODE_ROOT,
CONFIG_NODE_PERSISTENCE,
"type"
],
default=PERSISTENCE_TYPE_LOCAL)

LOCAL_PERSISTENCE_FOLDER_PATH = ConfigEntry(
yaml_path=[
CONFIG_NODE_ROOT,
CONFIG_NODE_PERSISTENCE,
"path"
],
default=DEFAULT_LOCAL_PERSISTENCE_FOLDER_PATH)

IMAGE_ANALYSIS_TYPE = ConfigEntry(
yaml_path=[
CONFIG_NODE_ROOT,
"image_analysis",
CONFIG_NODE_IMAGE_ANALYSIS,
"type"
],
default=None)

IMAGE_ANALYSIS_GOOGLE_VISION_AUTH_FILE = ConfigEntry(
yaml_path=[
CONFIG_NODE_ROOT,
"image_analysis",
CONFIG_NODE_IMAGE_ANALYSIS,
"auth_file"
],
default=None)
Expand Down
4 changes: 4 additions & 0 deletions const.py → infinitewisdom/const.py
Expand Up @@ -38,4 +38,8 @@
IMAGE_ANALYSIS_TYPE_TESSERACT = "tesseract"
IMAGE_ANALYSIS_TYPE_GOOGLE_VISION = "google-vision"

PERSISTENCE_TYPE_LOCAL = "local"

CONFIG_NODE_ROOT = "InfiniteWisdom"
CONFIG_NODE_PERSISTENCE = "persistence"
CONFIG_NODE_IMAGE_ANALYSIS = "image_analysis"
4 changes: 2 additions & 2 deletions persistence.py → infinitewisdom/persistence.py
Expand Up @@ -19,8 +19,8 @@
import pickle
import random

from const import DEFAULT_LOCAL_PERSISTENCE_FOLDER_PATH
from stats import POOL_SIZE
from infinitewisdom.const import DEFAULT_LOCAL_PERSISTENCE_FOLDER_PATH
from infinitewisdom.stats import POOL_SIZE

LOGGER = logging.getLogger(__name__)

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions tests/image_api_test.py
Expand Up @@ -18,7 +18,7 @@
import unittest
from unittest import mock

from const import ENV_PARAM_BOT_TOKEN
from infinitewisdom.const import ENV_PARAM_BOT_TOKEN


class ImageApiTests(unittest.TestCase):
Expand All @@ -30,6 +30,6 @@ class ImageApiTests(unittest.TestCase):
ENV_PARAM_BOT_TOKEN: "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11"
})
def test_retrieve_new_image(self):
from bot import InfiniteWisdomBot
from infinitewisdom.bot import InfiniteWisdomBot
url = InfiniteWisdomBot._fetch_generated_image_url()
self.assertRegex(url, r'https://generated\.inspirobot\.me/\w/\w+\.jpg')

0 comments on commit c0b5dc3

Please sign in to comment.