-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
87 additions
and
1 deletion.
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
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,40 @@ | ||
import requests | ||
import xml.etree.ElementTree as ET | ||
import csv | ||
|
||
outfile = 'data/financiar/curs-valutar.csv' | ||
|
||
# Define the URL of the XML data | ||
xml_url = 'https://www.bnr.ro/nbrfxrates.xml' | ||
|
||
# Send a GET request to the URL and get the response | ||
response = requests.get(xml_url) | ||
|
||
# Check if the request was successful | ||
if response.status_code == 200: | ||
# Parse the XML content with namespace | ||
xml_data = response.content | ||
root = ET.fromstring(xml_data) | ||
|
||
# Define the namespace | ||
ns = {'ns': 'http://www.bnr.ro/xsd'} | ||
|
||
# Extract data from the XML | ||
date = root.find(".//ns:Cube", namespaces=ns).attrib['date'] | ||
rates = root.findall(".//ns:Rate", namespaces=ns) | ||
|
||
# Create a CSV file and write header | ||
csv_filename = outfile | ||
with open(csv_filename, mode='w', newline='') as csv_file: | ||
csv_writer = csv.writer(csv_file) | ||
csv_writer.writerow(["Currency", "Rate"]) | ||
|
||
# Write exchange rates to CSV | ||
for rate in rates: | ||
currency = rate.attrib['currency'] | ||
rate_value = rate.text | ||
csv_writer.writerow([currency, rate_value]) | ||
|
||
print(f"Exchange rates saved to {csv_filename}") | ||
else: | ||
print("Failed to fetch XML data") |
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,32 @@ | ||
Currency,Rate | ||
AED,1.2531 | ||
AUD,2.9370 | ||
BGN,2.5304 | ||
BRL,0.9321 | ||
CAD,3.3719 | ||
CHF,5.1858 | ||
CNY,0.6302 | ||
CZK,0.2050 | ||
DKK,0.6640 | ||
EGP,0.1489 | ||
EUR,4.9491 | ||
GBP,5.7800 | ||
HUF,1.2855 | ||
INR,0.0555 | ||
JPY,3.1285 | ||
KRW,0.3449 | ||
MDL,0.2566 | ||
MXN,0.2673 | ||
NOK,0.4294 | ||
NZD,2.7063 | ||
PLN,1.1040 | ||
RSD,0.0422 | ||
RUB,0.0472 | ||
SEK,0.4157 | ||
THB,0.1298 | ||
TRY,0.1719 | ||
UAH,0.1246 | ||
USD,4.6025 | ||
XAU,285.7467 | ||
XDR,6.0918 | ||
ZAR,0.2403 |