Skip to content

Commit b27640a

Browse files
authored
Merge pull request #2 from RickCruzz/feat/exercise2
Feat/exercise2
2 parents b9318a2 + 9c99515 commit b27640a

File tree

3 files changed

+46
-7
lines changed

3 files changed

+46
-7
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.idea*
22
*.DS_Store*
3-
*postgres-data*
3+
*postgres-data*
4+
*.venv

Exercises/Exercise-1/main.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ def unzip_remove(ret, directory, name_file):
2525

2626
def main():
2727
directory = "./downloads"
28-
if not os.path.exists(directory):
29-
os.makedirs(directory)
30-
28+
os.makedirs(directory, exist_ok=True)
29+
3130
for url in download_uris:
3231
name_file = url.split("/")[-1]
3332
ret = requests.get(url)

Exercises/Exercise-2/main.py

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,50 @@
1+
12
import requests
2-
import pandas
3+
import pandas as pd
4+
import re
5+
import shutil
6+
import os
7+
import glob
8+
9+
def find_files_by_time(url: str) -> list[str]:
10+
with requests.get(url, timeout=16) as response:
11+
pattern = re.compile(r"([A-z0-9]{11}\.csv)")
12+
13+
s = [
14+
pattern.search(i)
15+
for i in response.text.splitlines()
16+
if re.search(r"2024-01-19 10:27\s{2}", i)
17+
]
18+
19+
return [f"{url}{i.group(0)}" for i in s if i]
20+
21+
def download_files_find_max(files_list: list):
22+
os.makedirs(name="./tmp", exist_ok=True)
23+
24+
for file in files_list:
25+
name_file = file.split("/")[-1]
26+
ret = requests.get(file)
27+
open(f'./tmp/{name_file}.csv', 'wb').write(ret.content)
28+
29+
folder_path = './tmp/*.csv'
30+
csv_files = glob.glob(folder_path)
31+
max_value = 0
32+
for file in csv_files:
33+
df = pd.read_csv(file, low_memory=False)
34+
df_value = float(pd.to_numeric(df["HourlyDryBulbTemperature"].fillna("0"), errors='coerce').max())
35+
max_value = max(max_value, df_value)
36+
return max_value
37+
338

439

540
def main():
6-
# your code here
7-
pass
41+
url = "https://www.ncei.noaa.gov/data/local-climatological-data/access/2021/"
42+
file_list = find_files_by_time(url)
43+
max_value = download_files_find_max(file_list)
44+
print(max_value)
45+
shutil.rmtree("./tmp/")
846

947

1048
if __name__ == "__main__":
1149
main()
50+

0 commit comments

Comments
 (0)