Skip to content

Commit

Permalink
QA 2 (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
aschuma authored Jan 27, 2018
1 parent 6e19116 commit 3466703
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 19 deletions.
59 changes: 43 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,58 @@ c$$$cc$$$c $$$ $$$$$$c $$ Y$c$$$c$P $$"""" $$""""
```
# Tweets air quality measurement results of particulate matter (Feinstaub) (http://luftdaten.info)

This is the source code of a Twitter bot that monitors particulate matter (Feinstaub) for a single
sensor of the http://luftdaten.info network. A tweet is published in case the PM10 particulate matter
exceeds a configurable value, e.g. 50 µg/m³.

## config
A tweet might look like this:
```
#feinstaub #feinstaubalarm #bot
⚠ PM10: 68.07g/m,³ PM2.5: 41.87µg/m³, 5.50°C, RH:96.00%
http://deutschland.maps.luftdaten.info/#13/48.8066/9.2372
```

Set your Twitter credentials in config.py.
Set your sensor meta data in config.py.
This repository provides a cron job written in python 3. After a tweet submission no further tweets
are created for a configurable period.

(see config.py-template for example)

## run as cron
# Installation

add to your crontab:
- Create a twitter account, obtain an access token, see https://developer.twitter.com/en/docs/basics/authentication/guides/access-tokens for further details.
- Make sure python 3 is installed on your dev machine.
- Clone this repository
- Create a virtual environment, e.g. you may obtain more information about those steps here: http://docs.python-guide.org/en/latest/dev/virtualenvs/
```
virtualenv venv -p /usr/bin/python3
source venv/bin/activate
pip3 install -r requirements.txt
```
- Copy the file ```config.py-template``` to ```config.py```, adjust the setup. At least you should alter the following values as starting point.

```
*/15 * * * * cd /home/pi/projects/aschuma__luftdaten_tweet && venv/bin/python tweet.py > /dev/null 2>&1
```

## virtualenv
# Your PM sensor ID
conf_particle_sensor_id = 4711
# Your temperature sensor ID
conf_temperature_sensor_id = 4711
# The URL pointing to the location of your sensor
conf_luftdaten_map_url = "http://deutschland.maps.luftdaten.info/#13/48.8066/9.2372"
# The name of your twitter account
conf_twitter_user_id = 'my-account'
# Credentials provided by twitter
consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''
```
cp config.py-template config.py
# edit config.py
virtualenv venv -p /usr/bin/python3
source venv/bin/activate
pip3 install -r requirements.txt
python tweet.py
- Setup a cron job

```
*/15 * * * * cd /home/pi/projects/aschuma__luftdaten_tweet && venv/bin/python tweet.py > /dev/null 2>&1
```

# Contribution
Please feel free to issue a bug report or create a PR. Any helping hand is welcome.

Be aware that my primary coding language is Java. So currently some code portions might not follow python best practices.
6 changes: 3 additions & 3 deletions tweet.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ def may_tweet_again():
if pm_10_0 is not None and pm_2_50 is not None and float(pm_10_0) > conf_limit_pm_10_0:
current_time = strftime("%Y-%m-%d %H:%M:%S UTC", gmtime())

message = "{} #{}\n⚠ PM10: {}g/m,³ PM2.5: {}µg/m³, {}°C, RH:{}%\n{}\n".format(
message = "{}\n⚠ PM10: {}g/m,³ PM2.5: {}µg/m³, {}°C, RH:{}%\nDetails: {}\nThis is a #{}, code available on github aschuma/air_tweets\n".format(
conf_twitter_msg_preamble,
conf_twitter_tag_bot,
pm_10_0,
pm_2_50,
temperature,
humidity,
conf_luftdaten_map_url
conf_luftdaten_map_url,
conf_twitter_tag_bot
)

print(message)
Expand Down

0 comments on commit 3466703

Please sign in to comment.