-
Notifications
You must be signed in to change notification settings - Fork 0
/
scheduler.py
34 lines (26 loc) · 917 Bytes
/
scheduler.py
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
import sqlalchemy as db
from api import Weather
from sender import Email
import os
from dotenv import load_dotenv
load_dotenv()
endpoint = os.getenv('OPENWEATHER_ENDPOINT')
openw_api_key = os.getenv('OPENWEATHER_APIKEY')
sendgrid_api_key = os.getenv('SENDGRID_API_KEY')
sender = os.getenv('SENDER_EMAIL')
engine = db.create_engine(os.getenv('DATABASE_URL'), echo=True)
connection = engine.connect()
metadata = db.MetaData()
users = db.Table('User', metadata, autoload=True, autoload_with=engine)
query = db.select([users])
result = connection.execute(query)
result_list = result.fetchall()
result_dict = [{
'email': row[1],
'location': row[2],
'lat': row[3].split(' ')[0],
'lon': row[3].split(' ')[1]} for row in result_list]
for single in result_dict:
my_weather = Weather(endpoint, openw_api_key, single['lat'], single['lon'])
forecast = my_weather.getResponse()
print(forecast)