Skip to content

Commit

Permalink
add html
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanVnucec committed Apr 5, 2021
1 parent 047c080 commit c6a432b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
23 changes: 18 additions & 5 deletions forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,27 @@ def get_forecast_today(self):
def construct_forecast_message(self):
subject = f'Rain in Zagreb from {self.rainStartHour}h'

content = ''
html = '<html><body>'
plain = ''
for forecast in self.forecastToday:
hour = str(forecast['h'])
probability = str(round(forecast['p'] * 100))
hourStr = str(forecast['h'])
probStr = str(round(forecast['p'] * 100))

content += f'{hour : <2}h {probability : >3}%\n'
plain += f'{hourStr : <2}h {probStr : >3}%\n'

return subject, content
alpha = forecast['p'] * 0.6
alpha = round(alpha, 2)
bColor = f'hsla(240, 100%, 50%, {alpha})'

if len(hourStr) == 1:
hourStr += ' '

html += f'<span>{hourStr}h </span>'
html += f'<span style="color: rgb(0, 0, 0); background-color: {bColor};">{probStr}%</span><br>'

html += '</body></html>'

return subject, plain, html

def rain_today(self):
return self.rainToday
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
forecast = Forecast(openWeatherApiKey)

if forecast.rain_today():
subject, content = forecast.construct_forecast_message()
subject, content, contentHtml = forecast.construct_forecast_message()

for receiver in receivers:
gmail.send(receiver, subject, content)
gmail.send(receiver, subject, content, contentHtml)
else:
print('INFO: No rain today in Zagreb.')

0 comments on commit c6a432b

Please # to comment.