add: gitignore

This commit is contained in:
Дмитрий Абдрахманов 2024-09-09 11:23:33 +03:00
parent cce24c469a
commit 8402acd68c
6 changed files with 22 additions and 20 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
__pycache__

1
data.out Normal file

File diff suppressed because one or more lines are too long

1
main.sh Normal file → Executable file
View File

@ -0,0 +1 @@
curl localhost:8000 > data.out

View File

@ -1,12 +1,11 @@
from datetime import datetime
from functools import cache
from http.server import BaseHTTPRequestHandler, HTTPServer
import json
import urllib.request
import os
from weather import weather_handler
def run(server_class=HTTPServer, handler_class=BaseHTTPRequestHandler):
server_address = ("", 8000)
server_address = ("", int(os.getenv("PORT", "8000")))
httpd = server_class(server_address, WeatherHandler)
httpd.serve_forever()
@ -27,19 +26,3 @@ class WeatherHandler(BaseHTTPRequestHandler):
self.end_headers()
if response_body is not None:
self.wfile.write(response_body)
@cache
def weather_handler(date: str):
print(date)
coordinates = [48.712, 44.514]
url = (
"https://api.open-meteo.com/v1/forecast?latitude="
+ str(coordinates[0])
+ "&longitude="
+ str(coordinates[1])
+ "&current=temperature_2m,wind_speed_10m&hourly=temperature_2m,relative_humidity_2m,wind_speed_10m"
)
raw_data = urllib.request.urlopen(url).read()
# print(raw_data)
return raw_data

View File

@ -0,0 +1,16 @@
from functools import cache
import urllib.request
@cache
def weather_handler(date: str):
print(date)
coordinates = [48.712, 44.514]
url = (
"https://api.open-meteo.com/v1/forecast?latitude="
+ str(coordinates[0])
+ "&longitude="
+ str(coordinates[1])
+ "&current=temperature_2m,wind_speed_10m&hourly=temperature_2m,relative_humidity_2m,wind_speed_10m"
)
raw_data = urllib.request.urlopen(url).read()
return raw_data