<jupyter_start><jupyter_text>Factor cambiario HN - BCH
 Historico Factor Cambiario<jupyter_code>from datetime import datetime
import requests as req
import xml.etree.ElementTree as ET 
import pandas as pd

BCH_URL="https://www.bch.hn/_api/web/lists/GetByTitle('LST-INDICADOR-TIPOCAMBIO')/items?$top=5000&$select=Fecha,Etiqueta1,Valor1&$orderby=FechaPublicacion1 desc"

def getWsFactorCambiario():
	""" Extrayendo datos """
	res=req.get(BCH_URL,params={'Accept':'application/json; odata=verbose'})
	tree = ET.fromstring(res.content)
	return [(tree[i][6][0][0].text, tree[i][6][0][1].text, tree[i][6][0][2].text) for i in range(3,len(tree))]

def getFactorCambiarioSinCambios():
	""" Generando el dataset """
	data=pd.DataFrame(getWsFactorCambiario())
	data=data.rename(columns={0:'Fecha',1:'Tipo',2:'Factor'})
	return data
  
def getFactorCambiario():
	""" Limpiando el dataset """
	data = getFactorCambiarioSinCambios()
	data['Fecha']=data['Fecha'].str.strip()
	data['Dia']=data['Fecha'].apply(lambda x: x.split(' ')[0])
	data['Fecha']=data['Fecha'].apply(lambda x: x.split(' ')[1])
	data['Fecha']=data['Fecha'].apply(lambda x: pd.to_datetime(x,format='%d/%m/%Y'))
	data['Factor']=data['Factor'].astype(float)
	data.loc[data['Tipo']=='Valor de Compra','Tipo']='Compra'
	fechas = pd.DataFrame({'Fecha':pd.date_range(start=min(data['Fecha']),end=max(data['Fecha']))})
	data=fechas.merge(data,on='Fecha',how='left')
	data=data.fillna(method='pad')
	data=data.sort_values(by='Fecha')
	return(data)

data=getFactorCambiario()
data.head(10)
import plotly.express as px

df = data
fig = px.line(df, x='Fecha', y="Factor",labels={'Factor':'Precio Compra (lps)','Fecha':'Fecha'})

fig.update_xaxes(
    rangeslider_visible=True,
    rangeselector=dict(
        buttons=list([
            dict(count=1, label="1m", step="month", stepmode="backward"),
            dict(count=6, label="6m", step="month", stepmode="backward"),
            dict(count=1, label="YTD", step="year", stepmode="todate"),
            dict(count=1, label="1y", step="year", stepmode="backward"),
            dict(step="all")
        ])
    )
)
fig.write_html('fcwidget.html')
fig.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20458715596330276, 'fraction_numerical': 0.014220183486238533, 'mean_word_length': 6.343434343434343, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '383109', 'license': 'MIT', 'n_tokens_mistral': 874, 'n_tokens_neox': 857, 'n_words': 115, 'path': 'bch/factorcambiario.ipynb', 'repo_name': 'jhrodix/webscrapinghn', 'size': '2180'}