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

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: BrianMitchL/weatherBot
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.2.2
Choose a base ref
...
head repository: BrianMitchL/weatherBot
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Loading
Showing with 481 additions and 200 deletions.
  1. +10 −4 .travis.yml
  2. +46 −0 CODE_OF_CONDUCT.md
  3. +9 −7 CONTRIBUTING.md
  4. +51 −44 README.md
  5. +5 −5 keys.py
  6. +1 −2 models.py
  7. +5 −5 requirements-dev.txt
  8. +4 −4 requirements.txt
  9. +1 −1 runtime.txt
  10. +19 −0 strings.yml
  11. +1 −1 tasks.py
  12. +132 −99 test.py
  13. +150 −0 test_helpers.py
  14. +6 −7 utils.py
  15. +3 −0 weatherBot.conf
  16. +38 −21 weatherBot.py
14 changes: 10 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
dist: xenial
language: python
python:
- '3.3'
- '3.4'
- '3.5'
- '3.6'
- '3.7'
- '3.8'
- '3.9'
install:
- pip install -r requirements.txt
- pip install -r requirements-dev.txt
- pip install coveralls
before_script:
- invoke lint && invoke validate_yaml
- invoke lint && invoke validateyaml
script:
- invoke test
after_success:
@@ -20,6 +21,11 @@ deploy:
"latest"}'' https://registry.hub.docker.com/u/brianmitchl/weatherbot/trigger/$DOCKER_HUB_TOKEN/'
on:
branch: master
branches:
only:
- development
- master
- /^v\d+\.\d+(\.\d+)?(-\S*)?$/
env:
global:
- secure: Httle2zpXRyVPIdRZ2XE9WwdhdTicZBi7vltamQczSoiKK5MLquE9gUS5Vnyfs+8v58IiJdyfaRt2QG/03a3hf9F95BnVt00zWZKHLDpNgfDwRd1JMxIE+4ey+bcNVbcqNwQ7HvNcdknrV1NvBhkTtB5AUWKD3IK3fne7ziX0u0=
46 changes: 46 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at bman4789@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
16 changes: 9 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -10,13 +10,13 @@ pip3 install -r requirements.txt
pip3 install -r requirements-dev.txt
```

Unless your contribution is an urgent bugfix or critical fix, contributions must be committed in a topic branch based on `development`. `git checkout -b my_contribution development`
Contributions must be committed in a topic branch based on `development`. `git checkout -b my_contribution development`

## Linting/Validating

### Python Code

It is required that all code will pass a lint and validation test. I (@BrianMitchL), have made exceptions for some cases in the existing code, but this should be kept to a minimum.
It is required that all code will pass a lint and validation test. Some exceptions can be made, but this should be kept to a minimum.

Code must conform to [PEP8](https://www.python.org/dev/peps/pep-0008/), but ultimately the linter.
Here are the important things:
@@ -28,31 +28,33 @@ Here are the important things:
5. Use underscores to separate variable names vs camel-case. (Yes, I know this contradicts the name _weatherBot_)

Lint your code with the following:
```shell
```sh
invoke lint
```

If you are adding a new Python file, run `invoke lint --extra=newfile.py`

### Strings.yml

Mind the 140 character limit that Twitter enforces.
Mind the 140 character limit that Twitter enforces. Anything over 140 characters will be truncated.

Emoji must be escaped until the PyYAML libary is updated (https://github.com/yaml/pyyaml/issues/25).

If you are contributing to the `strings.yml` file, you must validate the file by running:
```shell
invoke validate_yaml
```

If you are creating new strings files of your own, run `invoke validate_yaml --filename=filename.yml`
If you are creating new strings files of your own, run `invoke validate_yaml --filename=filename.yml`.

## Testing
Tests have been written for nearly all of the non-looping/logic code. It is expected to add tests for your contributions (with the exception of adding new text to `strings.yml`). Tests must be run using environmental variables. To set the environmental variables per command, prepend the command with the followig, replacing `xxxx` with your keys.
Tests have been written for nearly all of the non-looping/logic code. It is expected to add tests for your contributions (with the exception of adding new text to `strings.yml`). Tests must be run using environmental variables. To set the environmental variables per command, prepend the command with the following, replacing `xxxx` with your keys.

```sh
WEATHERBOT_CONSUMER_KEY=xxxx WEATHERBOT_CONSUMER_SECRET=xxxx WEATHERBOT_ACCESS_TOKEN=xxxx WEATHERBOT_ACCESS_TOKEN_SECRET=xxxx WEATHERBOT_DARKSKY_KEY=xxxx your_command_here
```

```shell
```sh
invoke test
# For a coverage report
invoke test --report
95 changes: 51 additions & 44 deletions 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.3+-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.6+-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/).

