I have this script that is in python, and i want to make c++ program from that.
Currency converter:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
import datetime
def fetching_Exchange_Rate():
d = datetime.date.today()
date = d.strftime("%d%m%y")
url = "http://www.hnb.hr/tecajn/f" + date + ".dat"
link = urllib2.urlopen(url)
s = link.read()
link.close()
return s
def rate(code,type):
cont = fetching_Exchange_Rate()
list = cont.split("\r\n")
rate = 0.0
for i in list:
if i.find(kod) >= 0:
if tip == "s":
rate = float(i[31:39].replace(",","."))
if type == "k":
rate = float(i[16:24].replace(",","."))
if type == "p":
rate = float(i[46:].replace(",","."))
if i[6:9] == "100":
rate = rate / 100
break
return rate
more = "y"
while more.lower() == "y":
k = raw_input("Enter the currency (EUR € , USD $, GBP £, ...): ")
k = k.upper()
print "\n"
t = raw_input("type of transaction (s=Buying, p=Middle, k=Selling: ")
j = float(raw_input("amount of monetary units: "))
print "total: %s Kn" % str(j * rate(k, t))
more = raw_input("more? (d/n): ")
what this script do is connect to web page of Croatian National Bank, download exchange rate and convert needed currency, one line of that formatted data:
http://www.hnb.hr/tecajn/f041011.dat
036AUD001 5,389627 5,405845 5,422063
i figured out how to get date in that format in c++, but i don't know how to write that urllib2, urlopen command in c++. thanks for any advice, sorry if something make no sense, i just translated it in google translate in 5 minutes.
4 replies to this topic
#1
Posted 04 October 2011 - 10:20 AM
|
|
|
#2
Posted 04 October 2011 - 10:32 AM
What library are you planning to use? C++ does not, by default, have support for any form of socket programming. You could use the boost library, however.
#3
Posted 04 October 2011 - 10:39 AM
well, I don't really know which libraries exist for that purpose, i find some libraries on google but i cound't understand how to fit it into rest program
#4
Posted 04 October 2011 - 12:39 PM
Qt, wxWidgets, gtkmm, and boost all provide networking libraries. Some of them provide easier tools for getting data from a website than others. It's really going to depend on what you want to use.
#5
Posted 04 October 2011 - 12:55 PM
okay, i find one solution. for date i write function:
void dat(string &d){
time_t rawtime;
struct tm * timeinfo;
char datum[80];
time ( &rawtime );
timeinfo=localtime(&rawtime);
strftime(datum,80,"%d%m%y.",timeinfo);
cout << "\ndatum: " << datum;
d=datum;
}
int main()
{
string f;
dat(f);
cout << "http://www.hnb.hr/tecajn/f" << f << ".dat";
and for exchange rates, i will download that list as txt file on disk with libcurl, and read data from file...
void dat(string &d){
time_t rawtime;
struct tm * timeinfo;
char datum[80];
time ( &rawtime );
timeinfo=localtime(&rawtime);
strftime(datum,80,"%d%m%y.",timeinfo);
cout << "\ndatum: " << datum;
d=datum;
}
int main()
{
string f;
dat(f);
cout << "http://www.hnb.hr/tecajn/f" << f << ".dat";
and for exchange rates, i will download that list as txt file on disk with libcurl, and read data from file...
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









