Helper module deprecated (use davtelepot.helper instead), typos and minor refactoring
This commit is contained in:
parent
790565297e
commit
9d2f9b06dc
@ -3,7 +3,7 @@
|
|||||||
__author__ = "Davide Testa"
|
__author__ = "Davide Testa"
|
||||||
__email__ = "davide@davte.it"
|
__email__ = "davide@davte.it"
|
||||||
__license__ = "GNU General Public License v3.0"
|
__license__ = "GNU General Public License v3.0"
|
||||||
__version__ = "1.1.16"
|
__version__ = "1.1.17"
|
||||||
__maintainer__ = "Davide Testa"
|
__maintainer__ = "Davide Testa"
|
||||||
__contact__ = "t.me/davte"
|
__contact__ = "t.me/davte"
|
||||||
|
|
||||||
|
@ -15,7 +15,8 @@ from .messages import (
|
|||||||
default_help_messages, language_messages, supported_languages
|
default_help_messages, language_messages, supported_languages
|
||||||
)
|
)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
|
def main():
|
||||||
path = os.path.dirname(
|
path = os.path.dirname(
|
||||||
os.path.abspath(
|
os.path.abspath(
|
||||||
__file__
|
__file__
|
||||||
@ -43,6 +44,7 @@ if __name__ == '__main__':
|
|||||||
# Outputs the log in console, log_file and errors_file
|
# Outputs the log in console, log_file and errors_file
|
||||||
# Log formatter: datetime, module name (filled with spaces up to 15
|
# Log formatter: datetime, module name (filled with spaces up to 15
|
||||||
# characters), logging level name (filled to 8), message
|
# characters), logging level name (filled to 8), message
|
||||||
|
# noinspection SpellCheckingInspection
|
||||||
log_formatter = logging.Formatter(
|
log_formatter = logging.Formatter(
|
||||||
"%(asctime)s [%(module)-15s %(levelname)-8s] %(message)s",
|
"%(asctime)s [%(module)-15s %(levelname)-8s] %(message)s",
|
||||||
style='%'
|
style='%'
|
||||||
@ -60,10 +62,10 @@ if __name__ == '__main__':
|
|||||||
file_handler.setLevel(logging.ERROR)
|
file_handler.setLevel(logging.ERROR)
|
||||||
root_logger.addHandler(file_handler)
|
root_logger.addHandler(file_handler)
|
||||||
|
|
||||||
consoleHandler = logging.StreamHandler()
|
console_handler = logging.StreamHandler()
|
||||||
consoleHandler.setFormatter(log_formatter)
|
console_handler.setFormatter(log_formatter)
|
||||||
consoleHandler.setLevel(logging.DEBUG)
|
console_handler.setLevel(logging.DEBUG)
|
||||||
root_logger.addHandler(consoleHandler)
|
root_logger.addHandler(console_handler)
|
||||||
|
|
||||||
# Instantiate bot
|
# Instantiate bot
|
||||||
bot = davtelepot.bot.Bot(token=bot_token,
|
bot = davtelepot.bot.Bot(token=bot_token,
|
||||||
@ -78,8 +80,7 @@ if __name__ == '__main__':
|
|||||||
bot.set_authorization_denied_message(
|
bot.set_authorization_denied_message(
|
||||||
messages.authorization_denied_message
|
messages.authorization_denied_message
|
||||||
)
|
)
|
||||||
with bot.db as db:
|
bot.db['users'].upsert(
|
||||||
db['users'].upsert(
|
|
||||||
dict(
|
dict(
|
||||||
telegram_id=63538990,
|
telegram_id=63538990,
|
||||||
privileges=1
|
privileges=1
|
||||||
@ -101,4 +102,8 @@ if __name__ == '__main__':
|
|||||||
local_host=local_host,
|
local_host=local_host,
|
||||||
port=port
|
port=port
|
||||||
)
|
)
|
||||||
sys.exit(exit_state)
|
return exit_state
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.exit(main())
|
||||||
|
@ -21,7 +21,7 @@ default_location = None
|
|||||||
|
|
||||||
_URL = "http://www.ciclopi.eu/frmLeStazioni.aspx"
|
_URL = "http://www.ciclopi.eu/frmLeStazioni.aspx"
|
||||||
|
|
||||||
ciclopi_webpage = CachedPage.get(
|
ciclopi_web_page = CachedPage.get(
|
||||||
_URL,
|
_URL,
|
||||||
datetime.timedelta(seconds=15),
|
datetime.timedelta(seconds=15),
|
||||||
mode='html'
|
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,
|
async def _ciclopi_command(bot: davtelepot.bot.Bot, update, user_record, sent_message=None,
|
||||||
show_all=False):
|
show_all=False):
|
||||||
return {
|
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):
|
if ciclopi_data is None or isinstance(ciclopi_data, Exception):
|
||||||
text = bot.get_message(
|
text = bot.get_message(
|
||||||
'ciclopi', 'command', 'unavailable_website',
|
'ciclopi', 'command', 'unavailable_website',
|
||||||
|
@ -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,
|
|
||||||
)
|
|
Loading…
x
Reference in New Issue
Block a user