Skip to content
This repository was archived by the owner on Nov 5, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 3 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ LAMBDA_NAME := check-garbage-day
LAMBDA_HANDLER := refusereminder
LAMBDA_FREQ := 12 hours

BUILD_CONTAINER_NAME := mke-trash-pickup_libs
BUILD_CONTAINER_IMAGE := amazonlinux:latest


venv:
virtualenv -p python$(PYTHON_VERSION) $(VENV_DIR)
Expand All @@ -19,34 +16,13 @@ venv:
deps : venv
$(VENV_DIR)/bin/pip$(PIP_VERSION) install -e .

site-packages :
@docker rm -f $(BUILD_CONTAINER_NAME) >&/dev/null || true
@docker run \
-id \
-v $(shell pwd):/code:ro \
--name $(BUILD_CONTAINER_NAME) \
$(BUILD_CONTAINER_IMAGE)
@docker exec -it $(BUILD_CONTAINER_NAME) yum install -y \
gcc \
libxml2-devel \
libxslt-devel \
python27 \
python27-devel \
python27-pip
@docker exec -it $(BUILD_CONTAINER_NAME) pip install /code
@docker cp \
$(BUILD_CONTAINER_NAME):/usr/local/lib64/python2.7/$@ \
./$@-64
@docker cp \
$(BUILD_CONTAINER_NAME):/usr/local/lib/python2.7/$@ \
./$@
@docker rm -f $(BUILD_CONTAINER_NAME)
.PHONY : version
version : venv
@echo "import mkerefuse; print(mkerefuse.__version__)" | $(VENV_DIR)/bin/python

.PHONY : ldist
ldist : site-packages
zip -r $(LDIST_ZIP) $(LAMBDA_HANDLER).py mkerefuse -x *.pyc
cd site-packages-64 && zip -r $(LDIST_ZIP) *
cd site-packages && zip -r $(LDIST_ZIP) *

.PHONY : s3-bucket
s3-bucket :
Expand Down
76 changes: 53 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ I'm lazy.
## Usage
### CloudFormation

