colesr commited on
Commit
eb28c3e
·
verified ·
1 Parent(s): 5ccefae

Force upload: main.py with correct filter + frontend fix

Browse files
Files changed (1) hide show
  1. main.py +17 -7
main.py CHANGED
@@ -198,9 +198,20 @@ def fetch_worldbank(
198
  if len(data) < 2:
199
  continue
200
  # Known World Bank aggregate/region codes (not real countries)
201
- # Known World Bank aggregate codes (not real countries)
202
- WB_AGGREGATE_CODES = {"AFE","AFW","ARB","CSS","CEB","EAP","EAR","EAS","ECA","ECS","EUU","FCS","HPC","IBD","IBT","IDA","IDB","IDX","INX","LAC","LCN","LDC","LIC","LMC","LMY","LTE","MEA","MIC","MNA","NAC","OED","OSS","PSS","PRE","PST","SAS","SSA","SSF","SST","TEA","TEC","TLA","TMN","TSA","TSS","WLD"}
203
- # Common aggregate name patterns (not exhaustive, but catches most)
 
 
 
 
 
 
 
 
 
 
 
204
  AGGREGATE_NAME_PATTERNS = ["(excluding", "income levels)", "all income", "small states", "demographic dividend", "World", "Arab World", "European Union"]
205
  for item in data[1]:
206
  country_info = item.get("country", {})
@@ -211,12 +222,11 @@ def fetch_worldbank(
211
  year = item.get("date")
212
  if not country or value is None:
213
  continue
214
- # Filter: skip if country ID is a known WB aggregate code
215
  if country_id in WB_AGGREGATE_CODES:
216
  continue
217
- # Secondary filter: skip if name contains aggregate patterns
218
- is_agg_name = any(p in country_raw for p in AGGREGATE_NAME_PATTERNS)
219
- if is_agg_name:
220
  continue
221
  if country not in records:
222
  records[country] = {"country": country}
 
198
  if len(data) < 2:
199
  continue
200
  # Known World Bank aggregate/region codes (not real countries)
201
+ # Observed from actual API: 1A,1W,4E,7E,8S,B8,S1-S4,T2-T7,V1-V4,XC-XT,XY,Z4-ZJ,ZQ,ZT,ZF,ZG,ZH,ZI, and long 3-char region codes
202
+ WB_AGGREGATE_CODES = {
203
+ "1A","1W","4E","7E","8S","B8","F1","OE","EU",
204
+ "ZH","ZI","ZG","ZF","Z4","Z7","ZJ","ZQ","ZT",
205
+ "S1","S2","S3","S4","T2","T3","T4","T5","T6","T7",
206
+ "V1","V2","V3","V4",
207
+ "XC","XD","XE","XF","XG","XH","XI","XJ","XL","XM","XN","XO","XP","XQ","XT","XU","XY",
208
+ "AFE","AFW","ARB","CSS","CEB","EAP","EAR","EAS","ECA","ECS",
209
+ "EUU","FCS","HPC","IBD","IBT","IDA","IDB","IDX","INX",
210
+ "LAC","LCN","LDC","LIC","LMC","LMY","LTE","MEA","MIC","MNA",
211
+ "NAC","OED","OSS","PSS","PRE","PST","SAS","SSA","SSF","SST",
212
+ "TEA","TEC","TLA","TMN","TSA","TSS","WLD"
213
+ }
214
+ # Common aggregate name patterns
215
  AGGREGATE_NAME_PATTERNS = ["(excluding", "income levels)", "all income", "small states", "demographic dividend", "World", "Arab World", "European Union"]
216
  for item in data[1]:
217
  country_info = item.get("country", {})
 
222
  year = item.get("date")
223
  if not country or value is None:
224
  continue
225
+ # Skip known aggregate codes AND all single/double-letter codes (they're all aggregates)
226
  if country_id in WB_AGGREGATE_CODES:
227
  continue
228
+ # Also skip if name contains aggregate patterns
229
+ if any(p in country_raw for p in AGGREGATE_NAME_PATTERNS):
 
230
  continue
231
  if country not in records:
232
  records[country] = {"country": country}