diff --git a/README.md b/README.md index a1332fb..95cd989 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,15 @@ optional arguments: -d DELTA, --delta DELTA Time between queries. ``` -The Bot Token file must contain the bot ID in plain text. -The ids's file must contain an ID in each line of the document (separated by "\n") +The Bot Token file must contain the bot ID in JSON format. +{ + "token": "token_string" (str) +} + +The ids's file must contain the IDs in JSON format. +{ + "name": id (int) +} You can get your Telegram ID from @userinfobot You can register your Telegram Bot from @BotFather diff --git a/setup.py b/setup.py index 6a40508..1e262e4 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ "telegramgetbotip = telegramgetbotip.__main__:main" ] }, - version="0.1.3", + version="0.1.4", license="GPL3", description="Python3 telegram bot to retrieve public IP " "of the Telegram bot's host machine.", @@ -24,7 +24,7 @@ author_email="bubbledoloresuruguay2@gmail.com", url="https://github.com/carlosplanchon/telegramgetbotip", download_url="https://github.com/carlosplanchon/" - "telegramgetbotip/archive/v0.1.3.tar.gz", + "telegramgetbotip/archive/v0.1.4.tar.gz", keywords=["telegram", "bot", "ip", "networking"], install_requires=[ "telepot" diff --git a/telegramgetbotip/__main__.py b/telegramgetbotip/__main__.py index 819b783..208a137 100644 --- a/telegramgetbotip/__main__.py +++ b/telegramgetbotip/__main__.py @@ -3,7 +3,6 @@ from telegramgetbotip.telegramgetbotip import TelegramGetBotIp from argparse import ArgumentParser -from pathlib import Path def main(): @@ -44,8 +43,8 @@ def main(): bot = TelegramGetBotIp() if args.tokenfile and args.idsfile: bot.start_bot( - bot_token_file=Path(args.tokenfile), - allowed_telegram_ids_file=Path(args.idsfile), + bot_token_file=args.tokenfile, + allowed_telegram_ids_file=args.idsfile, time_between_queries=args.delta, verbose=args.verbose ) diff --git a/telegramgetbotip/telegramgetbotip.py b/telegramgetbotip/telegramgetbotip.py index 98a48c1..7a21a2a 100644 --- a/telegramgetbotip/telegramgetbotip.py +++ b/telegramgetbotip/telegramgetbotip.py @@ -5,7 +5,7 @@ from requests import get from telepot import Bot -from pathlib import Path +from json import load from pprint import pprint from time import sleep, time @@ -69,8 +69,8 @@ def message_handler(self, msg: Dict[Any, Any]) -> None: def start_bot( self, - bot_token_file: Path, - allowed_telegram_ids_file: Path, + bot_token_file, + allowed_telegram_ids_file, time_between_queries: int = -1, verbose: bool = False ): @@ -84,9 +84,10 @@ def start_bot( :param verbose: bool: Verbosity. (Default value = False) """ - self.bot_token = Path(bot_token_file).read_text() - self.allowed_telegram_ids = [int(i) for i in Path( - allowed_telegram_ids_file).read_text().split("\n") if i.isnumeric()] + with open(bot_token_file, "r") as f: + self.bot_token = list(load(f).values())[0] + with open(allowed_telegram_ids_file, "r") as f: + self.allowed_telegram_ids = load(f).values() self.time_between_queries = time_between_queries self.verbose = verbose