@@ -36,7 +36,7 @@ pip3 install -r requirements-dev.txt
```

## Use
weatherBot.py has been built for Python 3 (tested with 3.3 and above). Legacy Python is not supported.
weatherBot.py has been built for Python 3 (tested with 3.6 and above). Legacy Python is not supported.

1. Set your location and other settings in `weatherBot.conf`
2. Set your API keys and secrets as environmental variables (recommended) or in `keys.py`
@@ -49,7 +49,8 @@ You're all set!
## Settings and Customizing

### Configuration File
Many features of weatherBot can be customized in a conf file. This ships with a file named `weatherBot.conf`, but can be called whatever you'd like. Each option has a comment above it describing its purpose.
Many features of weatherBot can be customized in a conf file, using the [INI](https://en.wikipedia.org/wiki/INI_file) configuration format. This ships with a file named `weatherBot.conf`, but can be called whatever you'd like. Each option has a comment above it describing its purpose. By default, each option is commented out with a semi-colons (`;`). This shows the default value and provides an example of a valid configuration.

If you want a clean conf file, feel free to remove all but the settings you set, they are all optional. The section headers must remain in the file.

### API Keys
@@ -61,56 +62,62 @@ The language as well as the text used for all tweets can be edited or added in `

### Variable Location
Enable variable location to have the location for weather change. The Twitter username in the variable location user setting will be used to determine this location. The specified user must tweet with location fairly regularly (at least every 20 tweets, not including retweets), or the manually entered location will be used. The most recent tweet with a location will be used to get the location for weather.
For example, say the given user tweets from Minneapolis, MN one day. Minneapolis will be used as the location indefinitely until a new tweet with location is posted or if 20 new tweets have been posted that do not contain a location. weatherBot checked the user's timeline every 30 minutes for updated in location.
For example, say the given user tweets from Minneapolis, MN one day. Minneapolis will be used as the location indefinitely until a new tweet with location is posted or if 20 new tweets have been posted that do not contain a location. weatherBot checks the user's timeline every 30 minutes for updates in location.
The human readable Twitter location will also be added to the beginning of each tweet. For example, in the same case as earlier, "Minneapolis, MN: " would be prefixed to every tweet.

## Deploying to [Heroku](https://www.heroku.com/)
weatherBot can easily be deployed to Heroku. Install the heroku-toolbelt and run the following to get started:
```shell
heroku login
heroku create
git push heroku master
```
The Twitter and Dark Sky keys need to be added. The format to do so is:
```shell
heroku config:set \
WEATHERBOT_CONSUMER_KEY=xxx \
WEATHERBOT_CONSUMER_SECRET=xxx \
WEATHERBOT_ACCESS_TOKEN=xxx \
WEATHERBOT_ACCESS_TOKEN_SECRET=xxx \
WEATHERBOT_DARKSKY_KEY=xxx
```
You can also add keys/environmental variables on the Heroku project's settings page.
## Deploying

## Deploying with Docker
Head over to the [wiki](https://github.com/BrianMitchL/weatherBot/wiki#deploying) for some examples of deploying weatherBot.

weatherBot can easily be deployed using Docker.
## Task Runner

### weatherBot from Docker Hub
The following tasks are available through `invoke`.

To download the image, run:
```shell
docker pull brianmitchl/weatherbot
```
Start the bot with the following, replacing the API keys and secrets with the correct strings. You will also need to add your conf file to the container (I use the `-v` flag).
```shell
docker run --name weatherBot -d \
-v /home/brianmitchell/weatherBot/dist/custom.conf:/src/custom.conf \
-e WEATHERBOT_CONSUMER_KEY=xxx \
-e WEATHERBOT_CONSUMER_SECRET=xxx \
-e WEATHERBOT_ACCESS_TOKEN=xxx \
-e WEATHERBOT_ACCESS_TOKEN_SECRET=xxx \
-e WEATHERBOT_DARKSKY_KEY=xxx \
brianmitchl/weatherbot python weatherBot.py custom.conf
```
- `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.
### Building Your Own weatherBot
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.
Alternatively, if you wish to build the Docker image yourself, run:
```shell
docker build -t weatherbot .
```
Start the bot using the same run command as above, while replacing the image name with what you call yours.
- `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)
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-2016 Brian Mitchell under the MIT license
Copyright 2015-2019 Brian Mitchell under the MIT license
See the GitHub repository: https://github.com/BrianMitchL/weatherBot
"""

@@ -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']
@@ -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-2016 Brian Mitchell under the MIT license
Copyright 2015-2019 Brian Mitchell under the MIT license
See the GitHub repository: https://github.com/BrianMitchL/weatherBot
"""

@@ -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:
10 changes: 5 additions & 5 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
testfixtures>=4.13.5,<5.0
invoke>=0.15.0,<1.0
pylint>=1.7.1,<2.0
yamllint>=1.6.1,<2.0
coverage>=4.3.4,<5.0
testfixtures>=6.17.1,<7
invoke>=1.5.0,<2
pylint==2.8.0
yamllint==1.26.1
coverage>=5.5,<6
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tweepy>=3.5.0,<4.0
python-forecastio>=1.3.5,<2.0
pytz>=2017.2
PyYAML>=3.12,<4.0
tweepy==3.10.0
python-forecastio==1.4.0
pytz>=2020.4
PyYAML==5.4.1
2 changes: 1 addition & 1 deletion runtime.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python-3.5.2
python-3.7.2
Loading