1
0

check_seo.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. """
  2. Script de vérification SEO pour le blog Django
  3. Execute ce script pour vérifier que toutes les améliorations SEO sont en place
  4. Usage:
  5. python check_seo.py
  6. """
  7. import sys
  8. import os
  9. from pathlib import Path
  10. def check_file_exists(filepath, description):
  11. """Vérifie qu'un fichier existe"""
  12. if Path(filepath).exists():
  13. print(f"✅ {description}: {filepath}")
  14. return True
  15. else:
  16. print(f"❌ MANQUANT: {description}: {filepath}")
  17. return False
  18. def check_file_contains(filepath, search_string, description):
  19. """Vérifie qu'un fichier contient une chaîne"""
  20. try:
  21. with open(filepath, 'r', encoding='utf-8') as f:
  22. content = f.read()
  23. if search_string in content:
  24. print(f"✅ {description}")
  25. return True
  26. else:
  27. print(f"❌ ABSENT: {description}")
  28. return False
  29. except FileNotFoundError:
  30. print(f"❌ FICHIER INTROUVABLE: {filepath}")
  31. return False
  32. except Exception as e:
  33. print(f"❌ ERREUR: {description} - {e}")
  34. return False
  35. def main():
  36. print("🔍 Vérification des améliorations SEO du blog\n")
  37. print("=" * 60)
  38. results = []
  39. # 1. Vérifier les nouveaux fichiers
  40. print("\n1️⃣ FICHIERS CRÉÉS")
  41. print("-" * 60)
  42. results.append(check_file_exists("blog/seo_helpers.py", "Helper SEO"))
  43. results.append(check_file_exists("blog/templates/blog/seo_meta.html", "Template métadonnées SEO"))
  44. results.append(check_file_exists("blog/templates/blog/breadcrumbs.html", "Template breadcrumbs"))
  45. # 2. Vérifier les imports dans views.py
  46. print("\n2️⃣ IMPORTS DANS LES VUES")
  47. print("-" * 60)
  48. results.append(check_file_contains(
  49. "blog/views.py",
  50. "from blog.seo_helpers import SEOMetadata",
  51. "Import SEOMetadata"
  52. ))
  53. results.append(check_file_contains(
  54. "blog/views.py",
  55. "import json",
  56. "Import json pour Schema.org"
  57. ))
  58. # 3. Vérifier l'utilisation dans blog_play
  59. print("\n3️⃣ INTÉGRATION DANS blog_play()")
  60. print("-" * 60)
  61. results.append(check_file_contains(
  62. "blog/views.py",
  63. "seo_helper = SEOMetadata",
  64. "Initialisation SEOMetadata dans blog_play"
  65. ))
  66. results.append(check_file_contains(
  67. "blog/views.py",
  68. "page.breadcrumbs",
  69. "Génération des breadcrumbs"
  70. ))
  71. results.append(check_file_contains(
  72. "blog/views.py",
  73. "prefetch_related",
  74. "Optimisation des requêtes"
  75. ))
  76. # 4. Vérifier l'intégration dans blog_index
  77. print("\n4️⃣ INTÉGRATION DANS blog_index()")
  78. print("-" * 60)
  79. results.append(check_file_contains(
  80. "blog/views.py",
  81. "seo = seo_helper.get_listing_metadata",
  82. "Métadonnées pour listing"
  83. ))
  84. # 5. Vérifier le sitemap
  85. print("\n5️⃣ CONFIGURATION SITEMAP")
  86. print("-" * 60)
  87. results.append(check_file_exists("blog/sitemaps.py", "Sitemap Django"))
  88. results.append(check_file_contains(
  89. "blog/sitemaps.py",
  90. "BlogSitemap",
  91. "Classe BlogSitemap"
  92. ))
  93. results.append(check_file_contains(
  94. "blog/sitemaps.py",
  95. "protocol = 'https'",
  96. "Protocol HTTPS dans sitemap"
  97. ))
  98. # 6. Vérifier robots.txt
  99. print("\n6️⃣ ROBOTS.TXT")
  100. print("-" * 60)
  101. results.append(check_file_exists("static/robots.txt", "Fichier robots.txt"))
  102. results.append(check_file_contains(
  103. "static/robots.txt",
  104. "Sitemap: https://www.duhaz.fr/sitemap.xml",
  105. "Référence au sitemap"
  106. ))
  107. # Résumé
  108. print("\n" + "=" * 60)
  109. total = len(results)
  110. passed = sum(results)
  111. failed = total - passed
  112. print(f"\n📊 RÉSUMÉ")
  113. print("-" * 60)
  114. print(f"✅ Tests réussis: {passed}/{total}")
  115. print(f"❌ Tests échoués: {failed}/{total}")
  116. if failed == 0:
  117. print("\n🎉 PARFAIT! Toutes les améliorations SEO sont en place!")
  118. print("\n📋 PROCHAINES ÉTAPES:")
  119. print(" 1. Mettre à jour core/templates/base.html")
  120. print(" 2. Ajouter les breadcrumbs dans listing.html et read.html")
  121. print(" 3. Tester avec Google Rich Results Test")
  122. print(" 4. Consulter AMELIORATION_SEO.md pour plus de détails")
  123. return 0
  124. else:
  125. print("\n⚠️ Certaines améliorations sont manquantes.")
  126. print(" Consultez AMELIORATION_SEO.md pour les instructions complètes.")
  127. return 1
  128. if __name__ == "__main__":
  129. sys.exit(main())