
    ǥj                         d Z ddlZddlZej                            ej                            e                    Zej                            ed          Z	dddddd	Z
d
 Zd Zd ZddZdS )u  World.xyz binary-market integration for the football pipeline.

The market catalog (`markets-api-proxy.world-xyz.workers.dev/api/v1/markets`) is
Cloudflare-gated to the world.xyz frontend session — even stealth proxies get
403 — so price fetching is not possible from this box. Instead:

1. picks.py prices every upcoming fixture into binary markets
   (win / over-under 2.5 / BTTS) and writes world_prices.json.
2. You read the YES price in Phantom, then:
   - compare it against the fair price in today's report, or
   - run `python3 world_check.py "Team A vs Team B" <price> [market]`
     for an instant verdict (BUY YES / BUY NO / PASS).

Feeding skeleton: the day the API opens up (or via a session-cookie channel),
`fetch_prices()` drops in and the manual step disappears.
    Nzworld_prices.jsonzHome to winzAway to winzOver 2.5 goalszUnder 2.5 goalszBoth teams to score)home_winaway_winover_2_5	under_2_5bttsc                     t          t          d          5 }t          j        | |dd           d d d            d S # 1 swxY w Y   d S )NwF   )ensure_asciiindent)openPRICES_FILEjsondump)rowsfs     //root/.hermes/scripts/sports-predictor/world.pysave_pricesr       s    	k3		 91	$a88889 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9s   <A A c                      t           j                            t                    sg S t	          t                    5 } t          j        |           cd d d            S # 1 swxY w Y   d S )N)ospathexistsr   r   r   load)r   s    r   load_pricesr   %   s    7>>+&& 		k		 ay||                 s   AA #A c                 $  
 ddl m
 
fd|                    dd          D             \  }}d\  }}| D ]S} 
|d                    
|d                   }}||k    s||v s||v rdnd||k    s||v s||v rdndz   }	|	|k    r||	}}T|d	k    r|nd
S )z8Fuzzy match a 'Team A vs Team B' string onto price rows.r   )normalize_teamc                 J    g | ]} |                                            S  )strip).0xr   s     r   
<listcomp>zfind_match.<locals>.<listcomp>/   s+    HHH!NN17799%%HHH    vsr
   )Ng        homeaway   N)sourcesr   split)haystack	match_keyabbest
best_scorerownanbscorer   s             @r   
find_matchr4   ,   s    &&&&&&HHHHytQ/G/GHHHDAq D* * *F,,nnS[.I.IBQww"''Q"WW1Qww"''Q"WW1>:"E*D??44,r#   {Gz?皙?c                 
   ddl m} | d                             |          }| d| dd                    t                     S  |||||          }t                              ||          }|d	         d
k    r!| d|dd|dd|d         dd|d         dd
S |d	         dk    r!| d|dd|dd|d         dd|d         dd
S | d|dd|dd|                    dd          dd|                    dd          dd
S )zNrow: world_prices entry; market: key like 'home_win'; price: quoted YES price.r   )world_verdictmarketsNzUnknown market 'z'. Available: z, )spreadedge_minactionzBUY YESz: model z.0%z
 vs price z -> BUY YES at <= price_at_mostz (edge edge)zBUY NOz -> BUY NO at >= price_at_leastz -> PASS (edge yes edge_yesz+.0%z, no edge_no)modelr8   getjoinMARKET_LABELS)	r0   marketpricer:   r;   r8   model_pvlabels	            r   verdict_forrL   :   s   ######)n  ((GR&RR		-8P8PRRRguVhGGGAff--E{i T T'E T TE T T$%o$6ST TCDV9ST T T 	U{h T T'E T TE T T#$%5#6ST TCDV9ST T T 	U U UgI U UUI U Uz1--TU U9:y!9L9LTU U U Vr#   )r5   r6   )__doc__r   r   r   dirnameabspath__file__HERErE   r   rF   r   r   r4   rL   r   r#   r   <module>rR      s       					wrwx0011gll4!455  "! 9 9 9
  - - -V V V V V Vr#   