Queer European MD passionate about IT
소스 검색

Helper module deprecated (use davtelepot.helper instead), typos and minor refactoring

Davte 4 년 전
부모
커밋
948325cb42
4개의 변경된 파일24개의 추가작업 그리고 36개의 파일을 삭제
  1. 1 1
      ciclopibot/__init__.py
  2. 19 14
      ciclopibot/bot.py
  3. 4 2
      ciclopibot/ciclopi.py
  4. 0 19
      ciclopibot/helper.py

+ 1 - 1
ciclopibot/__init__.py

@@ -3,7 +3,7 @@
 __author__ = "Davide Testa"
 __email__ = "davide@davte.it"
 __license__ = "GNU General Public License v3.0"
-__version__ = "1.1.16"
+__version__ = "1.1.17"
 __maintainer__ = "Davide Testa"
 __contact__ = "t.me/davte"
 

+ 19 - 14
ciclopibot/bot.py

@@ -15,7 +15,8 @@ from .messages import (
     default_help_messages, language_messages, supported_languages
 )
 
-if __name__ == '__main__':
+
+def main():
     path = os.path.dirname(
         os.path.abspath(
             __file__
@@ -43,6 +44,7 @@ if __name__ == '__main__':
     # Outputs the log in console, log_file and errors_file
     # Log formatter: datetime, module name (filled with spaces up to 15
     # characters), logging level name (filled to 8), message
+    # noinspection SpellCheckingInspection
     log_formatter = logging.Formatter(
         "%(asctime)s [%(module)-15s %(levelname)-8s]     %(message)s",
         style='%'
@@ -60,10 +62,10 @@ if __name__ == '__main__':
     file_handler.setLevel(logging.ERROR)
     root_logger.addHandler(file_handler)
 
-    consoleHandler = logging.StreamHandler()
-    consoleHandler.setFormatter(log_formatter)
-    consoleHandler.setLevel(logging.DEBUG)
-    root_logger.addHandler(consoleHandler)
+    console_handler = logging.StreamHandler()
+    console_handler.setFormatter(log_formatter)
+    console_handler.setLevel(logging.DEBUG)
+    root_logger.addHandler(console_handler)
 
     # Instantiate bot
     bot = davtelepot.bot.Bot(token=bot_token,
@@ -78,14 +80,13 @@ if __name__ == '__main__':
     bot.set_authorization_denied_message(
         messages.authorization_denied_message
     )
-    with bot.db as db:
-        db['users'].upsert(
-            dict(
-                telegram_id=63538990,
-                privileges=1
-            ),
-            ['telegram_id']
-        )
+    bot.db['users'].upsert(
+        dict(
+            telegram_id=63538990,
+            privileges=1
+        ),
+        ['telegram_id']
+    )
     davtelepot.administration_tools.init(bot)
     ciclopi.init(bot)
     davtelepot.authorization.init(bot)
@@ -101,4 +102,8 @@ if __name__ == '__main__':
         local_host=local_host,
         port=port
     )
-    sys.exit(exit_state)
+    return exit_state
+
+
+if __name__ == '__main__':
+    sys.exit(main())

+ 4 - 2
ciclopibot/ciclopi.py

@@ -21,7 +21,7 @@ default_location = None
 
 _URL = "http://www.ciclopi.eu/frmLeStazioni.aspx"
 
-ciclopi_webpage = CachedPage.get(
+ciclopi_web_page = CachedPage.get(
     _URL,
     datetime.timedelta(seconds=15),
     mode='html'
@@ -569,6 +569,8 @@ async def cancel_ciclopi_location(bot, update, user_record):
     )
 
 
+# The service is currently suspended: code is unreachable of course
+# noinspection PyUnreachableCode,PyUnusedLocal
 async def _ciclopi_command(bot: davtelepot.bot.Bot, update, user_record, sent_message=None,
                            show_all=False):
     return {
@@ -593,7 +595,7 @@ async def _ciclopi_command(bot: davtelepot.bot.Bot, update, user_record, sent_me
         #     )
         # )
     )
-    ciclopi_data = await ciclopi_webpage.get_page()
+    ciclopi_data = await ciclopi_web_page.get_page()
     if ciclopi_data is None or isinstance(ciclopi_data, Exception):
         text = bot.get_message(
             'ciclopi', 'command', 'unavailable_website',

+ 0 - 19
ciclopibot/helper.py

@@ -1,19 +0,0 @@
-"""Make a self-consistent bot help section."""
-
-# Third party modules
-import davtelepot.helper
-from davtelepot.utilities import json_read
-
-# Project modules
-from .messages import default_help_messages
-
-
-def init(bot, help_messages=None,
-         help_buttons=[]):
-    """Assign parsers, commands, buttons and queries to given `bot`."""
-    if help_messages is None:
-        help_messages = default_help_messages
-    davtelepot.helper.init(
-        bot=bot,
-        help_messages=help_messages,
-    )