Skip to content
This repository has been archived by the owner on Dec 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #40 from BrianMitchL/updates
Browse files Browse the repository at this point in the history
Updates
  • Loading branch information
BrianMitchL committed Jan 5, 2019
2 parents 9aa467f + 4825b82 commit 7423c65
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 27 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
dist: xenial
language: python
python:
- '3.4'
- '3.5'
- '3.6'
- '3.7'
install:
- pip install -r requirements.txt
- pip install -r requirements-dev.txt
Expand Down
52 changes: 51 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# weatherBot [![GitHub release](https://img.shields.io/github/release/BrianMitchL/weatherBot.svg?maxAge=86400)](https://github.com/BrianMitchL/weatherBot/releases/latest) [![Python Version](https://img.shields.io/badge/python-3.4+-blue.svg)](https://www.python.org) [![Build Status](https://travis-ci.org/BrianMitchL/weatherBot.svg?branch=master)](https://travis-ci.org/BrianMitchL/weatherBot) [![Coverage Status](https://coveralls.io/repos/github/BrianMitchL/weatherBot/badge.svg?branch=master)](https://coveralls.io/github/BrianMitchL/weatherBot?branch=master) [![Dependency Status](https://gemnasium.com/badges/github.com/BrianMitchL/weatherBot.svg)](https://gemnasium.com/github.com/BrianMitchL/weatherBot)
# weatherBot [![GitHub release](https://img.shields.io/github/release/BrianMitchL/weatherBot.svg?maxAge=86400)](https://github.com/BrianMitchL/weatherBot/releases/latest) [![Python Version](https://img.shields.io/badge/python-3.4+-blue.svg)](https://www.python.org) [![Build Status](https://travis-ci.org/BrianMitchL/weatherBot.svg?branch=master)](https://travis-ci.org/BrianMitchL/weatherBot) [![Coverage Status](https://coveralls.io/repos/github/BrianMitchL/weatherBot/badge.svg?branch=master)](https://coveralls.io/github/BrianMitchL/weatherBot?branch=master)

