No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

seeIdGroups.py 1018B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. import telegram
  4. import configparser
  5. from telegram.error import NetworkError, Unauthorized
  6. from time import sleep
  7. from sys import argv
  8. config = []
  9. parser = configparser.SafeConfigParser()
  10. if len(argv) == 2:
  11. parser.read(argv[1])
  12. else:
  13. parser.read('config.ini')
  14. for name, value in parser.items('config'):
  15. config.append(value)
  16. bot = telegram.Bot(config[4])
  17. update_id = 0
  18. print('It can take a while to print the ID, please wait.')
  19. print("Press Ctrl-c when the ID you want is printed.")
  20. printed = []
  21. while True:
  22. try:
  23. for update in bot.getUpdates(offset=update_id, timeout=10):
  24. chat_id = update.message.chat_id
  25. chat_title = update.message
  26. if chat_id not in printed:
  27. printed.append(chat_id)
  28. print("Title: " + str(chat_title['chat']['title']))
  29. print("ID: " + str(chat_id))
  30. except NetworkError:
  31. sleep(1)
  32. except Unauthorized:
  33. update_id += 1