members.py 622 B

123456789101112131415161718192021
  1. import os
  2. import json
  3. import requests
  4. def is_member(telegram_id):
  5. token = os.environ['API_TOKEN']
  6. # with open('printers/access-token', 'r', encoding='utf-8') as token_file:
  7. # token = token_file.read()
  8. url = 'https://physics.itmo.ru/ru/rest/export/json/users-telegram-id-roles'
  9. params = {'_format': 'json', 'telegram_id_value': telegram_id}
  10. headers = {'Authorization': f'Bearer {token}'}
  11. response = requests.get(url, params=params, headers=headers)
  12. resp = json.loads(response.text)
  13. if resp != [] and resp[0]['roles_target_id'] == 'member':
  14. return True
  15. return False