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 #42 from BrianMitchL/development
Browse files Browse the repository at this point in the history
Release v3.0.1
  • Loading branch information
BrianMitchL authored Jan 5, 2019
2 parents 09addd4 + cd9ab18 commit f264b2e
Show file tree
Hide file tree
Showing 10 changed files with 96 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
19 changes: 19 additions & 0 deletions strings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ forecast_endings:
- "\U0001f44c"
- "\U0001f4af"
- "\U0001f44c\U0001f4af"
- "It's going to be great!"
- "Oh joy \U0001f644"
# use 'temp', 'summary', or 'location'
normal_conditions:
- "{temp} and {summary}. \U0001f937"
Expand Down Expand Up @@ -64,12 +66,21 @@ normal_conditions:
- "Only in {location} would it be {temp} and {summary} right now."
- "I hope you like that it's {summary}. It's {temp}."
- "{summary} and {temp}. \U0001f4af\U0001f4af\U0001f4af"
- "My word, it's {summary} and {temp}."
- "It's {summary} and {temp}. Don't forget to like, comment, and subscribe."
- "Can you believe it's {temp} and {summary}?"
- "It's {summary} and {temp}. Cheers, mate."
- "It's {temp} and {summary}. Finally!"
- "Good grief, it's {temp} and {summary}."
# use 'apparent_temp', 'temp', 'wind_speed', 'wind_bearing', 'humidity',
# 'summary', or 'location'
special_conditions:
wind-chill: # wind chill at or below -30F or -34C
- "Brr! The windchill is {apparent_temp} and the wind is blowing at
{wind_speed} from the {wind_bearing}. Stay safe out there!"
- "Even though it feels like {apparent_temp}, it's actually only {temp}."
- "It's cold out there! The windchill is {apparent_temp} and the wind is blowing at
{wind_speed} from the {wind_bearing}."
medium-wind:
- "Looks like we've got some medium wind at {wind_speed} coming from
the {wind_bearing}."
Expand All @@ -86,12 +97,16 @@ special_conditions:
cold: # below -28C or -20F
- "It's {temp}. Too cold."
- "It's a wee bit chilly. {temp} \U0001f643"
- "Stupid polar vortex making things all cold, it's {temp}!"
- "It's {temp}. Just put a hat on, you'll be fine."
super-hot: # over 110F or 43C
- "Wowowowowowowowow, it's {temp}. I need some A/C ASAP."
- "\U0001f525\U0001f525\U0001f525 \U0001f635"
hot: # over 100F or 37C
- "Holy moly it's {temp}. I could literally (figuratively) melt."
- "\U0001f321 It's {temp}!"
- "We did it, it's {temp}!"
- "High five for climate change! It's {temp}."
dry: # humidity under 25%
- "{temp} with {humidity}% humidity."
- "It's dry as strained pasta. {humidity}% humid right now."
Expand Down Expand Up @@ -119,13 +134,16 @@ precipitations:
- "Light rain. \U0001f326"
- "Light rain. Just think how hydrated all of the plants will be!"
- "Light rain? More like free car wash!"
- "Light rain. At least it's not snowing."
very-light:
- "Drizzlin' yo."
- "Very light rain detected."
- "Hey look, it's drizzling!"
snow:
heavy:
- "Heavy snow, bundle up."
- "Heavy snow detected, good luck with that."
- "Look at the snow, there's so much of it!"
moderate:
- "Alert: there are flakes of crystalline water
ice falling from the clouds."
Expand All @@ -141,6 +159,7 @@ precipitations:
very-light:
- "Flurries"
- "Flurries detected."
- "Hey look, flurries!"
sleet:
heavy:
- "Heavy sleet."
Expand Down
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 f264b2e

Please sign in to comment.