Commit ca6aa21b authored by Martin Vítek's avatar Martin Vítek
Browse files

Add observatin_forecast.py script

parent e39eda3c
#!/bin/python3
import requests
import json
import time
import datetime
from astral import Astral
def calculate_observation(time_from):
if time_from[2] == current_time[2]:
data_start = current_time[3] - forecast_time[3]; # There will be problem after passing midnight
else:
data_start = current_time[3] - forecast_time[3] + 24;
clouds_total = 0
clouds_medium = 0
clouds_low = 0
clouds_high = 0
for i in range(data_start,data_start+4):
clouds_low += data['parameterValues']['CLOUDS_LOW'][i]
clouds_medium += data['parameterValues']['CLOUDS_MEDIUM'][i]
clouds_high += data['parameterValues']['CLOUDS_HIGH'][i]
clouds_total += data['parameterValues']['CLOUDS_TOTAL'][i]
clouds_low = clouds_low / 4.0
clouds_medium = clouds_medium / 4.0
clouds_high = clouds_high / 4.0
clouds_total = clouds_total / 4.0
print('Clouds low:\t%6.2f%%' %(clouds_low*100))
print('Clouds medium:\t%6.2f%%' %(clouds_medium*100))
print('Clouds high:\t%6.2f%%' %(clouds_high*100))
print('Clouds total:\t%6.2f%%' %(clouds_total*100))
possible = True
if clouds_low > 0.15:
possible = False
if clouds_medium > 0.15:
possible = False
if clouds_high > 0.15:
possible = False
if clouds_total > 0.15:
possible = False
if possible:
print("Observation is possible :)")
else:
print("Observation is not possible :(")
### Get Aladin data
longitude = '12.90708333'
latitude = '50.2155833'
url = 'http://aladinonline.androworks.org/get_data.php?latitude='+latitude+'&longitude='+longitude
response = requests.get(url)
data = json.loads(response.text)
## print all json data in readable format
#print(json.dumps(data, sort_keys=True, indent=4))
### Get data for processing
number_of_records = data['forecastLength']
forecast_time = time.strptime(data['forecastTimeIso'], '%Y-%m-%d %H:%M:%S')
current_time = time.localtime();
### Get sunset time
city_name = 'Prague'
a = Astral()
a.solar_depression = 'civil'
city = a[city_name]
sun = city.sun(date=datetime.datetime.now(), local=True)
dusk_time = time.strptime(str(sun['dusk']).split('+')[0], '%Y-%m-%d %H:%M:%S')
next_date = datetime.datetime.now() + datetime.timedelta(days=1)
sun = city.sun(date=next_date, local=True)
next_dusk_time = time.strptime(str(sun['dusk']).split('+')[0], '%Y-%m-%d %H:%M:%S')
### Calculation of observation conditions 4 hours from dusk or 4hours from curent time if > sunset
print('Using forecast from: %s' % str(data['forecastTimeIso']))
print('\nToday observation conditions:')
if current_time[3] >= dusk_time[3]:
if current_time[4] >= dusk_time[4]:
calculate_observation(current_time)
else:
calculate_observation(dusk_time)
else:
calculate_observation(dusk_time)
### Calculation of observation conditions for next day
print('\nToday observation conditions:')
calculate_observation(next_dusk_time)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment