41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
import json
|
|
|
|
import requests
|
|
from bs4 import BeautifulSoup
|
|
|
|
|
|
def tmp():
|
|
r = requests.get('https://portal.opendata.dk/api/3/action/datastore_search?resource_id=b3eeb0ff-c8a8-4824-99d6-e0a3747c8b0d')
|
|
with open('traffic_data_13_23.json', 'w') as f:
|
|
json.dump(r.json(), f)
|
|
|
|
|
|
def read_tmp():
|
|
with open('traffic_data_13_23.json') as f:
|
|
data = json.load(f)
|
|
number = sum([cars['vehicleCount'] for cars in data['result']['records']])
|
|
print(number / len(data['result']['records']))
|
|
|
|
|
|
|
|
|
|
def scrape_weather():
|
|
r = requests.get('https://weather.com/weather/hourbyhour/l/99546:4:US')
|
|
soup = BeautifulSoup(r.content)
|
|
print(soup.find_all('td', {'class': 'temp'})[0])
|
|
|
|
def scrape_dmi_aarhus():
|
|
r = requests.get('https://www.dmi.dk/NinJo2DmiDk/ninjo2dmidk?cmd=obj&wmo=06074')
|
|
data = r.json()
|
|
latest_time, aarhus_latest_temp = max(data['Temperature2m'].items(), key= lambda x : x[0])
|
|
|
|
adak_r = requests.get('https://www.dmi.dk/NinJo2DmiDk/ninjo2dmidk?cmd=llj&id=5878818')
|
|
adak_data = adak_r.json()
|
|
adak_temp_latest = adak_data['timeserie'][0]['temp']
|
|
if aarhus_latest_temp-5 < adak_temp_latest:
|
|
return 1.0
|
|
return 0.0
|
|
#adak_latest_time, adak_latest_temp_aarhus = max(adak_timeserie.items(), key= lambda x : x[0])
|
|
|
|
|
|
read_tmp() |