sarim commited on
Commit
f74ddd5
·
1 Parent(s): 4463e2d

different metals

Browse files
Files changed (1) hide show
  1. app.py +28 -5
app.py CHANGED
@@ -22,7 +22,11 @@ CACHE = {
22
  "gainers": None,
23
  "last_updated": None,
24
  "circuit_breaker": None,
25
- "gold_price": None
 
 
 
 
26
  }
27
 
28
  BASE_URL = "https://www.psx.com.pk"
@@ -338,7 +342,7 @@ def get_announcements_scrap():
338
  return announcements
339
 
340
 
341
- def get_gold_data():
342
 
343
  BASE_URL = "https://api.gold-api.com/history"
344
 
@@ -349,7 +353,7 @@ def get_gold_data():
349
  end = int(datetime.utcnow().timestamp())
350
  start = int((datetime.utcnow() - timedelta(days=730)).timestamp())
351
 
352
- data = metals_api.get_price_history("XAU", start, end)
353
  return data
354
 
355
 
@@ -380,7 +384,11 @@ def background_scrap():
380
  CACHE["gainers"] = get_active_gainers()
381
  CACHE["last_updated"] = time.time()
382
  CACHE["circuit_breaker"] = get_circuit_breakers()
383
- CACHE["gold_price"] = get_gold_data()
 
 
 
 
384
 
385
  print(f"Next update after 3 hours delay...")
386
 
@@ -457,5 +465,20 @@ def get_all_circuit_breakers():
457
 
458
  @app.get("/gold_price")
459
  def get_gold_historial_price():
460
-
461
  return CACHE["gold_price"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  "gainers": None,
23
  "last_updated": None,
24
  "circuit_breaker": None,
25
+ "gold_price": None,
26
+ "silver_price": None,
27
+ "palladium_price": None,
28
+ "copper_price": None,
29
+ "platinum_price": None
30
  }
31
 
32
  BASE_URL = "https://www.psx.com.pk"
 
342
  return announcements
343
 
344
 
345
+ def get_metal_data(metal:str):
346
 
347
  BASE_URL = "https://api.gold-api.com/history"
348
 
 
353
  end = int(datetime.utcnow().timestamp())
354
  start = int((datetime.utcnow() - timedelta(days=730)).timestamp())
355
 
356
+ data = metals_api.get_price_history(metal, start, end)
357
  return data
358
 
359
 
 
384
  CACHE["gainers"] = get_active_gainers()
385
  CACHE["last_updated"] = time.time()
386
  CACHE["circuit_breaker"] = get_circuit_breakers()
387
+ CACHE["gold_price"] = get_metal_data("XAU")
388
+ CACHE["silver_price"] = get_metal_data(metal="XAG"),
389
+ CACHE['platinum_price'] = get_metal_data(metal="XPT")
390
+ CACHE['palladium_price'] = get_metal_data(metal="XPD")
391
+ CACHE['copper_price'] = get_metal_data(metal="HG")
392
 
393
  print(f"Next update after 3 hours delay...")
394
 
 
465
 
466
  @app.get("/gold_price")
467
  def get_gold_historial_price():
 
468
  return CACHE["gold_price"]
469
+
470
+ @app.get("/gold_price")
471
+ def get_silver_historial_price():
472
+ return CACHE['silver_price']
473
+
474
+ @app.get("/gold_price")
475
+ def get_copper_historial_price():
476
+ return CACHE['copper_price']
477
+
478
+ @app.get("/gold_price")
479
+ def get_platinum_historial_price():
480
+ return CACHE['platinum_price']
481
+
482
+ @app.get("/gold_price")
483
+ def get_palladium_historial_price():
484
+ return CACHE['palladium_price']