-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtelegram-logger
More file actions
28 lines (23 loc) · 973 Bytes
/
telegram-logger
File metadata and controls
28 lines (23 loc) · 973 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env python3
import telegram
from telegramlogger import default_token_path
from pathlib import Path
import argparse
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Send Telegram messages.')
parser.add_argument('--tokenfile', '-t', nargs=1, default=default_token_path,
help=f'file containing the telegram token (default: {default_token_path})')
parser.add_argument('--get-updates', '-u', action='store_true',
help='get messages recently sent to the bot')
args = parser.parse_args()
bot = None
with open(args.tokenfile, 'r') as f:
token = f.read().strip()
bot = telegram.Bot(token=token)
if args.get_updates:
updates = bot.get_updates()
for update in updates:
msg = update.message
print(f'{msg.chat.last_name}, {msg.chat.first_name} ({msg.chat_id}): "{msg.text}"')
else:
parser.print_help()