Spaces:
Sleeping
Sleeping
Download script/test_api.py from Loren/api_search_articles: direct link, hf CLI and curl.
- Browser
- Download file 1.07 kB
-
https://huggingface.co/spaces/Loren/api_search_articles/resolve/refs%2Fpr%2F1/script/test_api.py
- Command line
-
hf download hf://spaces/Loren/api_search_articles@refs/pr/1/script/test_api.py
-
curl -L -o test_api.py https://huggingface.co/spaces/Loren/api_search_articles/resolve/refs%2Fpr%2F1/script/test_api.py
1.07 kB
| import requests | |
| BASE_URL = "https://loren-api-search-articles.hf.space" | |
| def test_get_tags(): | |
| print("🔍 Test: /get_tags") | |
| resp = requests.get(f"{BASE_URL}/get_tags") | |
| if resp.status_code != 200: | |
| print("❌ Erreur", resp.status_code, resp.text) | |
| return | |
| tags = resp.json().get("tags", []) | |
| print(f"✅ {len(tags)} tags récupérés : {tags[:3]}...") # affiche 3 premiers | |
| return tags | |
| def test_get_articles_with_tags(tags): | |
| if not tags: | |
| print("⚠️ Aucun tag trouvé, test sauté") | |
| return | |
| print("\n🔍 Test: /get_articles_with_tags") | |
| params = {"tags": tags} | |
| resp = requests.get(f"{BASE_URL}/get_articles_with_tags", params=params) | |
| if resp.status_code != 200: | |
| print("❌ Erreur", resp.status_code, resp.text) | |
| return | |
| data = resp.json() | |
| print(f"✅ Articles trouvés: {len(data['articles'])}") | |
| def main(): | |
| tags = test_get_tags() | |
| print(tags[0:1]) | |
| test_get_articles_with_tags(tags[0:1]) | |
| if __name__ == "__main__": | |
| main() | |