-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_settings.py
More file actions
68 lines (54 loc) · 2.67 KB
/
user_settings.py
File metadata and controls
68 lines (54 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# -*- coding: utf-8 -*-
import os
# Get user settings set as environment variables. All read in as str. Set environment variables in dokku according to http://dokku.viewdocs.io/dokku/configuration/environment-variables/
databaseUrl = os.environ.get('DATABASE_URL')
# Keys. If named item doesn't exist, var = None.
header_key = os.environ.get('HEADER_KEY')
openWeatherApiKey = os.environ.get('OPENWEATHER_API_KEY')
# OpenWeather API settings
timezone = os.environ.get('APP_TIMEZONE')
latitude = os.environ.get('LAT')
longitude = os.environ.get('LONG')
lang = os.environ.get('LANG')
# Display settings
defaultTimeRange = os.environ.get('DEFAULT_TIME_RANGE')
showDailyForecast = os.environ.get('SHOW_DAILY_FORECAST')
showHourlyForecast = os.environ.get('SHOW_HOURLY_FORECAST')
# Other
loadHistoricalData = os.environ.get('LOAD_HISTORICAL_DATA')
# Validate settings.
if not openWeatherApiKey:
print('no OpenWeather API key provided. Official outside weather info will not be displayed')
if not header_key:
print("no PurpleAir POST header key provided. Database will have increased vulnerability to insertion attacks from unverified POST sources. Add header key on the PurpleAir 'Modify registration' form at https://www.purpleair.com/register according to https://www.keycdn.com/support/custom-http-headers")
if not timezone:
raise Exception(
"Timezone not provided. Please set environment variable APP_TIMEZONE according to the sensor's location and https://pvlib-python.readthedocs.io/en/stable/timetimezones.htm")
if not latitude or not longitude:
raise Exception(
"Latitude or longitude not provided. Please set environment variables LAT and LONG to the sensor's location.")
if not lang:
print('defaulting to weather info in English. See other language options at https://openweathermap.org/api/one-call-api#data')
lang = 'en'
if not defaultTimeRange:
print('defaulting to showing 3 days of data')
defaultTimeRange = '3 days'
if showDailyForecast == 'True':
showDailyForecast = True
elif showDailyForecast == 'False':
showDailyForecast = False
else:
print('defaulting to showing daily forecast')
showDailyForecast = True
if showHourlyForecast == 'True':
showHourlyForecast = True
elif showHourlyForecast == 'False':
showHourlyForecast = False
else:
print('defaulting to not showing hourly forecast')
showHourlyForecast = False
if loadHistoricalData == 'True':
print('loading historical sensor data. Not recommended to leave this setting permanently on due to process intensity. Run during first setup or when you know data has not saved to your database (WiFi down, etc)')
loadHistoricalData = True
else:
loadHistoricalData = False