A Twitter bot for weather. [Powered by Dark Sky](https://darksky.net/poweredby/).

Expand Down Expand Up @@ -112,6 +112,56 @@ docker build -t weatherbot .
```
Start the bot using the same run command as above, while replacing the image name with what you call yours.

## Task Runner

The following tasks are available through `invoke`.

- `invoke lint`
```text
Docstring:
Use PyLint to check for errors and enforce a coding standard.
This will, by default, use the PyLint configuration found in '.pylintrc',
but can accept a different path.
Options:
-e STRING, --extra=STRING Extra Python files to lint in addition to the
default.
-p STRING, --pylintrc=STRING Path to a pylintrc file for configuring
PyLint.
```
- `invoke clean`
```text
Docstring:
Clean (delete) files. If passed with no arguments, nothing is deleted.
Options:
-b, --bytecode Remove bytecode files matching the pattern
'**/*.pyc'.
-c, --cache Remove the '.wbcache.p' file.
-e STRING, --extra=STRING Remove any extra files passed in here.
```
- `invoke validateyaml`
```text
Docstring:
Use yamllint to check for errors and enforce a markup standard for the strings YAML file.
By default this will use the '.yamllint' config file to validate 'strings.yml'.
Options:
-f STRING, --filename=STRING Path to the strings YAML file to validate.
-y STRING, --yamllintrc=STRING Path to a yamllintrc file for configuring
PyLint.
```
- `invoke test`
```text
Docstring:
Runs tests and reports on code coverage.
Keys need to be entered in 'keys.py' or set as environmental variables.
Options:
-r, --report Flag to print a coverage report
```

## Tools Used
* [Tweepy](https://github.com/tweepy/tweepy)
* [Dark Sky API](https://darksky.net/poweredby/)
Expand Down
10 changes: 5 additions & 5 deletions keys.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
weatherBot keys
Copyright 2015-2018 Brian Mitchell under the MIT license
Copyright 2015-2019 Brian Mitchell under the MIT license
See the GitHub repository: https://github.com/BrianMitchL/weatherBot
"""

Expand All @@ -19,10 +19,10 @@

def set_twitter_env_vars():
"""
If no Twitter environmental variables are set, set them based on the keys dict
If any of the Twitter environmental variables are not set, set them based on the keys dict
"""
if os.getenv('WEATHERBOT_CONSUMER_KEY', 0) is 0 or os.getenv('WEATHERBOT_CONSUMER_SECRET', 0) is 0 \
or os.getenv('WEATHERBOT_ACCESS_TOKEN', 0) is 0 or os.getenv('WEATHERBOT_ACCESS_TOKEN_SECRET', 0) is 0:
if os.getenv('WEATHERBOT_CONSUMER_KEY') is None or os.getenv('WEATHERBOT_CONSUMER_SECRET') is None \
or os.getenv('WEATHERBOT_ACCESS_TOKEN') is None or os.getenv('WEATHERBOT_ACCESS_TOKEN_SECRET') is None:
os.environ['WEATHERBOT_CONSUMER_KEY'] = KEYS['consumer_key']
os.environ['WEATHERBOT_CONSUMER_SECRET'] = KEYS['consumer_secret']
os.environ['WEATHERBOT_ACCESS_TOKEN'] = KEYS['access_token']
Expand All @@ -33,5 +33,5 @@ def set_darksky_env_vars():
"""
If no Dark Sky environmental variable is set, set it based on the keys dict
"""
if os.getenv('WEATHERBOT_DARKSKY_KEY', 0) is 0:
if os.getenv('WEATHERBOT_DARKSKY_KEY') is None:
os.environ['WEATHERBOT_DARKSKY_KEY'] = KEYS['darksky_key']
3 changes: 1 addition & 2 deletions models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
weatherBot models
Copyright 2015-2018 Brian Mitchell under the MIT license
Copyright 2015-2019 Brian Mitchell under the MIT license
See the GitHub repository: https://github.com/BrianMitchL/weatherBot
"""

Expand All @@ -23,7 +23,6 @@ class BadForecastDataError(Exception):
"""
Designed to be thrown when a Forecast object contains issues that would render the weather data unusable
"""
pass


class WeatherLocation:
Expand Down
10 changes: 5 additions & 5 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
testfixtures>=6.0.1,<7.0
invoke>=0.22.1,<1.0
pylint>=1.8.4,<2.0
yamllint>=1.11.1,<2.0
coverage>=4.5.1,<5.0
testfixtures>=6.4.1,<7
invoke>=1.2.0,<2
pylint>=2.2.2,<3
yamllint>=1.13.0,<2
coverage>=4.5.2,<5
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tweepy>=3.6.0,<4.0
python-forecastio>=1.4.0,<2.0
pytz>=2018.4
PyYAML>=3.12,<4.0
tweepy>=3.7.0,<4
python-forecastio>=1.4.0,<2
pytz>=2018.7
PyYAML>=4.2b4,<5
2 changes: 1 addition & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
weatherBot tests
Copyright 2015-2018 Brian Mitchell under the MIT license
Copyright 2015-2019 Brian Mitchell under the MIT license
See the GitHub repository: https://github.com/BrianMitchL/weatherBot
"""

Expand Down
13 changes: 6 additions & 7 deletions utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
weatherBot utils
Copyright 2015-2018 Brian Mitchell under the MIT license
Copyright 2015-2019 Brian Mitchell under the MIT license
See the GitHub repository: https://github.com/BrianMitchL/weatherBot
"""

Expand All @@ -14,7 +14,6 @@

class InvalidTimeError(Exception):
"""Designed to be thrown when parsing a bad str for creating a Time namedtuple"""
pass


def get_units(unit):
Expand All @@ -40,7 +39,7 @@ def get_units(unit):
'pressure': 'mb',
'visibility': 'mi'
}
elif unit == 'ca':
if unit == 'ca':
return {
'unit': 'ca',
'nearestStormDistance': 'km',
Expand All @@ -56,7 +55,7 @@ def get_units(unit):
'pressure': 'hPa',
'visibility': 'km'
}
elif unit == 'uk2':
if unit == 'uk2':
return {
'unit': 'uk2',
'nearestStormDistance': 'mi',
Expand Down Expand Up @@ -195,11 +194,11 @@ def precipitation_intensity(precip_intensity, unit):

if precip_intensity >= intensities[unit]['heavy'][1]:
return intensities[unit]['heavy'][0]
elif precip_intensity >= intensities[unit]['moderate'][1]:
if precip_intensity >= intensities[unit]['moderate'][1]:
return intensities[unit]['moderate'][0]
elif precip_intensity >= intensities[unit]['light'][1]:
if precip_intensity >= intensities[unit]['light'][1]:
return intensities[unit]['light'][0]
elif precip_intensity >= intensities[unit]['very-light'][1]:
if precip_intensity >= intensities[unit]['very-light'][1]:
return intensities[unit]['very-light'][0]
return 'none'

Expand Down
4 changes: 2 additions & 2 deletions weatherBot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
weatherBot
Copyright 2015-2018 Brian Mitchell under the MIT license
Copyright 2015-2019 Brian Mitchell under the MIT license
See the GitHub repository: https://github.com/BrianMitchL/weatherBot
"""
# pylint: disable=global-statement,invalid-name
Expand Down Expand Up @@ -186,7 +186,7 @@ def get_location_from_user_timeline(username, fallback):
logging.debug('Found %s: %f, %f', name, lat, lng)
return models.WeatherLocation(lat=lat, lng=lng, name=name)
# if the location is a place, not coordinates
elif tweet.place is not None:
if tweet.place is not None:
point = utils.centerpoint(tweet.place.bounding_box.coordinates[0])
lat = point[0]
lng = point[1]
Expand Down

0 comments on commit 7423c65

Please sign in to comment.