From d710811fb21266d23ce4acd8fd5a461fe5108c8f Mon Sep 17 00:00:00 2001 From: Fabian Date: Thu, 9 May 2019 21:58:09 +0800 Subject: [PATCH 01/21] Separate changelog * Fix formatting inconsistencies * Remove attribution * Add issue numbers --- CHANGELOG.md | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 48 ------------------------------------------------ 2 files changed, 50 insertions(+), 48 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..6823b03 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,50 @@ +## Changelog +### v0.8.0-beta +* Fix program stops running after a while (issue #30) +* Implement proper logging +* Clean up and refactor codebase +* Travis CI + +### v0.7.0-beta +* Fix random crashes (issue #25) +* Fix README formatting issues +* Clean up code +* Update README developer documentation + +### v0.6.0-beta +* Update subreddit monitoring implementation + +### v0.5.0-beta +* Fix program crash when exception occurs (issue #13) +* Fix exception in handling Ricemedia links (issue #19) +* Add support for businesstimes.com.sg, tnp.sg, yahoo.com +* Add support for CNAlifestyle + +### v0.4.0-beta +* Add Straits Times support + +### v0.3.0-beta +* Temporarily remove Straits Times support +(until premium article detection feature) +* Fix Todayonline article handling +* Fix Ricemedia article handling +* Update AbstractBaseHandler `handle` method definition +* Add tests + +### v0.2.2-beta +* Fix scheduling bug + +### v0.2.1-beta +* Remove ricemedia.co from list of supported sites (incompatibility) +* Fix start script to run immediately +* Fix long lines in README + +### v0.2.0-beta +* Add scheduling to run every 2 minutes +* Update database module to be compatible with new database table structure +(3 columns) + +### v0.1.0-beta +* Minimum viable product +* Supports channelnewsasia.com, mothership.sg, ricemedia.co, straitstimes.com, +todayonline.com, zula.sg diff --git a/README.md b/README.md index 41fb358..55d997f 100644 --- a/README.md +++ b/README.md @@ -82,51 +82,3 @@ the commands. ### Production `ENV=prod python main.py` or `ENV=prod nohup python main.py &` - -## Changelog -### v0.8.0-beta -* Fix program stops running after a while (issue #30) -* Implement proper logging -* Clean up and refactor codebase -* Travis CI - -### v0.7.0-beta -* Fix random crashes (issue #25) -* Fix README formatting issues -* Clean up code -* Update README developer documentation - -### v0.6.0-beta -* Update subreddit monitoring implementation -### v0.5.0-beta -* Fix program crash when exception occurs (@yleong PR #22) -* Fix exception in handling Ricemedia links (@yleong PR #20) -* Add support for businesstimes.com.sg, tnp.sg, yahoo.com (@changhuapeng PR #18) -* Add support for CNAlifestyle (@changhuapeng PR #17) -### v0.4.0-beta -* Add Straits Times support -### v0.3.0-beta -* Temporarily remove Straits Times support -(until premium article detection feature) -* Fix Todayonline article handling -* Fix Ricemedia article handling -* Update AbstractBaseHandler `handle` method definition -* Add tests - -### v0.2.2-beta -* Fix scheduling bug - -### v0.2.1-beta -* Remove ricemedia.co from list of supported sites (incompatibility) -* Fix start script to run immediately -* Fix long lines in README - -### v0.2.0-beta -* Add scheduling to run every 2 minutes -* Update database module to be compatible with new database table structure -(3 columns) - -### v0.1.0-beta -* Minimum viable product -* Supports channelnewsasia.com, mothership.sg, ricemedia.co, straitstimes.com, -todayonline.com, zula.sg From b1c8bd8f75d0b27ce2567d3dbc6c823d5393792e Mon Sep 17 00:00:00 2001 From: Fabian Date: Thu, 9 May 2019 22:01:01 +0800 Subject: [PATCH 02/21] Update README.md --- README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 55d997f..60b54c0 100644 --- a/README.md +++ b/README.md @@ -19,9 +19,11 @@ too long. * zula.sg ## Contributing -1. Write documentation -2. Write Handlers to support more websites -3. Write tests +PRs are always welcome. + +1. Write Handlers to support more websites +2. Improve test coverage +3. Improve documentation ### New version release checklist 1. Create a release branch (e.g. `release-v1.2.3`) from the `develop` branch @@ -30,9 +32,9 @@ too long. 4. Possibly commit minor bug fixes to the release branch 5. Merge the release branch into `master` and `develop` -This project follows this [Git branching workflow](https://nvie.com/posts/a-successful-git-branching-model/): +This project follows this [Git branching workflow](https://nvie.com/posts/a-successful-git-branching-model/). -## How it works +## Operation ### General `main.py` starts the bot and calls `scan(subreddit)` (in `scan.py`), which monitors for new submissions in the provided subreddit. From 715491db27a79fec8fdf1bdf5baf51ce1019abdb Mon Sep 17 00:00:00 2001 From: Fabian Date: Thu, 9 May 2019 22:27:22 +0800 Subject: [PATCH 03/21] Read subreddit from environmental variable This makes it easier to switch subreddits without having to modify source code. --- config.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/config.py b/config.py index 781c8de..20ec31a 100644 --- a/config.py +++ b/config.py @@ -6,9 +6,6 @@ load_dotenv() -# Set to "prod" in production, but default to "dev" -ENV = os.getenv("ENV", "dev") - # Logging configuration LOGGING = { "LEVEL": logging.DEBUG, @@ -31,5 +28,5 @@ USER_AGENT = os.getenv("USER_AGENT") -SUBREDDIT = "singapore" if ENV == "prod" else "rsgretrivr" +SUBREDDIT = os.getenv("SUBREDDIT", "all") # Set subreddit using environmental variables, default to /r/all COMMENT_LENGTH_LIMIT = 9900 From 829707c2dbdc731966b185b058e8b06861c7015f Mon Sep 17 00:00:00 2001 From: Fabian Date: Thu, 9 May 2019 22:32:58 +0800 Subject: [PATCH 04/21] Update README.md --- README.md | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 60b54c0..eff0b0e 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,18 @@ PRs are always welcome. This project follows this [Git branching workflow](https://nvie.com/posts/a-successful-git-branching-model/). ## Operation +### Before running +The program requires an environmental variable to be set `SUBREDDIT`. +This specifies the subreddit that the bot will monitor. +At the moment, only 1 subreddit may be specified. + +### Running/Testing +All the commands below assume that the virtual environment has been activated +(`pipenv shell`). + +* Running: `SUBREDDIT=name python main.py` (or `SUBREDDIT=name nohup python main.py &`) +* Testing: `invoke test` + ### General `main.py` starts the bot and calls `scan(subreddit)` (in `scan.py`), which monitors for new submissions in the provided subreddit. @@ -70,17 +82,3 @@ sub-modules or sub-packages as necessary. The comments module (in `comment.py`) exports the Comment class, which all Handlers must return. A Comment class requires a `title` and `body`, and accepts a `byline` and `attribution` (which are optional). - -## Running and deploying -All the commands below assume you have already activated the -virtual environment (`pipenv shell`). Alternatively, prepend `pipenv run` to -the commands. - -### Development -`python main.py` - -### Testing -`invoke test` - -### Production -`ENV=prod python main.py` or `ENV=prod nohup python main.py &` From 6ad1a8135ad1c5c9914153513bf3e66053177b45 Mon Sep 17 00:00:00 2001 From: Fabian Date: Thu, 9 May 2019 23:01:32 +0800 Subject: [PATCH 05/21] Add Dockerfile --- Dockerfile | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2bd0df2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM python:3 +WORKDIR / +COPY . / +RUN pip install -r requirements.txt +ENV SUBREDDIT singapore +CMD ["python", "main.py"] From 00288ca3bba3819ecc5ead1fd113f1428d0ded6d Mon Sep 17 00:00:00 2001 From: Fabian Date: Thu, 9 May 2019 23:01:38 +0800 Subject: [PATCH 06/21] Update .travis.yml --- .travis.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e8ff167..301cf3b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,21 @@ dist: xenial +services: + - docker language: python python: - "3.7" +before_install: + - docker pull python:3 install: - pip install pipenv -script: +before_script: - pipenv install +script: - pipenv run invoke test +before_deploy: + - pipenv run pip freeze > requirements.txt + - docker build --tag=sneakpeek . +deploy: + - docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD" + - docker tag sneakpeek "$DOCKER_USERNAME"/sneakpeek + - docker push "$DOCKER_USERNAME"/sneakpeek From 0dd57721395f5b47d1e6579a72278b78b1cbe04b Mon Sep 17 00:00:00 2001 From: Fabian Date: Thu, 9 May 2019 23:04:39 +0800 Subject: [PATCH 07/21] Fix deployment script in .travis.yml --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 301cf3b..6159320 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,6 @@ script: before_deploy: - pipenv run pip freeze > requirements.txt - docker build --tag=sneakpeek . -deploy: - docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD" - docker tag sneakpeek "$DOCKER_USERNAME"/sneakpeek - docker push "$DOCKER_USERNAME"/sneakpeek From a1b5d1ef795bb1f7ac59bc23c995b3e0bea93f64 Mon Sep 17 00:00:00 2001 From: Fabian Date: Thu, 9 May 2019 23:08:35 +0800 Subject: [PATCH 08/21] Rename before_deploy to after_success --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6159320..c094188 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ before_script: - pipenv install script: - pipenv run invoke test -before_deploy: +after_success: - pipenv run pip freeze > requirements.txt - docker build --tag=sneakpeek . - docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD" From 261ec7f5493cadc207a302d5e91101de8b3acaa4 Mon Sep 17 00:00:00 2001 From: Fabian Date: Fri, 10 May 2019 08:08:03 +0800 Subject: [PATCH 09/21] Deploy to heroku --- .travis.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.travis.yml b/.travis.yml index c094188..5f5f1af 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,3 +18,10 @@ after_success: - docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD" - docker tag sneakpeek "$DOCKER_USERNAME"/sneakpeek - docker push "$DOCKER_USERNAME"/sneakpeek +deploy: + provider: heroku + api_key: + secure: "$HEROKU_API_KEY" + app: + master: fterh-sneakpeek + develop: fterh-sneakpeek-staging From 58013c7b83b4c1e5a5a5fbc66a1f5cbc1be94aa6 Mon Sep 17 00:00:00 2001 From: Fabian Date: Fri, 10 May 2019 08:12:35 +0800 Subject: [PATCH 10/21] Temporarily permit "cd" branch for deployment --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 5f5f1af..1fa9e2a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,3 +25,4 @@ deploy: app: master: fterh-sneakpeek develop: fterh-sneakpeek-staging + cd: fterh-sneakpeek-staging From b7aa96ecd03aaf9f891a00a00fb250f29ade854c Mon Sep 17 00:00:00 2001 From: Fabian Date: Fri, 10 May 2019 13:41:35 +0800 Subject: [PATCH 11/21] Update Dockerfile --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index 2bd0df2..a66c9ad 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,8 @@ FROM python:3 WORKDIR / COPY . / +RUN pip install pipenv +RUN pipenv run pip freeze > requirements.txt RUN pip install -r requirements.txt ENV SUBREDDIT singapore CMD ["python", "main.py"] From 1767ef6c3c2aa8cdd8a0ae1f8cb8c1c532dc6fc3 Mon Sep 17 00:00:00 2001 From: Fabian Date: Fri, 10 May 2019 13:41:44 +0800 Subject: [PATCH 12/21] Update .travis.yml --- .travis.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1fa9e2a..fe306dc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,12 +12,6 @@ before_script: - pipenv install script: - pipenv run invoke test -after_success: - - pipenv run pip freeze > requirements.txt - - docker build --tag=sneakpeek . - - docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD" - - docker tag sneakpeek "$DOCKER_USERNAME"/sneakpeek - - docker push "$DOCKER_USERNAME"/sneakpeek deploy: provider: heroku api_key: From 9906f59543c12528c6939cbce85a37f9a4c476a1 Mon Sep 17 00:00:00 2001 From: Fabian Date: Fri, 10 May 2019 13:41:59 +0800 Subject: [PATCH 13/21] Add heroku.yml --- heroku.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 heroku.yml diff --git a/heroku.yml b/heroku.yml new file mode 100644 index 0000000..7b13190 --- /dev/null +++ b/heroku.yml @@ -0,0 +1,3 @@ +build: + docker: + worker: Dockerfile From 91a931e2abfe7c6d6cdf51cc01fc77ddcf4a9dd7 Mon Sep 17 00:00:00 2001 From: Fabian Date: Fri, 10 May 2019 13:53:03 +0800 Subject: [PATCH 14/21] Temporarily add requirements.txt --- requirements.txt | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..92c5065 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,28 @@ +beautifulsoup4==4.7.1 +certifi==2018.11.29 +chardet==3.0.4 +cssselect==1.0.3 +feedfinder2==0.0.4 +feedparser==5.2.1 +idna==2.8 +invoke==1.2.0 +jieba3k==0.35.1 +lxml==4.3.0 +newspaper3k==0.2.8 +nltk==3.4 +Pillow==5.4.1 +praw==6.0.0 +prawcore==1.0.0 +python-dateutil==2.7.5 +python-dotenv==0.10.1 +PyYAML==3.13 +requests==2.21.0 +requests-file==1.4.3 +schedule==0.5.0 +singledispatch==3.4.0.3 +six==1.12.0 +soupsieve==1.7 +tinysegmenter==0.3 +tldextract==2.2.0 +update-checker==0.16 +urllib3==1.24.1 From fbfea9529c9915af18847dd42a2390048f790021 Mon Sep 17 00:00:00 2001 From: Fabian Date: Fri, 10 May 2019 13:59:47 +0800 Subject: [PATCH 15/21] Fix Dockerfile --- Dockerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index a66c9ad..2bd0df2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,6 @@ FROM python:3 WORKDIR / COPY . / -RUN pip install pipenv -RUN pipenv run pip freeze > requirements.txt RUN pip install -r requirements.txt ENV SUBREDDIT singapore CMD ["python", "main.py"] From 862349f7befb481cd29f26176c02bf77c1b2cae7 Mon Sep 17 00:00:00 2001 From: Fabian Date: Fri, 10 May 2019 14:19:51 +0800 Subject: [PATCH 16/21] Remove env var "SUBREDDIT" from Dockerfile This should be set at run-time in the environment (e.g. staging, production) that the container is running in. --- Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 2bd0df2..e9049c1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,5 +2,4 @@ FROM python:3 WORKDIR / COPY . / RUN pip install -r requirements.txt -ENV SUBREDDIT singapore CMD ["python", "main.py"] From 36a1800d6711c3eb0c0b50e309deca2cabc73911 Mon Sep 17 00:00:00 2001 From: Fabian Date: Fri, 10 May 2019 14:29:35 +0800 Subject: [PATCH 17/21] Fix Dockerfile: generate requirements.txt --- Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Dockerfile b/Dockerfile index e9049c1..ff031fe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,8 @@ FROM python:3 WORKDIR / COPY . / +RUN pip install pipenv +RUN pipenv install +RUN pipenv run pip freeze > requirements.txt RUN pip install -r requirements.txt CMD ["python", "main.py"] From c33d7574547cba2f038e5787425df071e8397fd1 Mon Sep 17 00:00:00 2001 From: Fabian Date: Fri, 10 May 2019 14:44:08 +0800 Subject: [PATCH 18/21] Remove temporary "cd" branch --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index fe306dc..9ed7b0d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,4 +19,3 @@ deploy: app: master: fterh-sneakpeek develop: fterh-sneakpeek-staging - cd: fterh-sneakpeek-staging From 066aa5afb7b98c0844aaee6e4726e97b041fe3fe Mon Sep 17 00:00:00 2001 From: Fabian Date: Fri, 10 May 2019 14:48:43 +0800 Subject: [PATCH 19/21] Update README.md --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index eff0b0e..2fc9fd5 100644 --- a/README.md +++ b/README.md @@ -36,8 +36,9 @@ This project follows this [Git branching workflow](https://nvie.com/posts/a-succ ## Operation ### Before running -The program requires an environmental variable to be set `SUBREDDIT`. +The program requires an environmental variable `SUBREDDIT` to be set. This specifies the subreddit that the bot will monitor. +If it's not set, the default subreddit `/r/all` will be monitored. At the moment, only 1 subreddit may be specified. ### Running/Testing @@ -47,6 +48,9 @@ All the commands below assume that the virtual environment has been activated * Running: `SUBREDDIT=name python main.py` (or `SUBREDDIT=name nohup python main.py &`) * Testing: `invoke test` +#### Docker +This application can be built and run as a Docker image. + ### General `main.py` starts the bot and calls `scan(subreddit)` (in `scan.py`), which monitors for new submissions in the provided subreddit. From 8826fe2b88e448fc390076062f7e35bc8165f8b9 Mon Sep 17 00:00:00 2001 From: Fabian Date: Fri, 10 May 2019 14:54:22 +0800 Subject: [PATCH 20/21] Bump to v1.0.0 --- config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.py b/config.py index 20ec31a..6391158 100644 --- a/config.py +++ b/config.py @@ -13,7 +13,7 @@ } BOT = { - "VERSION": "0.8.0-beta", + "VERSION": "1.0.0", "REPO_LINK": "https://github.com/fterh/sneakpeek", "CONTRIBUTE_LINK": "https://github.com/fterh/sneakpeek" } From 4c1768d5a2852abb12ce5991ee982b7d8aaae6b3 Mon Sep 17 00:00:00 2001 From: Fabian Date: Fri, 10 May 2019 14:54:28 +0800 Subject: [PATCH 21/21] Update CHANGELOG.md --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6823b03..7efb212 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ ## Changelog +## v1.0.0 +* Add support for Docker +* Set up continuous deployment (Heroku) +* Update README +* Separate changelog into CHANGELOG.md + ### v0.8.0-beta * Fix program stops running after a while (issue #30) * Implement proper logging