Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Test direct pour identifier le problème exact avec NOM d'usage | |
| """ | |
| import sys | |
| sys.path.append('/home/liantsoa/Desktop/Work/process-IQ-rush-school-main/backend/admission-api') | |
| from pyairtable import Api | |
| # Configuration | |
| api_token = "patERUzF3jfYjyiJN.da9ae870b2d6f3904a9779159d7326c547a9376001ab741df0a43dd731081868" | |
| base_id = "app4dQwtK4LsrZl3k" | |
| table_name = "Liste des candidats" | |
| api = Api(api_token) | |
| table = api.table(base_id, table_name) | |
| # Test 1: Récupérer un record et voir le nom exact de la colonne | |
| print("=== Test 1: Récupération d'un enregistrement existant ===") | |
| records = table.all() | |
| for record in records[:1]: | |
| fields = record.get('fields', {}) | |
| for key in fields.keys(): | |
| if 'usage' in key.lower(): | |
| print(f"Nom exact de la colonne: {repr(key)}") | |
| print(f"Bytes: {key.encode('utf-8')}") | |
| # Test 2: Essayer de créer avec différentes variantes | |
| print("\n=== Test 2: Tentatives de création ===") | |
| # Variante 1: Apostrophe droite | |
| test1 = { | |
| "Prénom": "Test1", | |
| "NOM de naissance": "TestNom1", | |
| "NOM d'usage": "TestUsage1", | |
| "Sexe": "Masculin", | |
| "Date de naissance": "1990-01-01" | |
| } | |
| print("\nVariante 1: Apostrophe droite ('):") | |
| key1 = "NOM d'usage" | |
| print(f" Clé: {repr(key1)}") | |
| try: | |
| result1 = table.create(test1) | |
| print(f" ✅ Succès! ID: {result1['id']}") | |
| table.delete(result1['id']) | |
| except Exception as e: | |
| print(f" ❌ Échec: {e}") | |
| # Variante 2: Apostrophe typographique | |
| test2 = { | |
| "Prénom": "Test2", | |
| "NOM de naissance": "TestNom2", | |
| "NOM d'usage": "TestUsage2", # Apostrophe typographique | |
| "Sexe": "Féminin", | |
| "Date de naissance": "1990-01-01" | |
| } | |
| print("\nVariante 2: Apostrophe typographique ('):") | |
| key2 = "NOM d'usage" | |
| print(f" Clé: {repr(key2)}") | |
| try: | |
| result2 = table.create(test2) | |
| print(f" ✅ Succès! ID: {result2['id']}") | |
| table.delete(result2['id']) | |
| except Exception as e: | |
| print(f" ❌ Échec: {e}") | |
| # Variante 3: Sans NOM d'usage | |
| test3 = { | |
| "Prénom": "Test3", | |
| "NOM de naissance": "TestNom3", | |
| "Sexe": "Masculin", | |
| "Date de naissance": "1990-01-01" | |
| } | |
| print("\nVariante 3: Sans NOM d'usage:") | |
| try: | |
| result3 = table.create(test3) | |
| print(f" ✅ Succès! ID: {result3['id']}") | |
| table.delete(result3['id']) | |
| except Exception as e: | |
| print(f" ❌ Échec: {e}") | |