Spaces:
Sleeping
Sleeping
File size: 2,465 Bytes
d7e7bab b15516f d7e7bab b15516f d7e7bab b15516f d7e7bab b15516f d7e7bab b15516f d7e7bab b15516f d7e7bab b15516f d7e7bab b15516f d7e7bab b15516f d7e7bab b15516f d7e7bab b15516f d7e7bab b15516f d7e7bab b15516f d7e7bab b15516f d7e7bab b15516f d7e7bab b15516f d7e7bab b15516f d7e7bab | 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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | #!/usr/bin/env python3
"""
Standalone script to fetch Polymarket menu data and export as JSON.
Run this on your local machine to avoid network timeout issues.
Usage:
python fetch_menu_data.py [--num-items N] [--output output.json]
"""
import argparse
import json
import sys
from datetime import datetime, timezone
from pathlib import Path
from dotenv import load_dotenv
# Load environment variables from .env file
load_dotenv()
# Import the generator from email3.py
from email3 import PolymarketEmailGenerator
def main():
parser = argparse.ArgumentParser(
description="Fetch Polymarket menu data and export as JSON"
)
parser.add_argument(
"--num-items",
type=int,
default=10,
help="Number of items per section (default: 10)",
)
parser.add_argument(
"--output",
type=str,
default="menu_data.json",
help="Output JSON file path (default: menu_data.json)",
)
args = parser.parse_args()
print("Starting Polymarket menu data fetch...")
print(f" Items per section: {args.num_items}")
print()
try:
# Create generator instance
generator = PolymarketEmailGenerator(num_items=args.num_items)
# Build menu (this fetches all data including breaking news)
print("Fetching menu data...")
menu_entries = generator.build_menu(verbose=True)
# Format as MenuResponse structure
menu_response = {
"generated_at": datetime.now(timezone.utc).isoformat(),
"items": menu_entries,
}
# Write to JSON file
output_path = Path(args.output)
with open(output_path, "w", encoding="utf-8") as f:
json.dump(menu_response, f, indent=2, ensure_ascii=False)
print()
print(f"Success! Menu data exported to: {output_path}")
print(f" Total items: {len(menu_entries)}")
# Show breakdown by category
categories = {}
for item in menu_entries:
cat = item.get("category", "unknown")
categories[cat] = categories.get(cat, 0) + 1
print(f" Categories: {categories}")
return 0
except KeyboardInterrupt:
print("\nInterrupted by user")
return 1
except Exception as e:
print(f"\nError: {e}", file=sys.stderr)
import traceback
traceback.print_exc()
return 1
if __name__ == "__main__":
sys.exit(main())
|