mirror of
https://github.com/davegallant/rfd.git
synced 2025-08-07 09:02:32 +00:00
Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
1e0d6da48b | ||
|
22d75f8332 |
11
.github/PULL_REQUEST_TEMPLATE.md
vendored
11
.github/PULL_REQUEST_TEMPLATE.md
vendored
@@ -1,9 +1,8 @@
|
||||
|
||||
**What this PR does / why we need it:**
|
||||
-
|
||||
*Description of changes:*
|
||||
|
||||
**Which issue(s) this PR fixes:**
|
||||
-
|
||||
*Checklist:*
|
||||
|
||||
**Additional Notes:**
|
||||
-
|
||||
- [ ] Write unit tests
|
||||
- [ ] `make pr` passes
|
||||
- [ ] Write documentation
|
||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@@ -88,5 +88,3 @@ venv.bak/
|
||||
.mypy_cache/
|
||||
.dmypy.json
|
||||
dmypy.json
|
||||
|
||||
tmp/
|
||||
|
66
Makefile
66
Makefile
@@ -1,57 +1,35 @@
|
||||
|
||||
SRC := rfd
|
||||
SHELL := bash
|
||||
.ONESHELL:
|
||||
.SHELLFLAGS := -eu -o pipefail -c
|
||||
.DELETE_ON_ERROR:
|
||||
MAKEFLAGS += --warn-undefined-variables
|
||||
MAKEFLAGS += --no-builtin-rules
|
||||
SRC:=rfd
|
||||
|
||||
|
||||
ifeq ($(origin .RECIPEPREFIX), undefined)
|
||||
$(error This Make does not support .RECIPEPREFIX. Please use GNU Make 4.0 or later)
|
||||
endif
|
||||
.RECIPEPREFIX = >
|
||||
|
||||
## build: Build a tar.gz of the python package
|
||||
build:
|
||||
> rm -rf dist/
|
||||
> python setup.py sdist
|
||||
.PHONY: build
|
||||
build:
|
||||
rm -rf dist/
|
||||
python setup.py sdist
|
||||
|
||||
.PHONY: push_test
|
||||
push_test:
|
||||
twine upload -r testpypi dist/*.tar.gz
|
||||
|
||||
.PHONY: push_prod
|
||||
push_prod:
|
||||
twine upload dist/*.tar.gz
|
||||
|
||||
## precommit: Run all pre-commit hooks
|
||||
precommit:
|
||||
> pre-commit run \
|
||||
--all-files \
|
||||
--show-diff-on-failure
|
||||
.PHONY: precommit
|
||||
precommit: ## Run pre-commit
|
||||
pre-commit run \
|
||||
--all-files \
|
||||
--show-diff-on-failure
|
||||
|
||||
## lint: Run static analysis on the code
|
||||
lint:
|
||||
> pylint $(SRC)
|
||||
.PHONY: lint
|
||||
lint:
|
||||
pylint $(SRC)
|
||||
|
||||
## test: Run all unit tests
|
||||
test: tmp/.tests-passed.sentinel
|
||||
.PHONY: test
|
||||
test:
|
||||
pytest -v
|
||||
|
||||
# Tests - re-ran if any file under src has been changed since tmp/.tests-passed.sentinel was last touched
|
||||
tmp/.tests-passed.sentinel: $(shell find ${SRC} -type f)
|
||||
> mkdir -p $(@D)
|
||||
> pytest -v
|
||||
> touch $@
|
||||
|
||||
## pr: Run pre-commit, lint and test
|
||||
pr: precommit lint test
|
||||
.PHONY: pr
|
||||
pr: precommit lint test
|
||||
|
||||
ci: lint test
|
||||
.PHONY: ci
|
||||
|
||||
## help: Print this help message
|
||||
help:
|
||||
> @echo "Usage:"
|
||||
> @echo
|
||||
> @sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /' | sort
|
||||
> @echo
|
||||
.PHONY: help
|
||||
ci: lint test
|
||||
|
37
README.md
37
README.md
@@ -4,15 +4,10 @@ Hot deals on the command line.
|
||||
|
||||
[](https://travis-ci.org/davegallant/rfd)
|
||||
[](https://badge.fury.io/py/rfd)
|
||||
[](https://dependabot.com/)
|
||||
[](https://lgtm.com/projects/g/davegallant/rfd/alerts/)
|
||||
[](https://lgtm.com/projects/g/davegallant/rfd/context:python)
|
||||
|
||||
|
||||

|
||||
|
||||
|
||||
## Install
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
pip install rfd
|
||||
@@ -20,37 +15,21 @@ pip install rfd
|
||||
|
||||
## Usage
|
||||
|
||||
```shell
|
||||
Usage: rfd [OPTIONS] COMMAND [ARGS]...
|
||||

|
||||
|
||||
CLI for https://forums.redflagdeals.com
|
||||
|
||||
Options:
|
||||
-v, --version
|
||||
--help Show this message and exit.
|
||||
|
||||
Commands:
|
||||
posts Display all posts in a thread.
|
||||
search Search deals based on a regular expression.
|
||||
threads Displays threads in the forum. Defaults to hot deals.
|
||||
### threads
|
||||
```bash
|
||||
rfd threads [--forum-id 9] [--limit 10]
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### view hot deals
|
||||
```shell
|
||||
rfd threads
|
||||
```
|
||||
|
||||
### search for pizza
|
||||
```shell
|
||||
rfd search 'pizza'
|
||||
### search
|
||||
```bash
|
||||
rfd search pizza [--num-pages 100]
|
||||
```
|
||||
|
||||
## Tab Completion
|
||||
|
||||
To enable:
|
||||
|
||||
### bash
|
||||
|
||||
```bash
|
||||
|
@@ -1,5 +1,4 @@
|
||||
beautifulsoup4<=4.8.2
|
||||
beautifulsoup4>=4.6.0
|
||||
click>=7.0
|
||||
colorama>=0.4.3
|
||||
requests>=2.22.0
|
||||
soupsieve<=2.0
|
||||
colorama>=0.3.9
|
||||
requests>=2.18.0
|
||||
|
@@ -1,5 +1,5 @@
|
||||
pre-commit==1.21.0
|
||||
pre-commit==1.18.3
|
||||
pylint
|
||||
pytest>=4.6.6
|
||||
rope==0.16.0
|
||||
rope==0.14.0
|
||||
tox-travis==0.12
|
||||
|
@@ -1 +1 @@
|
||||
0.3.5
|
||||
0.3.3
|
||||
|
51
rfd/cli.py
51
rfd/cli.py
@@ -36,40 +36,34 @@ def get_vote_color(score):
|
||||
return Fore.BLUE + " [" + str(score) + "] "
|
||||
|
||||
|
||||
def print_version(ctx, value):
|
||||
if not value or ctx.resilient_parsing:
|
||||
return
|
||||
click.echo(get_version())
|
||||
ctx.exit()
|
||||
|
||||
|
||||
@click.group(invoke_without_command=True)
|
||||
@click.option(
|
||||
"-v",
|
||||
"--version",
|
||||
is_flag=True,
|
||||
callback=print_version,
|
||||
expose_value=False,
|
||||
is_eager=True,
|
||||
)
|
||||
@click.option("--version/--no-version", default=False)
|
||||
@click.pass_context
|
||||
def cli(ctx):
|
||||
def cli(ctx, version):
|
||||
"""CLI for https://forums.redflagdeals.com"""
|
||||
if not ctx.invoked_subcommand:
|
||||
if version:
|
||||
click.echo(get_version())
|
||||
elif not ctx.invoked_subcommand:
|
||||
click.echo(ctx.get_help())
|
||||
|
||||
|
||||
@cli.command(short_help="Display all posts in a thread.")
|
||||
@cli.command("version")
|
||||
def display_version():
|
||||
click.echo(get_version())
|
||||
|
||||
|
||||
@cli.command(short_help="Displays posts in a specific thread.")
|
||||
@click.argument("post_id")
|
||||
def posts(post_id):
|
||||
"""Iterate all pages and display all posts in a thread.
|
||||
"""Displays posts in a specific thread.
|
||||
|
||||
post_id can be a full url or post id only
|
||||
|
||||
Example:
|
||||
|
||||
\b
|
||||
rfd posts https://forums.redflagdeals.com/koodo-targeted-public-mobile-12-120-koodo-5gb-40-no-referrals-2173603
|
||||
url: https://forums.redflagdeals.com/koodo-targeted-public-mobile-12-120-koodo-5gb-40-no-referrals-2173603
|
||||
post_id: 2173603
|
||||
"""
|
||||
|
||||
try:
|
||||
@@ -93,11 +87,11 @@ def posts(post_id):
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
@cli.command(short_help="Displays threads in the forum. Defaults to hot deals.")
|
||||
@cli.command(short_help="Displays threads in the specified forum.")
|
||||
@click.option("--limit", default=10, help="Number of topics.")
|
||||
@click.option("--forum-id", default=9, help="The forum id number")
|
||||
def threads(limit, forum_id):
|
||||
"""Display threads in the specified forum id. Defaults to 9 (hot deals).
|
||||
"""Displays threads in the specified forum id. Defaults to 9.
|
||||
|
||||
Popular forum ids:
|
||||
|
||||
@@ -122,22 +116,19 @@ def threads(limit, forum_id):
|
||||
+ get_vote_color(thread.score)
|
||||
+ Fore.RESET
|
||||
+ "[%s] %s" % (thread.dealer_name, thread.title)
|
||||
+ Fore.LIGHTYELLOW_EX
|
||||
+ " (%d views)" % thread.total_views
|
||||
+ Fore.RESET
|
||||
)
|
||||
click.echo(Fore.BLUE + " {}".format(thread.url))
|
||||
click.echo(Style.RESET_ALL)
|
||||
|
||||
|
||||
@cli.command(short_help="Search deals based on a regular expression.")
|
||||
@cli.command(short_help="Displays threads in the specified forum.")
|
||||
@click.option("--num-pages", default=5, help="Number of pages to search.")
|
||||
@click.option(
|
||||
"--forum-id", default=9, help="The forum id number. Defaults to 9 (hot deals)."
|
||||
)
|
||||
@click.argument("regex")
|
||||
def search(num_pages, forum_id, regex):
|
||||
"""Search deals based on regex.
|
||||
@click.argument("keyword")
|
||||
def search(num_pages, forum_id, keyword):
|
||||
"""Searches for deals based on a keyword in the specified forum id.
|
||||
|
||||
Popular forum ids:
|
||||
|
||||
@@ -157,7 +148,7 @@ def search(num_pages, forum_id, regex):
|
||||
count = 0
|
||||
for page in range(1, num_pages):
|
||||
_threads = parse_threads(get_threads(forum_id, 100, page=page), limit=100)
|
||||
for thread in search_threads(threads=_threads, regex=regex):
|
||||
for thread in search_threads(threads=_threads, keyword=keyword):
|
||||
count += 1
|
||||
click.echo(
|
||||
" "
|
||||
|
@@ -1,11 +1,10 @@
|
||||
# pylint: disable=old-style-class
|
||||
class Thread:
|
||||
def __init__(self, title, dealer_name, score, url, total_views):
|
||||
def __init__(self, title, dealer_name, score, url):
|
||||
self.dealer_name = dealer_name
|
||||
self.score = score
|
||||
self.title = title
|
||||
self.url = url
|
||||
self.total_views = total_views
|
||||
|
||||
def __repr__(self):
|
||||
return "Thread(%s)" % self.title
|
||||
|
@@ -29,7 +29,6 @@ def parse_threads(threads, limit):
|
||||
dealer_name=topic["offer"].get("dealer_name"),
|
||||
score=calculate_score(topic),
|
||||
url=build_web_path(topic.get("web_path")),
|
||||
total_views=topic.get("total_views"),
|
||||
)
|
||||
)
|
||||
return parsed_threads
|
||||
|
@@ -1,14 +1,13 @@
|
||||
import re
|
||||
def search_threads(threads, keyword=None):
|
||||
"""Match deal title and dealer names with keyword specified."""
|
||||
|
||||
if keyword is None:
|
||||
return
|
||||
|
||||
def search_threads(threads, regex):
|
||||
"""Match deal title and dealer names with regex specified."""
|
||||
|
||||
regexp = re.compile(str(regex).lower())
|
||||
keyword = str(keyword)
|
||||
|
||||
for deal in threads:
|
||||
|
||||
if regexp.search(deal.title.lower()) or (
|
||||
deal.dealer_name and regexp.search(deal.dealer_name.lower())
|
||||
if keyword.lower() in deal.title.lower() or (
|
||||
deal.dealer_name and keyword.lower() in deal.dealer_name.lower()
|
||||
):
|
||||
yield deal
|
||||
|
Reference in New Issue
Block a user