Created
January 22, 2026 21:38
-
-
Save met/d63e1b5644a3040a1e6cf55ca1d2fcc3 to your computer and use it in GitHub Desktop.
Compare the charitable amounts collected from the Czech Republic and Poland to save people in Kyiv
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 requests | |
| from bs4 import BeautifulSoup | |
| import re | |
| from decimal import Decimal | |
| HEADERS = { | |
| "User-Agent": "Mozilla/5.0 (compatible; DonationComparer/1.0)" | |
| } | |
| def parse_amount(text: str) -> Decimal: | |
| """ | |
| Převede text typu '123 456 789 Kč' nebo '1,234,567 zł' | |
| na Decimal | |
| """ | |
| numbers = re.sub(r"[^\d]", "", text) | |
| return Decimal(numbers) | |
| def get_zbrane_pro_ukrajinu(): | |
| url = "https://www.zbraneproukrajinu.cz/kampane/sos" | |
| r = requests.get(url, headers=HEADERS, timeout=10) | |
| r.raise_for_status() | |
| soup = BeautifulSoup(r.text, "html.parser") | |
| # ⚠️ selektor je odhad – může se změnit | |
| amount_el = soup.select_one(".campaign__amount") | |
| if not amount_el: | |
| raise ValueError("Nepodařilo se najít částku na zbraneproukrajinu.cz") | |
| amount = parse_amount(amount_el.get_text()) | |
| return amount, "CZK" | |
| def get_pomagam(): | |
| url = "https://pomagam.pl/a7emy8" | |
| r = requests.get(url, headers=HEADERS, timeout=10) | |
| r.raise_for_status() | |
| soup = BeautifulSoup(r.text, "html.parser") | |
| # Pomagam.pl má částku většinou v meta nebo výrazném span | |
| amount_el = soup.select_one( | |
| '.total-pledge' | |
| ) | |
| if not amount_el: | |
| raise ValueError("Nepodařilo se najít částku na pomagam.pl") | |
| text = amount_el.get("content") if amount_el.name == "meta" else amount_el.get_text() | |
| amount = parse_amount(text) | |
| return amount, "PLN" | |
| def main(): | |
| cz_amount, cz_currency = get_zbrane_pro_ukrajinu() | |
| pl_amount, pl_currency = get_pomagam() | |
| print("📊 Porovnání vybraných částek") | |
| print("-" * 40) | |
| print(f"Zbraně pro Ukrajinu: {cz_amount:,} {cz_currency}") | |
| print(f"Pomagam.pl: {pl_amount:,} {pl_currency}") | |
| print("-" * 40) | |
| if cz_currency == pl_currency: | |
| diff = cz_amount - pl_amount | |
| print(f"Rozdíl: {diff:+,} {cz_currency}") | |
| else: | |
| print("⚠️ Částky jsou v různých měnách – pro srovnání je nutný kurz.") | |
| if __name__ == "__main__": | |
| main() | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Výstup: