Last active
March 7, 2026 15:25
-
-
Save jakubboucek/91d9793ffdaeb027933fccb8dd565603 to your computer and use it in GitHub Desktop.
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 json | |
| import re | |
| # Načtení dat ze souboru | |
| file_path = 'mike.json' | |
| with open(file_path, 'r', encoding='utf-8') as f: | |
| data = json.load(f) | |
| output = [] | |
| for page in data: | |
| posts = page.get('data', {}).get('posts', {}).get('nodes', []) | |
| for post in posts: | |
| # Filtrování: Chceme pouze příspěvky, které obsahují video | |
| assets = post.get('assets', []) | |
| if not any(asset.get('hasVideo') is True for asset in assets): | |
| continue | |
| raw_text = post.get('text', '') | |
| post_id = post.get('id', '') | |
| json_title = post.get('title') | |
| # 1. Extrakce CZ-ID (z celého textu) | |
| cz_match = re.search(r'(CZ-[\w\+\d\-/ ]+)', raw_text) | |
| cz_id = cz_match.group(1).strip() if cz_match else "" | |
| # 2. Základní očištění textu od podpisu DETEKTIV MIKE a dál | |
| # Rozdělíme text podle podpisu a vezmeme jen to, co je před ním | |
| clean_content = re.split(r'\n\nDETEKTIV MIKE', raw_text, flags=re.IGNORECASE)[0].strip() | |
| # Rozdělení na řádky pro separaci nadpisu a popisu | |
| lines = clean_content.split('\n') | |
| # 3. Logika pro NADPIS | |
| # Pokud title v JSONu chybí (je None), vezmeme první řádek z textu | |
| if json_title and str(json_title).strip().lower() != 'none': | |
| final_title = str(json_title).strip() | |
| final_description = '\n'.join(lines).strip() | |
| elif lines: | |
| final_title = lines[0].strip() | |
| final_description = '\n'.join(lines[1:]).strip() | |
| else: | |
| final_title = "xxx" | |
| final_description = "" | |
| # Sestavení URL | |
| url = f"https://herohero.co/mikejepan/post/{post_id}" | |
| # Formátování výstupního bloku (pokud je hodnota prázdná, zůstane prázdno pod hlavičkou) | |
| post_block = ( | |
| f"ID:\n{cz_id}\n\n" | |
| f"NADPIS:\n{final_title}\n\n" | |
| f"POPIS:\n{final_description}\n\n" | |
| f"URL: {url}" | |
| ) | |
| output.append(post_block) | |
| # Vypsání výsledku | |
| print("\n---\n".join(output)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment