-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
41 lines (34 loc) · 1.4 KB
/
utils.py
File metadata and controls
41 lines (34 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
def paginate_launches(launches, display_keys=None, page_size=5):
total = len(launches)
if total == 0:
print("❌ Aucun élément à afficher.")
return
total_pages = (total + page_size - 1) // page_size
current_page = 0
while True:
start = current_page * page_size
end = start + page_size
page_items = launches[start:end]
if total_pages > 1:
print(f"\n📄 Page {current_page + 1}/{total_pages} — Affichage {start + 1} à {min(end, total)} sur {total}\n")
for launch in page_items:
for key in display_keys or launch.keys():
value = launch.get(key, "N/A")
if isinstance(value, str) and "date" in key.lower():
print(f"📅 {key.capitalize():<12}: {value}")
else:
print(f"{key.capitalize():<12}: {value}")
print("-" * 40)
if total_pages == 1:
break
print("\n[N] Suivant | [P] Précédent | [Q] Quitter")
choice = input("Votre choix : ").strip().lower()
if choice == "n" and current_page < total_pages - 1:
current_page += 1
elif choice == "p" and current_page > 0:
current_page -= 1
elif choice == "q":
print("🔚 Fin de la pagination.")
break
else:
print("⛔ Choix invalide ou limite atteinte.")