members.py 565 B

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