-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunc.py
More file actions
35 lines (28 loc) · 981 Bytes
/
func.py
File metadata and controls
35 lines (28 loc) · 981 Bytes
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
import os
import csv
import time
import requests
from typing import List
from bs4 import BeautifulSoup
def true_index_search(day: str, month: str, year: str, data: str, result_data: str) -> None:
if '"error": "Not found"' not in data:
index = data.find("USD")
true_index_begin = data.find("Value", index)
true_index_end = data.find(",", true_index_begin)
result = ""
for i in range(true_index_begin + 8, true_index_end):
result = result + data[i]
print("USD value is " + result)
result_data.append(
[
str(day).zfill(2) + "." +
str(month).zfill(2) + "." + str(year),
result,
]
)
else:
print(f"can not pars{year}.{month}.{day}")
def csv_write(result_data: str) -> None:
with open("data.csv", "w", encoding="utf-8", newline="") as file:
writer = csv.writer(file)
writer.writerows(result_data)