Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
miroslav.suvada committed Apr 4, 2020
1 parent e5adb3f commit 4a19ee1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/pythonapp.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: get_weather.py
name: Python lint

on:
push:
branches: [ master ]
paths:
- '**.py'
pull_request:
branches: [ master ]
paths:
- '**.py'

jobs:
build:

runs-on: ubuntu-latest
env:
working_directory: ./open-weather/app
OPENWEATHER_API_KEY: ${{ secrets.OPENWEATHER_API_KEY }}
CITY_NAME: "Honolulu"
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
Expand All @@ -24,7 +29,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r ./open-weather/app/requirements.txt
pip install -r requirements.txt
- name: Lint with flake8
run: |
pip install flake8
Expand All @@ -35,4 +40,4 @@ jobs:
- name: Test with pytest
run: |
pip install pytest
pytest ./open-weather/app/get_weather.py
pytest
22 changes: 15 additions & 7 deletions open-weather/app/get_weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
import pyowm
import re


class EmptyValue(Exception):
pass


class InvalidFormat(Exception):
pass


try:
key = os.environ['OPENWEATHER_API_KEY']
key_valid = re.match('\w{32}', key)
key_valid = re.match(r'\w{32}', key)
if len(key) == 0:
raise EmptyValue('Environment varialbe OPENWEATHER_API_KEY is empty.')
if not key_valid:
Expand All @@ -31,13 +35,17 @@ class InvalidFormat(Exception):
exit('Undefined environment variable CITY_NAME.')

owm = pyowm.OWM(key)
if owm.is_API_online() == True:
if owm.is_API_online():
observation = owm.weather_at_place(city)
location = observation.get_location().get_name()
weather = observation.get_weather()
location = observation.get_location().get_name()
weather = observation.get_weather()
description = weather.get_detailed_status()
temperature = weather.get_temperature()['temp']
humidity = weather.get_humidity()
print(f'source=openweathermap, city="{city}", description="{description}", temp={temperature}, humidity={humidity}')
humidity = weather.get_humidity()
print(f'source=openweathermap,'
' city="{city}",'
' description="{description}",'
' temp={temperature},'
' humidity={humidity}')
else:
exit('API not online.')
exit('API not online.')

0 comments on commit 4a19ee1

Please sign in to comment.