-
Notifications
You must be signed in to change notification settings - Fork 0
/
currency.py
41 lines (34 loc) · 1.24 KB
/
currency.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import urllib
import sys
import time
import csv
import re
import os
LOCATION_URL="http://nok.fxexchangerate.com/"
regex2="(\S*\d+\s\w+\s\=\s[^\s]*.*[NOK])<br/>"
m2 = re.compile(regex2)
foundfirst=False
foundsecond=False
fromto=["USD","GBP","EUR","SGD","JPY"]
now = time.strftime("%c")
for currency in fromto:
response = urllib.urlopen(LOCATION_URL+ currency + ".xml")
lines = response.readlines()
output_string=""
# Build the output from the web query as a string
for line in lines:
#print("Current line: "+line)
mymatch2 = m2.search(line)
if mymatch2:
value=mymatch2.group(1)
if not foundfirst:
foundfirst=True
output_string=output_string + " " + "Convert:" + value + "\n"
continue
else:
foundsecond=True
output_string=output_string + " " + "Convert:" + value + "\n"
break
sys.stdout.write(now)
sys.stdout.write(output_string)
time.sleep(1)