LilRg commited on
Commit
3c0cc99
·
verified ·
1 Parent(s): 1727bbe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -2
app.py CHANGED
@@ -17,7 +17,7 @@ YOUR_APP_NAME = "MonChatbot"
17
 
18
  # ID de l'étudiant
19
  #student_id = 34
20
- url = "https://huggingface.co/spaces/LilRg/AlbatrossV1Chatbot/?id={LOGGED_IN_USER:ID}"
21
 
22
  # Parse l'URL
23
  parsed_url = urlparse(url)
@@ -26,7 +26,41 @@ parsed_url = urlparse(url)
26
  query_params = parse_qs(parsed_url.query)
27
 
28
  # Récupérer l'ID
29
- student_id = query_params.get('id', [None])[0]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
  def get_user_info_by_id(student_id):
32
  url = f"https://api.airtable.com/v0/{AIRTABLE_BASE_ID}/Inscription_Etudiants"
 
17
 
18
  # ID de l'étudiant
19
  #student_id = 34
20
+ url = "https://huggingface.co/spaces/LilRg/ModificationCompetences?name={LOGGED_IN_USER:NAME}"
21
 
22
  # Parse l'URL
23
  parsed_url = urlparse(url)
 
26
  query_params = parse_qs(parsed_url.query)
27
 
28
  # Récupérer l'ID
29
+ student_name = query_params.get('name', [None])[0]
30
+
31
+ def get_id_by_name(student_name):
32
+ url = f"https://api.airtable.com/v0/{AIRTABLE_BASE_ID}/Inscription_Etudiants"
33
+ headers = {
34
+ "Authorization": f"Bearer {AIRTABLE_API_KEY}",
35
+ "Content-Type": "application/json"
36
+ }
37
+
38
+ # Filtrer les enregistrements par ID_Etu
39
+ params = {
40
+ "filterByFormula": f"{{Nom}} = '{student_name}'"
41
+ }
42
+
43
+ try:
44
+ response = requests.get(url, headers=headers, params=params)
45
+
46
+ if response.status_code == 200:
47
+ data = response.json()
48
+
49
+ if len(data['records']) > 0:
50
+ record = data['records'][0] # On prend le premier enregistrement correspondant
51
+ student_id = record['fields'].get('ID_Etu', 'Aucun id trouvé')
52
+ return student_id
53
+ else:
54
+ return None
55
+ else:
56
+ logger.error(f"Erreur lors de la récupération des informations : {response.status_code} - {response.text}")
57
+ return None
58
+
59
+ except Exception as e:
60
+ logger.error(f"Erreur lors de la récupération des informations : {str(e)}")
61
+ return None
62
+
63
+ student_id = get_id_by_name(student_name)
64
 
65
  def get_user_info_by_id(student_id):
66
  url = f"https://api.airtable.com/v0/{AIRTABLE_BASE_ID}/Inscription_Etudiants"