Skip to content

Commit

Permalink
Merge pull request #3 from fterh/hotfix-remove-ricemedia
Browse files Browse the repository at this point in the history
Hotfix remove ricemedia
  • Loading branch information
fterh authored Jan 1, 2019
2 parents 23fb64a + ee842a6 commit 74cd58e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
42 changes: 30 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# sneakpeek
A Reddit bot that previews hyperlinks and posts their contents as a comment. It should **never spam or double-post**, and will skip a comment if it is too long.
A Reddit bot that previews hyperlinks and posts their contents as a comment.
It should **never spam or double-post**, and will skip a comment if it is too long.

## Site support
* channelnewsasia.com
Expand All @@ -17,41 +18,58 @@ A Reddit bot that previews hyperlinks and posts their contents as a comment. It

## How it works
### General
`main.py` starts the bot and calls `scan(subreddit)` (in `scan.py`), which scans for submissions in the provided subreddit.
`main.py` starts the bot and calls `scan(subreddit)` (in `scan.py`),
which scans for submissions in the provided subreddit.

`scan` gets a pre-configured number (`config.LIMIT`) of the latest submissions and checks if they qualify for preview by calling `qualify` (in `qualify.py`).
`scan` gets a pre-configured number (`config.LIMIT`) of the latest submissions
and checks if they qualify for preview by calling `qualify` (in `qualify.py`).

A submission qualifies for preview if it:
1. Is a link
2. Has not been encountered by the bot previously
3. Has a Handler for the website

If a submission qualifies, `scan` calls the `handle` method of the Handler to generate the raw comment, then `format_comment(comment)` in the comments module to generate the final comment in Markdown.
If a submission qualifies, `scan` calls the `handle` method of the Handler
to generate the raw comment, then `format_comment(comment)` in the
comments module to generate the final comment in Markdown.

If the final comment in Markdown does not exceed a pre-configured comment length (`config.COMMENT_LENGTH_LIMIT`), the comment is posted, and the action written to the database (through `DatabaseManager`) to prevent double-posting.
If the final comment in Markdown does not exceed a pre-configured comment length (`config.COMMENT_LENGTH_LIMIT`), the comment is posted, and the action written
to the database (through `DatabaseManager`) to prevent double-posting.

### Handlers
`handler.py` contains a HandlerManager that checks if a website is supported by a Handler.
`handler.py` contains a HandlerManager that checks if a website has a Handler.

A Handler is a class with a `@classmethod handle(cls, url)` that accepts a URL and returns a Comment. All Handlers must inherit from `AbstractBaseHandler`.
A Handler is a class with a `@classmethod handle(cls, url)` that accepts a URL
and returns a Comment. All Handlers must inherit from `AbstractBaseHandler`.

The Handler can be part of a module or package, and have as many supporting sub-modules or sub-packages as necessary.
The Handler can be part of a module or package, and have as many supporting
sub-modules or sub-packages as necessary.

### Comments
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).
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).

### Database
|submission_id|action|notes
|--|--|--
|text|text|text

A list of valid actions is provided by `DatabaseActionEnum` in the `database` module: `ERROR`, `SKIP`, and `SUCCESS`.
A list of valid actions is provided by `DatabaseActionEnum` in the
`database` module: `ERROR`, `SKIP`, and `SUCCESS`.

## Changelog
### 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)
* 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
* Supports channelnewsasia.com, mothership.sg, ricemedia.co, straitstimes.com,
todayonline.com, zula.sg
2 changes: 1 addition & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
RUN_EVERY = 2

BOT = {
"VERSION": "0.2.0-beta",
"VERSION": "0.2.1-beta",
"REPO_LINK": "https://github.com/fterh/sneakpeek",
"CONTRIBUTE_LINK": "https://github.com/fterh/sneakpeek"
}
Expand Down
1 change: 0 additions & 1 deletion handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class HandlerManager:
handlers = {
"channelnewsasia.com": ArticleHandler,
"mothership.sg": ArticleHandler,
"ricemedia.co": ArticleHandler,
"straitstimes.com": ArticleHandler,
"todayonline.com": ArticleHandler,
"zula.sg": ArticleHandler
Expand Down
1 change: 1 addition & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def start():

if __name__ == "__main__":
while True:
start()
schedule.run_pending()
print("Sleeping")
time.sleep(1)

0 comments on commit 74cd58e

Please sign in to comment.