-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2871 from Sublian/main
Reto #10 - Python
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# * Llamar a una API es una de las tareas más comunes en programación. | ||
# * | ||
# * Implementa una llamada HTTP a una API (la que tú quieras) y muestra su | ||
# * resultado a través de la terminal. Para este ejemplo: Yahoo Finance | ||
# * Se obtiene un registro historico de los precios del oro/dolar en base a un año | ||
# * al final muestro el ultimo valor registrado en tiempo real | ||
# * Aquí tienes un listado de posibles APIs: | ||
# * https://github.com/public-apis/public-apis | ||
|
||
import yfinance as yf | ||
import pandas as pd | ||
import json, requests | ||
|
||
def golddata(): | ||
golddata= yf.Ticker("GC=F").history(period="1y") | ||
print(golddata) | ||
print("Gold csv extraction Finished :)") | ||
|
||
golddata() | ||
|
||
gold = json.loads(requests.get("https://forex-data-feed.swissquote.com/public-quotes/bboquotes/instrument/XAU/USD").text) | ||
data = gold[0] | ||
dataextract = data["spreadProfilePrices"] | ||
dataextract = dataextract[0]["ask"] | ||
print(f"<Data>: Gold price {dataextract} <USD> in real time ") |