Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosplanchon committed Nov 25, 2019
1 parent 965d4e3 commit 618b664
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand All @@ -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"
Expand Down
5 changes: 2 additions & 3 deletions telegramgetbotip/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from telegramgetbotip.telegramgetbotip import TelegramGetBotIp

from argparse import ArgumentParser
from pathlib import Path


def main():
Expand Down Expand Up @@ -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
)
13 changes: 7 additions & 6 deletions telegramgetbotip/telegramgetbotip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
):
Expand All @@ -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
Expand Down

0 comments on commit 618b664

Please sign in to comment.