9 Commits

Author SHA1 Message Date
dependabot[bot]
31ff0e480f Bump pylint from 2.9.6 to 2.11.1 (#108)
* Bump pylint from 2.9.6 to 2.11.1

Bumps [pylint](https://github.com/PyCQA/pylint) from 2.9.6 to 2.11.1.
- [Release notes](https://github.com/PyCQA/pylint/releases)
- [Changelog](https://github.com/PyCQA/pylint/blob/main/ChangeLog)
- [Commits](https://github.com/PyCQA/pylint/compare/v2.9.6...v2.11.1)

---
updated-dependencies:
- dependency-name: pylint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Use f strings everywhere

* Add black.yml

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Dave G <davegallant@gmail.com>
2021-09-25 13:30:01 -04:00
dependabot[bot]
d0103f0733 Bump beautifulsoup4 from 4.9.3 to 4.10.0 (#107)
Bumps [beautifulsoup4](http://www.crummy.com/software/BeautifulSoup/bs4/) from 4.9.3 to 4.10.0.

---
updated-dependencies:
- dependency-name: beautifulsoup4
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Dave G <davegallant@gmail.com>
2021-09-20 16:54:32 -04:00
dependabot[bot]
46af76750e Bump pytest from 6.2.4 to 6.2.5 (#106)
Bumps [pytest](https://github.com/pytest-dev/pytest) from 6.2.4 to 6.2.5.
- [Release notes](https://github.com/pytest-dev/pytest/releases)
- [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst)
- [Commits](https://github.com/pytest-dev/pytest/compare/6.2.4...6.2.5)

---
updated-dependencies:
- dependency-name: pytest
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-09-20 16:53:47 -04:00
dependabot[bot]
8a9e84a30a Bump rope from 0.19.0 to 0.20.1 (#109)
Bumps [rope](https://github.com/python-rope/rope) from 0.19.0 to 0.20.1.
- [Release notes](https://github.com/python-rope/rope/releases)
- [Changelog](https://github.com/python-rope/rope/blob/master/CHANGELOG.md)
- [Commits](https://github.com/python-rope/rope/commits)

---
updated-dependencies:
- dependency-name: rope
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-09-20 16:53:16 -04:00
DG
062baa7707 Update README.md (#104) 2021-08-10 00:00:02 -04:00
DG
31ed869d05 Add brew/pipx instructions (#103)
* Add easier ways to install
2021-08-09 23:54:07 -04:00
dependabot[bot]
eb349c0ff9 Bump pylint from 2.9.5 to 2.9.6 (#102)
Bumps [pylint](https://github.com/PyCQA/pylint) from 2.9.5 to 2.9.6.
- [Release notes](https://github.com/PyCQA/pylint/releases)
- [Changelog](https://github.com/PyCQA/pylint/blob/main/ChangeLog)
- [Commits](https://github.com/PyCQA/pylint/compare/v2.9.5...v2.9.6)

---
updated-dependencies:
- dependency-name: pylint
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-07-29 09:19:13 -04:00
dependabot[bot]
f4afe538e5 Bump pylint from 2.9.3 to 2.9.5 (#101)
Bumps [pylint](https://github.com/PyCQA/pylint) from 2.9.3 to 2.9.5.
- [Release notes](https://github.com/PyCQA/pylint/releases)
- [Changelog](https://github.com/PyCQA/pylint/blob/main/ChangeLog)
- [Commits](https://github.com/PyCQA/pylint/compare/v2.9.3...v2.9.5)

---
updated-dependencies:
- dependency-name: pylint
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-07-21 09:40:56 -04:00
dependabot[bot]
0cb97f56e7 Bump requests from 2.25.1 to 2.26.0 (#100)
Bumps [requests](https://github.com/psf/requests) from 2.25.1 to 2.26.0.
- [Release notes](https://github.com/psf/requests/releases)
- [Changelog](https://github.com/psf/requests/blob/master/HISTORY.md)
- [Commits](https://github.com/psf/requests/compare/v2.25.1...v2.26.0)

---
updated-dependencies:
- dependency-name: requests
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-07-14 08:51:47 -04:00
8 changed files with 108 additions and 65 deletions

10
.github/workflows/black.yml vendored Normal file
View File

@@ -0,0 +1,10 @@
name: Black
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: psf/black@stable

View File

@@ -31,13 +31,21 @@ It is often faster to use a CLI than to load up a web page and navigate web elem
## Installation
> :information_source: python2 may still work but it is [no longer supported](https://www.python.org/doc/sunset-python-2/).
### pip
```bash
python3 -m pip install --user rfd
```sh
pip3 install --user rfd
```
After installation, if you cannot access `rfd` in your path, try `python3 -m rfd`.
This can also be installed with [pipx](https://github.com/pypa/pipx).
### brew
If you have [brew](https://brew.sh):
```sh
brew install davegallant/public/rfd
```
## Usage

92
poetry.lock generated
View File

@@ -19,7 +19,7 @@ pyyaml = "*"
[[package]]
name = "astroid"
version = "2.6.2"
version = "2.8.0"
description = "An abstract syntax tree for Python with inference support."
category = "dev"
optional = false
@@ -28,7 +28,7 @@ python-versions = "~=3.6"
[package.dependencies]
lazy-object-proxy = ">=1.4.0"
typed-ast = {version = ">=1.4.0,<1.5", markers = "implementation_name == \"cpython\" and python_version < \"3.8\""}
typing-extensions = {version = ">=3.7.4", markers = "python_version < \"3.8\""}
typing-extensions = {version = ">=3.10", markers = "python_version < \"3.10\""}
wrapt = ">=1.11,<1.13"
[[package]]
@@ -55,14 +55,14 @@ tests_no_zope = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>
[[package]]
name = "beautifulsoup4"
version = "4.9.3"
version = "4.10.0"
description = "Screen-scraping library"
category = "main"
optional = false
python-versions = "*"
python-versions = ">3.0.0"
[package.dependencies]
soupsieve = {version = ">1.2", markers = "python_version >= \"3.0\""}
soupsieve = ">1.2"
[package.extras]
html5lib = ["html5lib"]
@@ -85,12 +85,15 @@ optional = false
python-versions = ">=3.6"
[[package]]
name = "chardet"
version = "4.0.0"
description = "Universal encoding detector for Python 2 and 3"
name = "charset-normalizer"
version = "2.0.1"
description = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet."
category = "main"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
python-versions = ">=3.5.0"
[package.extras]
unicode_backport = ["unicodedata2"]
[[package]]
name = "click"
@@ -234,6 +237,18 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
[package.dependencies]
pyparsing = ">=2.0.2"
[[package]]
name = "platformdirs"
version = "2.3.0"
description = "A small Python module for determining appropriate platform-specific dirs, e.g. a \"user data dir\"."
category = "dev"
optional = false
python-versions = ">=3.6"
[package.extras]
docs = ["Sphinx (>=4)", "furo (>=2021.7.5b38)", "proselint (>=0.10.2)", "sphinx-autodoc-typehints (>=1.12)"]
test = ["appdirs (==1.4.4)", "pytest (>=6)", "pytest-cov (>=2.7)", "pytest-mock (>=3.6)"]
[[package]]
name = "pluggy"
version = "0.13.1"
@@ -278,18 +293,20 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
[[package]]
name = "pylint"
version = "2.9.3"
version = "2.11.1"
description = "python code static checker"
category = "dev"
optional = false
python-versions = "~=3.6"
[package.dependencies]
astroid = ">=2.6.2,<2.7"
astroid = ">=2.8.0,<2.9"
colorama = {version = "*", markers = "sys_platform == \"win32\""}
isort = ">=4.2.5,<6"
mccabe = ">=0.6,<0.7"
platformdirs = ">=2.2.0"
toml = ">=0.7.1"
typing-extensions = {version = ">=3.10.0", markers = "python_version < \"3.10\""}
[[package]]
name = "pyparsing"
@@ -301,7 +318,7 @@ python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*"
[[package]]
name = "pytest"
version = "6.2.4"
version = "6.2.5"
description = "pytest: simple powerful testing with Python"
category = "dev"
optional = false
@@ -314,7 +331,7 @@ colorama = {version = "*", markers = "sys_platform == \"win32\""}
importlib-metadata = {version = ">=0.12", markers = "python_version < \"3.8\""}
iniconfig = "*"
packaging = "*"
pluggy = ">=0.12,<1.0.0a1"
pluggy = ">=0.12,<2.0"
py = ">=1.8.2"
toml = "*"
@@ -331,32 +348,32 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*"
[[package]]
name = "requests"
version = "2.25.1"
version = "2.26.0"
description = "Python HTTP for Humans."
category = "main"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*"
[package.dependencies]
certifi = ">=2017.4.17"
chardet = ">=3.0.2,<5"
idna = ">=2.5,<3"
charset-normalizer = {version = ">=2.0.0,<2.1.0", markers = "python_version >= \"3\""}
idna = {version = ">=2.5,<4", markers = "python_version >= \"3\""}
urllib3 = ">=1.21.1,<1.27"
[package.extras]
security = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)"]
socks = ["PySocks (>=1.5.6,!=1.5.7)", "win-inet-pton"]
use_chardet_on_py3 = ["chardet (>=3.0.2,<5)"]
[[package]]
name = "rope"
version = "0.19.0"
version = "0.20.1"
description = "a python refactoring library..."
category = "dev"
optional = false
python-versions = "*"
[package.extras]
dev = ["pytest"]
dev = ["pytest", "pytest-timeout"]
[[package]]
name = "six"
@@ -454,7 +471,7 @@ testing = ["pytest (>=4.6)", "pytest-checkdocs (>=1.2.3)", "pytest-flake8", "pyt
[metadata]
lock-version = "1.1"
python-versions = "^3.6"
content-hash = "e77a1bc014d3861a81147e6e21c99f6bf3dfe5cd9831c2c99964c4cd5d819611"
content-hash = "5ee93b78656e5bc815fc41056cd80448eac2f8cee62db11c140c7248ab8b2834"
[metadata.files]
appdirs = [
@@ -466,8 +483,8 @@ appdirs = [
{file = "aspy.yaml-1.3.0.tar.gz", hash = "sha256:e7c742382eff2caed61f87a39d13f99109088e5e93f04d76eb8d4b28aa143f45"},
]
astroid = [
{file = "astroid-2.6.2-py3-none-any.whl", hash = "sha256:606b2911d10c3dcf35e58d2ee5c97360e8477d7b9f3efc3f24811c93e6fc2cd9"},
{file = "astroid-2.6.2.tar.gz", hash = "sha256:38b95085e9d92e2ca06cf8b35c12a74fa81da395a6f9e65803742e6509c05892"},
{file = "astroid-2.8.0-py3-none-any.whl", hash = "sha256:dcc06f6165f415220013801642bd6c9808a02967070919c4b746c6864c205471"},
{file = "astroid-2.8.0.tar.gz", hash = "sha256:fe81f80c0b35264acb5653302ffbd935d394f1775c5e4487df745bf9c2442708"},
]
atomicwrites = [
{file = "atomicwrites-1.4.0-py2.py3-none-any.whl", hash = "sha256:6d1784dea7c0c8d4a5172b6c620f40b6e4cbfdf96d783691f2e1302a7b88e197"},
@@ -478,9 +495,8 @@ attrs = [
{file = "attrs-20.3.0.tar.gz", hash = "sha256:832aa3cde19744e49938b91fea06d69ecb9e649c93ba974535d08ad92164f700"},
]
beautifulsoup4 = [
{file = "beautifulsoup4-4.9.3-py2-none-any.whl", hash = "sha256:4c98143716ef1cb40bf7f39a8e3eec8f8b009509e74904ba3a7b315431577e35"},
{file = "beautifulsoup4-4.9.3-py3-none-any.whl", hash = "sha256:fff47e031e34ec82bf17e00da8f592fe7de69aeea38be00523c04623c04fb666"},
{file = "beautifulsoup4-4.9.3.tar.gz", hash = "sha256:84729e322ad1d5b4d25f805bfa05b902dd96450f43842c4e99067d5e1369eb25"},
{file = "beautifulsoup4-4.10.0-py3-none-any.whl", hash = "sha256:9a315ce70049920ea4572a4055bc4bd700c940521d36fc858205ad4fcde149bf"},
{file = "beautifulsoup4-4.10.0.tar.gz", hash = "sha256:c23ad23c521d818955a4151a67d81580319d4bf548d3d49f4223ae041ff98891"},
]
certifi = [
{file = "certifi-2020.12.5-py2.py3-none-any.whl", hash = "sha256:719a74fb9e33b9bd44cc7f3a8d94bc35e4049deebe19ba7d8e108280cfd59830"},
@@ -490,9 +506,9 @@ cfgv = [
{file = "cfgv-3.0.0-py2.py3-none-any.whl", hash = "sha256:f22b426ed59cd2ab2b54ff96608d846c33dfb8766a67f0b4a6ce130ce244414f"},
{file = "cfgv-3.0.0.tar.gz", hash = "sha256:04b093b14ddf9fd4d17c53ebfd55582d27b76ed30050193c14e560770c5360eb"},
]
chardet = [
{file = "chardet-4.0.0-py2.py3-none-any.whl", hash = "sha256:f864054d66fd9118f2e67044ac8981a54775ec5b67aed0441892edb553d21da5"},
{file = "chardet-4.0.0.tar.gz", hash = "sha256:0d6f53a15db4120f2b08c94f11e7d93d2c911ee118b6b30a04ec3ee8310179fa"},
charset-normalizer = [
{file = "charset-normalizer-2.0.1.tar.gz", hash = "sha256:ad0da505736fc7e716a8da15bf19a985db21ac6415c26b34d2fafd3beb3d927e"},
{file = "charset_normalizer-2.0.1-py3-none-any.whl", hash = "sha256:b68b38179052975093d71c1b5361bf64afd80484697c1f27056e50593e695ceb"},
]
click = [
{file = "click-8.0.1-py3-none-any.whl", hash = "sha256:fba402a4a47334742d782209a7c79bc448911afe1149d07bdabdf480b3e2f4b6"},
@@ -570,6 +586,10 @@ packaging = [
{file = "packaging-20.9-py2.py3-none-any.whl", hash = "sha256:67714da7f7bc052e064859c05c595155bd1ee9f69f76557e21f051443c20947a"},
{file = "packaging-20.9.tar.gz", hash = "sha256:5b327ac1320dc863dca72f4514ecc086f31186744b84a230374cc1fd776feae5"},
]
platformdirs = [
{file = "platformdirs-2.3.0-py3-none-any.whl", hash = "sha256:8003ac87717ae2c7ee1ea5a84a1a61e87f3fbd16eb5aadba194ea30a9019f648"},
{file = "platformdirs-2.3.0.tar.gz", hash = "sha256:15b056538719b1c94bdaccb29e5f81879c7f7f0f4a153f46086d155dffcd4f0f"},
]
pluggy = [
{file = "pluggy-0.13.1-py2.py3-none-any.whl", hash = "sha256:966c145cd83c96502c3c3868f50408687b38434af77734af1e9ca461a4081d2d"},
{file = "pluggy-0.13.1.tar.gz", hash = "sha256:15b2acde666561e1298d71b523007ed7364de07029219b604cf808bfa1c765b0"},
@@ -583,16 +603,16 @@ py = [
{file = "py-1.10.0.tar.gz", hash = "sha256:21b81bda15b66ef5e1a777a21c4dcd9c20ad3efd0b3f817e7a809035269e1bd3"},
]
pylint = [
{file = "pylint-2.9.3-py3-none-any.whl", hash = "sha256:5d46330e6b8886c31b5e3aba5ff48c10f4aa5e76cbf9002c6544306221e63fbc"},
{file = "pylint-2.9.3.tar.gz", hash = "sha256:23a1dc8b30459d78e9ff25942c61bb936108ccbe29dd9e71c01dc8274961709a"},
{file = "pylint-2.11.1-py3-none-any.whl", hash = "sha256:0f358e221c45cbd4dad2a1e4b883e75d28acdcccd29d40c76eb72b307269b126"},
{file = "pylint-2.11.1.tar.gz", hash = "sha256:2c9843fff1a88ca0ad98a256806c82c5a8f86086e7ccbdb93297d86c3f90c436"},
]
pyparsing = [
{file = "pyparsing-2.4.7-py2.py3-none-any.whl", hash = "sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b"},
{file = "pyparsing-2.4.7.tar.gz", hash = "sha256:c203ec8783bf771a155b207279b9bccb8dea02d8f0c9e5f8ead507bc3246ecc1"},
]
pytest = [
{file = "pytest-6.2.4-py3-none-any.whl", hash = "sha256:91ef2131a9bd6be8f76f1f08eac5c5317221d6ad1e143ae03894b862e8976890"},
{file = "pytest-6.2.4.tar.gz", hash = "sha256:50bcad0a0b9c5a72c8e4e7c9855a3ad496ca6a881a3641b4260605450772c54b"},
{file = "pytest-6.2.5-py3-none-any.whl", hash = "sha256:7310f8d27bc79ced999e760ca304d69f6ba6c6649c0b60fb0e04a4a77cacc134"},
{file = "pytest-6.2.5.tar.gz", hash = "sha256:131b36680866a76e6781d13f101efb86cf674ebb9762eb70d3082b6f29889e89"},
]
pyyaml = [
{file = "PyYAML-5.4.1-cp27-cp27m-macosx_10_9_x86_64.whl", hash = "sha256:3b2b1824fe7112845700f815ff6a489360226a5609b96ec2190a45e62a9fc922"},
@@ -626,11 +646,11 @@ pyyaml = [
{file = "PyYAML-5.4.1.tar.gz", hash = "sha256:607774cbba28732bfa802b54baa7484215f530991055bb562efbed5b2f20a45e"},
]
requests = [
{file = "requests-2.25.1-py2.py3-none-any.whl", hash = "sha256:c210084e36a42ae6b9219e00e48287def368a26d03a048ddad7bfee44f75871e"},
{file = "requests-2.25.1.tar.gz", hash = "sha256:27973dd4a904a4f13b263a19c866c13b92a39ed1c964655f025f3f8d3d75b804"},
{file = "requests-2.26.0-py2.py3-none-any.whl", hash = "sha256:6c1246513ecd5ecd4528a0906f910e8f0f9c6b8ec72030dc9fd154dc1a6efd24"},
{file = "requests-2.26.0.tar.gz", hash = "sha256:b8aa58f8cf793ffd8782d3d8cb19e66ef36f7aba4353eec859e74678b01b07a7"},
]
rope = [
{file = "rope-0.19.0.tar.gz", hash = "sha256:64e6d747532e1f5c8009ec5aae3e5523a5bcedf516f39a750d57d8ed749d90da"},
{file = "rope-0.20.1.tar.gz", hash = "sha256:505a2f6b4ac7b18e0429be179f4d8712243a194da5c866b0731f9d91ce7590bb"},
]
six = [
{file = "six-1.15.0-py2.py3-none-any.whl", hash = "sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced"},

View File

@@ -1,6 +1,6 @@
[tool.poetry]
name = "rfd"
version = "0.7.2"
version = "0.8.0"
description = "view RedFlagDeals.com from the command line"
authors = ["Dave Gallant <davegallant@gmail.com>"]
license = "GPL-3.0-or-later"
@@ -8,7 +8,7 @@ readme = "README.md"
[tool.poetry.dependencies]
python = "^3.6"
beautifulsoup4 = "<4.9.4"
beautifulsoup4 = "<4.10.1"
click = ">=7.0"
colorama = ">=0.4.3"
requests = ">=2.22.0"
@@ -16,9 +16,9 @@ soupsieve = "<3.0"
[tool.poetry.dev-dependencies]
pre-commit = "1.21.0"
pylint = "^2.9.3"
pylint = "^2.11.1"
pytest = ">=4.6.6"
rope = "0.19.0"
rope = "0.20.1"
[tool.poetry.scripts]
rfd = "rfd.__main__:cli"

View File

@@ -27,7 +27,7 @@ def get_safe_per_page(limit):
def create_user_map(users):
"""Create a map of user ids to usernames."""
m = dict()
m = {}
for user in users:
m[user.get("user_id")] = user.get("username")
return m
@@ -47,12 +47,12 @@ def get_threads(forum_id, pages):
try:
for page in range(1, pages + 1):
response = requests.get(
"{}/api/topics?forum_id={}&per_page=40&page={}".format(
API_BASE_URL, forum_id, page
)
f"{API_BASE_URL}/api/topics?forum_id={forum_id}&per_page=40&page={page}"
)
if response.status_code != 200:
raise Exception("When collecting threads, received a status code: %s" % response.status_code)
raise Exception(
f"When collecting threads, received a status code: {response.status_code}"
)
threads += response.json().get("topics")
except JSONDecodeError as err:
logging.error("Unable to decode threads. %s", err)
@@ -76,16 +76,14 @@ def get_posts(post):
raise ValueError()
response = requests.get(
"{}/api/topics/{}/posts?per_page=40&page=1".format(API_BASE_URL, post_id)
f"{API_BASE_URL}/api/topics/{post_id}/posts?per_page=40&page=1"
)
total_pages = response.json().get("pager").get("total_pages")
for page in range(0, total_pages + 1):
response = requests.get(
"{}/api/topics/{}/posts?per_page={}&page={}".format(
API_BASE_URL, post_id, 40, page
)
f"{API_BASE_URL}/api/topics/{post_id}/posts?per_page=40&page={page}"
)
users = create_user_map(response.json().get("users"))

View File

@@ -4,9 +4,10 @@ from __future__ import unicode_literals
import logging
import sys
import click
try:
from importlib import metadata
except ImportError: # for Python<3.8
except ImportError: # for Python<3.8
import importlib_metadata as metadata
from colorama import init
from .api import get_threads, get_posts
@@ -24,6 +25,7 @@ logging.getLogger().addHandler(logging.StreamHandler())
def get_version():
return "rfd v" + metadata.version("rfd")
def print_version(ctx, _, value):
if not value or ctx.resilient_parsing:
return
@@ -91,7 +93,9 @@ def threads(forum_id, pages, sort_by):
74 \t shopping discussion
88 \t cell phones
"""
_threads = sort_threads(parse_threads(get_threads(forum_id, pages)), sort_by=sort_by)
_threads = sort_threads(
parse_threads(get_threads(forum_id, pages)), sort_by=sort_by
)
click.echo_via_pager(generate_thread_output(_threads))

View File

@@ -3,19 +3,22 @@ import os
from colorama import Fore, Style
from .scores import get_vote_color
class Post:
def __init__(self, body, score, user):
self.body = body
self.score = score
self.user = user
def get_terminal_width():
_, columns = os.popen("stty size", "r").read().split()
return int(columns)
def generate_posts_output(posts):
output = ""
output += ("-" * get_terminal_width())
output += "-" * get_terminal_width()
for post in posts:
output += (
" -"
@@ -23,10 +26,10 @@ def generate_posts_output(posts):
+ Fore.RESET
+ post.body
+ Fore.YELLOW
+ " ({})".format(post.user)
+ f" ({post.user})"
)
output += (Style.RESET_ALL)
output += Style.RESET_ALL
output += "\n"
output += ("-" * get_terminal_width())
output += "-" * get_terminal_width()
output += "\n"
return output

View File

@@ -3,7 +3,7 @@ from colorama import Fore, Style
from . import API_BASE_URL
from .scores import calculate_score, get_vote_color
# pylint: disable=old-style-class
class Thread:
def __init__(self, title, dealer_name, score, url, views):
self.dealer_name = dealer_name
@@ -13,11 +13,11 @@ class Thread:
self.views = views
def __repr__(self):
return "Thread(%s)" % self.title
return f"Thread({self.title})"
def build_web_path(slug):
return "{}{}".format(API_BASE_URL, slug)
return f"{API_BASE_URL}{slug}"
def get_dealer(topic):
@@ -88,12 +88,12 @@ def generate_thread_output(threads):
+ "."
+ get_vote_color(thread.score)
+ Fore.RESET
+ "%s%s" % (dealer, thread.title)
+ f"{dealer}{thread.title}"
+ Fore.LIGHTYELLOW_EX
+ " (%d views)" % thread.views
+ f" ({thread.views} views)"
+ Fore.RESET
)
output += Fore.BLUE + " {}".format(thread.url)
output += Fore.BLUE + f" {thread.url}"
output += Style.RESET_ALL
output += "\n\n"
yield output