-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
65 lines (50 loc) · 1.65 KB
/
main.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import requests
import datetime
import matplotlib.pyplot as plt
import numpy as np
x = datetime.datetime.now()
fromYear = x.strftime("%y")
fromMonth = x.strftime("%m")
monthNow = int(x.strftime("%m"))
if monthNow == 1:
fromMonth = "12"
fromYear = int(x.strftime("%y")) -1
fromYear = str(fromYear)
elif monthNow < 10:
fromMonth = int(x.strftime("%m")) -1
fromMonth = "0" + str(fromMonth)
else:
fromMonth = int(x.strftime("%m")) - 1
fromMonth = str(fromMonth)
fromDate = fromYear + "-" + fromMonth + "-" + x.strftime("%d")
timeNow = int(x.strftime("%H"))
if timeNow > 13:
toDate = x.strftime("%Y-%m-%d")
skro = requests.get("https://www.riksbank.se/sv/statistik/sok-rantor--valutakurser/?c=cAverage&f=Day&from=" + fromDate +"&g130-SEKTHBPMI=on&s=Dot&to=" + toDate + "&export=csv")
else:
oneDayAgo = int(x.strftime("%d")) -1
toDate = x.strftime("%Y-%m-"+str(oneDayAgo))
skro = requests.get("https://www.riksbank.se/sv/statistik/sok-rantor--valutakurser/?c=cAverage&f=Day&from=" + fromDate +"&g130-SEKTHBPMI=on&s=Dot&to=" + toDate + "&export=csv")
f = open("skrot.csv", "w")
f.write(skro.text)
f.close
f = open("skrot.csv", "r")
next(f)
database = {}
for line in f:
line = line.strip("\n")
line = line.split(";")
line = line[0] + ";" + line[3]
line = line.split(";")
currentValue = float(line[1])
currentValue = 1 / currentValue
currentValue = round(currentValue, 4)
database[line[0]] = currentValue
print("1 SEK =", currentValue, "THB")
x = list(database.keys())
y = list(database.values())
xpoints = np.array(x)
ypoints = np.array(y)
plt.plot(xpoints, ypoints)
plt.xticks(rotation=45)
plt.show()