Created
October 15, 2026 14:16
-
-
Save chiquimike/881b379b52898048fcb7dc5db48d9f66 to your computer and use it in GitHub Desktop.
wp_checker.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| from datetime import datetime, timezone, timedelta | |
| import requests | |
| SITES = [ | |
| "https://techcrunch.com", | |
| "https://wordpress.org/news", | |
| ] | |
| def check_wordpress_site(url): | |
| try: | |
| # Check main site status | |
| res = requests.get(url, timeout=10) | |
| if res.status_code != 200: | |
| return False, f"HTTP Error {res.status_code}" | |
| # Check WP JSON API for latest post | |
| api_url = f"{url.rstrip('/')}/wp-json/wp/v2/posts?per_page=1" | |
| api_res = requests.get(api_url, timeout=10) | |
| if api_res.status_code != 200: | |
| return False, f"API Error {api_res.status_code}" | |
| posts = api_res.json() | |
| if not posts: | |
| return False, "No posts found" | |
| latest_date_str = posts[0].get("date_gmt") | |
| latest_date = datetime.fromisoformat(latest_date_str).replace(tzinfo=timezone.utc) | |
| if datetime.now(timezone.utc) - latest_date > timedelta(hours=24): | |
| return False, f"Latest post is older than 24h ({latest_date_str})" | |
| return True, "OK" | |
| except Exception as e: | |
| return False, f"Exception: {str(e)}" | |
| if __name__ == "__main__": | |
| failed_sites = [] | |
| for site in SITES: | |
| ok, reason = check_wordpress_site(site) | |
| if not ok: | |
| failed_sites.append((site, reason)) | |
| print("=== FAILED SITES ===") | |
| for site, reason in failed_sites: | |
| print(f"FAILED: {site} -> {reason}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment