Bladeren bron

Added user verification

foreverpositive 2 jaren geleden
bovenliggende
commit
fae63704a4
1 gewijzigde bestanden met toevoegingen van 20 en 0 verwijderingen
  1. 20 0
      printers/members.py

+ 20 - 0
printers/members.py

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