import json, collections, re from radar import leer_xml, es_droga, ficha, sinacento ents, meta = leer_xml("SDN.XML") GIROS = ('accommodation','tour operator','travel agency','reservation service','real estate', 'restaurants','beverage serving','gambling','amusement','recreation','sports','creative, arts', 'passenger air transport','sea and coastal','renting and leasing of motor vehicles','water transport') NOMBRES = ('HOTEL','RESORT','BEACH','PLAYA','MARINA','VILLAS','SUITES','TIMESHARE','VACATION','VACACION', 'TOUR','TRAVEL','VIAJES','TURIST','TURISM','SPA ','CLUB ','YACHT','YATE','GOLF','RESIDENCES', 'CONDOMINIO','CASINO','RENTA VACACIONAL','HOSPEDAJE','INMOBILIARIA','BIENES RAICES','DESARROLLOS') def es_mx(x): return any((a.get('country') or '').strip().lower()=='mexico' for a in x['adr']) out=[] for x in ents: if x['tipo']!='Entity' or not es_droga(x['prog']) or not es_mx(x): continue giro=' '.join(x['ids'].get('Organization Type:',[])).lower() n=sinacento(x['nombre']) hit_g=[g for g in GIROS if g in giro] hit_n=[k for k in NOMBRES if k in n] if hit_g or hit_n: f=ficha(x); f['hit_giro']=hit_g; f['hit_nombre']=hit_n f['edo']=sorted({(a.get('stateOrProvince') or '').strip() for a in x['adr'] if a.get('stateOrProvince')}) f['ciudad']=sorted({(a.get('city') or '').strip() for a in x['adr'] if a.get('city')}) f['linked']=re.findall(r'Linked To: ([^;)]+)', x['remarks']) out.append(f) print(meta, 'entidades turismo/inmobiliario/ocio MX bloqueadas:', len(out)) # por estado c=collections.Counter() for f in out: for e in (f['edo'] or ['(sin estado)']): c[e]+=1 for k,v in c.most_common(): print(f"{v:4d} {k}") print('---- por giro OFAC ----') cg=collections.Counter(g for f in out for g in f['hit_giro']) for k,v in cg.most_common(): print(f"{v:4d} {k}") print('---- solo hospedaje/tour/viajes/reservas (turismo estricto) ----') est=[f for f in out if any(g in ('accommodation','tour operator','travel agency','reservation service') for g in f['hit_giro'])] print(len(est)) ce=collections.Counter() for f in est: for e in (f['edo'] or ['(sin estado)']): ce[e]+=1 for k,v in ce.most_common(): print(f"{v:4d} {k}") for f in est: print(f['uid'], '|', f['nombre'], '|', ', '.join(f['edo']), '|', ', '.join(f['ciudad']), '|', f['giro'], '|', f['prog'], '| RFC', f['rfc'], '| folio', f['folio'], '| linked', f['linked'][:2]) json.dump(out, open('censo_turismo_mx.json','w'), ensure_ascii=False, indent=1)