From 9ace5e126040d401f619ec71381c39393a8fbd6b Mon Sep 17 00:00:00 2001 From: Riku Silvennoinen Date: Wed, 18 Oct 2023 09:39:06 +0300 Subject: [PATCH] Delete script.py --- script.py | 63 ------------------------------------------------------- 1 file changed, 63 deletions(-) delete mode 100644 script.py diff --git a/script.py b/script.py deleted file mode 100644 index bea7754..0000000 --- a/script.py +++ /dev/null @@ -1,63 +0,0 @@ -import pandas as pd -from geopy.distance import geodesic -import requests -import subprocess -import time -from datetime import datetime -import os - -cmd = 'nginx' -os.system(cmd) - -while True: - - # Muuta seuraavat parametrit tarpeen mukaan - LATITUDE = "61.4981" - LONGITUDE = "23.7608" - MAX_RESULTS = 8 - - # Lataa maailman kaupunkien tietokanta - world_cities = pd.read_csv('https://download.geonames.org/export/dump/cities15000.zip', sep='\t', header=None, encoding='utf-8', low_memory=False) - world_cities.columns = ['geonameid', 'name', 'asciiname', 'alternatenames', 'latitude', 'longitude', 'feature_class', 'feature_code', 'country_code', 'cc2', 'admin1_code', 'admin2_code', 'admin3_code', 'admin4_code', 'population', 'elevation', 'dem', 'timezone', 'modification_date'] - - # Laske etäisyys ja valitse lähimmät kaupungit - world_cities['distance'] = world_cities.apply(lambda row: geodesic((LATITUDE, LONGITUDE), (row['latitude'], row['longitude'])).km, axis=1) - nearest_cities = world_cities.nsmallest(MAX_RESULTS, 'distance') - - # Hae säätiedot wttr.in-sivustolta curl-komennolla - weather_data_list = [] - cities_to_fetch = ["Death_valley", "London", "Sydney", "Oimjakon"] - for city_name in cities_to_fetch: - url = f"https://wttr.in/{city_name}?format=%l:+%c+%t+%h+%P+%w+%p+%S+%s" - response = requests.get(url) - weather_data = response.text.strip() - weather_data_list.append(weather_data) - - #Kello - current_time = datetime.now() - formatted_time = current_time.strftime("%H:%M") - - # Tulosta lähimpien kaupunkien nimet ja säätiedot - with open("/var/www/html/index_TEMP.html", "w") as f: # Avaa tiedosto kirjoitustilassa - f.write('\n') - f.write('\n') - f.write(f"

Sää tiedot klo:{formatted_time}, {MAX_RESULTS} lähintä kaupunkia.

\n") - - for index, city in nearest_cities.iterrows(): - if not pd.isnull(city['name']): - url = f"https://wttr.in/{city['name']}?format=%l:+%c+%t+%h+%P+%w+%p+%S+%s" - response = requests.get(url) - weather_data = response.text.strip() - city_name = city['name'] - f.write(f"

{weather_data}

") # Kirjoita tiedostoon säätiedot - - # Kirjoita muutaman kaupungin säätiedot tiedostoon - f.write(f"

Muutama kylmä ja kuuma kaupunki

\n") - for weather_data in weather_data_list: - f.write(f"

{weather_data}

\n") - - # Siirrä temp-tiedosto lopulliseen tiedostoon - cmd = 'mv /var/www/html/index_TEMP.html /var/www/html/index.html' - os.system(cmd) - - time.sleep(60) # Odota 1 minuutti ennen seuraavaa hakuajoa