**Important:** To build the [lxml](http://lxml.de/) library for deployment
to AWS Lambda, a Docker container will be employed during the `make ldist`
target.

```sh
# Create the S3 bucket, build the code, deploy to S3
make s3-bucket ldist s3-deploy
Expand All @@ -27,6 +23,7 @@ make cloud \
**Other Variables**

| Name | Default | Description |
| ---- | ------- | ----------- |
| `STACK_NAME` | `mke-trash-pickup` | CloudFormation stack name |
| `DEPLOY_BUCKET` | `mke-trash-pickup-12241` | S3 bucket for .zip deployment (Must be changed) |
| `LAMBDA_FREQ` | `12 hours` | How often the the scheduled event will check for changes |
Expand All @@ -40,30 +37,55 @@ $ mkerefusecheck \
--direction S \
--street 27th \
--street-type st
2016-04-14 20:23:19 - mke-refuse - DEBUG - Parsing arguments
2016-04-14 20:23:19 - mke-refuse - DEBUG - Composing query address
2016-04-14 20:23:19 - mke-refuse - INFO - Executing query...
2016-04-14 20:23:19 - requests.packages.urllib3.connectionpool - INFO - Starting new HTTP connection (1): mpw.milwaukee.gov
2016-04-14 20:23:19 - requests.packages.urllib3.connectionpool - DEBUG - "POST /services/garbage_day HTTP/1.1" 200 None
2016-04-14 20:23:19 - RefusePickup - INFO - Reading through 14152 bytes for 6 properties...
2016-04-14 20:23:19 - RefusePickup - DEBUG - Searching for 'next_pickup_recycle_after': //*[@id="nConf"]/strong[4]
2016-04-14 20:23:19 - RefusePickup - DEBUG - Searching for 'route_recyle': //*[@id="nConf"]/strong[3]
2016-04-14 20:23:19 - RefusePickup - DEBUG - Searching for 'next_pickup_recycle_before': //*[@id="nConf"]/strong[5]
2016-04-14 20:23:19 - RefusePickup - DEBUG - Searching for 'success_msg': //*[@id="nConf"]/h1
2016-04-14 20:23:19 - RefusePickup - DEBUG - Searching for 'route_garbage': //*[@id="nConf"]/strong[1]
2016-04-14 20:23:19 - RefusePickup - DEBUG - Searching for 'next_pickup_garbage': //*[@id="nConf"]/strong[2]
2016-04-14 20:23:19 - mke-refuse - INFO - Query returned
2016-12-29 12:50:08 - mke-refuse - DEBUG - Parsing arguments
2016-12-29 12:50:08 - mke-refuse - DEBUG - Composing query address
2016-12-29 12:50:08 - mke-refuse - INFO - Executing query...
2016-12-29 12:50:08 - requests.packages.urllib3.connectionpool - DEBUG - Starting new HTTP connection (1): mpw.milwaukee.gov
2016-12-29 12:50:08 - requests.packages.urllib3.connectionpool - DEBUG - http://mpw.milwaukee.gov:80 "POST /services/garbage_day HTTP/1.1" 200 None
2016-12-29 12:50:08 - RefusePickup - DEBUG - Parsing 13813 bytes of HTML
2016-12-29 12:50:08 - RefusePickup - DEBUG - Searching for 'next_pickup_garbage' with 'The next garbage collection pickup for this location is: <strong>(?P<value>[^<]+)</strong>'
2016-12-29 12:50:08 - RefusePickup - DEBUG - Searching for 'route_garbage' with 'garbage pickup route for this location is <strong>(?P<value>[^<]+)</strong>'
2016-12-29 12:50:08 - RefusePickup - DEBUG - Searching for 'next_pickup_recycle_before' with 'The next estimated pickup time is between <strong>(?P<after>[^<]+)</strong> and <strong>(?P<value>[^<]+)</strong>'
2016-12-29 12:50:08 - RefusePickup - DEBUG - Searching for 'route_recycle' with 'recycling pickup route for this location is <strong>(?P<value>[^<]+)</strong>'
2016-12-29 12:50:08 - RefusePickup - DEBUG - Searching for 'next_pickup_recycle_after' with 'The next estimated pickup time is between <strong>(?P<value>[^<]+)</strong> and <strong>(?P<before>[^<]+)</strong>'
2016-12-29 12:50:08 - mke-refuse - INFO - Query returned
{
"next_pickup_recycle_after": "TUESDAY MAY 3, 2016",
"route_recyle": "SR01-3-07",
"route_garbage": "SP1-3A",
"success_msg": "2727 S 27TH ST - Address located!",
"next_pickup_recycle_before": "May 9th - May 13th",
"next_pickup_garbage": "TUESDAY APRIL 19, 2016"
"route_recycle": "NR1-2-3",
"next_pickup_garbage": "THURSDAY JANUARY 5, 2017",
"route_garbage": "NP1-2A",
"next_pickup_recycle_before": "THURSDAY JANUARY 5, 2017",
"next_pickup_recycle_after": "WEDNESDAY JANUARY 4, 2017"
}
```

### Advanced

```python
In [1]: from mkerefuse.refuse import RefuseQuery
...: from mkerefuse.refuse import RefuseQueryAddress
...:
...: address = RefuseQueryAddress(
...: house_number='2727',
...: direction='S',
...: street_name='27th',
...: street_type='ST')
...:
...: pickup = RefuseQuery.Execute(address)
...:
...: print("Found garbage route: {}".format(pickup.route_garbage))
...:
...: pickup.to_dict()
...:

Found garbage route: SP1-3A
Out[1]:
{'next_pickup_garbage': u'THURSDAY DECEMBER 29, 2016',
'next_pickup_recycle_after': '',
'next_pickup_recycle_before': '',
'route_garbage': u'SP1-3A',
'route_recycle': ''}
```

*See [Usage.ipynb](Usage.ipynb)*

### Development Setup
Expand All @@ -85,6 +107,10 @@ venv/bin/jupyter notebook
- **Submit:** Submit

### Form Response *(XPaths)*
**Note:** These xpaths are still listed for historical reasons since parsing
is now done via regex due to issues like
[#5](https://github.com/tomislacker/python-mke-trash-pickup/issues/5).

- **Success Or Note:** `//*[@id="nConf"]/h1`
- **Winter Pickup Route:** `//*[@id="nConf"]/strong[1]`
- **Next Garbage Pickup:** `//*[@id="nConf"]/strong[2]`
Expand All @@ -103,5 +129,9 @@ curl \

## References
### Building Libraries for Lambda
**Note:** These references are still listed for historical reasons since
parsing is now done via regex due to issues like
[#5](https://github.com/tomislacker/python-mke-trash-pickup/issues/5).

- [[azavea.com] Using Python's LXML in Amazon Lambda](https://www.azavea.com/blog/2016/06/27/using-python-lxml-amazon-lambda/)
- [[stackoverflow.com] Use LXML on AWS Lambda](http://stackoverflow.com/questions/36387664/use-lxml-on-aws-lambda)
119 changes: 0 additions & 119 deletions Usage.ipynb

This file was deleted.

6 changes: 4 additions & 2 deletions mkerefuse/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
-s, --street STRING Street Name (ex: '27th')
-t, --street-type STRING Street Type
-T, --types List all Street Types

--html FILE Save the form output HTML for debug
"""
import logging
import sys
from docopt import docopt
from mkerefuse import __version__
from mkerefuse.util import LogProducer
from mkerefuse.util import setup_logging
setup_logging()

Expand Down Expand Up @@ -50,7 +51,8 @@

# Execute the query
log.info("Executing query...")
pickup = RefuseQuery.Execute(address)
pickup = RefuseQuery.Execute(address,
html_output=args['--html'])
log.info("Query returned")

# Show the results
Expand Down
Loading