s-ttp commited on
Commit
fc0f55c
·
verified ·
1 Parent(s): daa91a2

Upload engine/predict_yearly.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. engine/predict_yearly.py +12 -3
engine/predict_yearly.py CHANGED
@@ -7306,9 +7306,18 @@ def _wiki_leadership(company_name):
7306
  except Exception:
7307
  _ctx = _ssl.create_default_context()
7308
  def _get(url):
7309
- req = _u.Request(url, headers={"User-Agent": "crucible-analyst/1.0"})
7310
- with _u.urlopen(req, timeout=12, context=_ctx) as r:
7311
- return r.read().decode()
 
 
 
 
 
 
 
 
 
7312
  q = _up.quote(str(company_name or ""))
7313
  sr = json.loads(_get(f"https://en.wikipedia.org/w/api.php?action=opensearch&search={q}&limit=1&format=json"))
7314
  if not sr[1]:
 
7306
  except Exception:
7307
  _ctx = _ssl.create_default_context()
7308
  def _get(url):
7309
+ # Wikimedia 403s generic UAs from datacenter IPs — use a descriptive UA with a
7310
+ # contact URL (their bot policy), and prefer requests' TLS/proxy handling.
7311
+ _ua = {"User-Agent": "CrucibleAnalyst/1.0 (https://huggingface.co/spaces/s-ttp/crucible; research tool)"}
7312
+ try:
7313
+ import requests as _rq
7314
+ r = _rq.get(url, headers=_ua, timeout=12)
7315
+ r.raise_for_status()
7316
+ return r.text
7317
+ except Exception:
7318
+ req = _u.Request(url, headers=_ua)
7319
+ with _u.urlopen(req, timeout=12, context=_ctx) as r:
7320
+ return r.read().decode()
7321
  q = _up.quote(str(company_name or ""))
7322
  sr = json.loads(_get(f"https://en.wikipedia.org/w/api.php?action=opensearch&search={q}&limit=1&format=json"))
7323
  if not sr[1]: