From 0965aa050701e982931661e1de93f10df33f8c28 Mon Sep 17 00:00:00 2001 From: Dave Gallant Date: Sun, 8 Sep 2019 23:26:42 -0400 Subject: [PATCH] cleanup setup.py (#16) * cleanup setup. * fix pylint. --- MANIFEST.in | 1 + README.md | 2 +- requirements.txt | 4 ++ requirements_dev.txt | 4 ++ rfd/__version__.py | 2 +- rfd/api.py | 2 +- setup.py | 21 +++++---- tests/test_api.py | 101 +++++++++++++++++++++++++++---------------- 8 files changed, 89 insertions(+), 48 deletions(-) create mode 100644 requirements.txt create mode 100644 requirements_dev.txt diff --git a/MANIFEST.in b/MANIFEST.in index b65dcfa..0ee4b20 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,3 @@ include requirements.txt +include requirements_dev.txt include rfd/__version__.py \ No newline at end of file diff --git a/README.md b/README.md index f4edf0e..9913a1f 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ pip install rfd ## Usage -![rfd_demo_gif](https://user-images.githubusercontent.com/4519234/47625817-d3375500-dafd-11e8-9d86-491d4a4fb225.gif) +![rfd_demo_gif](https://user-images.githubusercontent.com/4519234/64501455-64836600-d28f-11e9-8381-3fbfda910230.gif) ```bash diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..49a740f --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +beautifulsoup4>=4.6.0 +click>=7.0 +colorama>=0.3.9 +requests>=2.18.0 \ No newline at end of file diff --git a/requirements_dev.txt b/requirements_dev.txt new file mode 100644 index 0000000..98eafc1 --- /dev/null +++ b/requirements_dev.txt @@ -0,0 +1,4 @@ +rope +black +pylint +pytest \ No newline at end of file diff --git a/rfd/__version__.py b/rfd/__version__.py index 98d000f..92b8ecb 100644 --- a/rfd/__version__.py +++ b/rfd/__version__.py @@ -1,4 +1,4 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -version = '0.1.8' +version = '0.1.9' diff --git a/rfd/api.py b/rfd/api.py index 253fb4f..bb3d148 100644 --- a/rfd/api.py +++ b/rfd/api.py @@ -180,7 +180,7 @@ def get_posts(post, count=5, tail=False, per_page=40): _posts = response.json().get("posts") # Determine which post to start with (for --tail) - if page == start_page and not start_post == 0: + if page == start_page and start_post != 0: if tail: _posts = _posts[start_post - 1 :] else: diff --git a/setup.py b/setup.py index d470152..e9441cc 100644 --- a/setup.py +++ b/setup.py @@ -3,29 +3,34 @@ from os import path from setuptools import setup, find_packages from rfd.__version__ import version + +def load_requirements(file_name): + """ Reads and returns requirements """ + with io.open(path.join(WORKING_DIR, file_name)) as handle: + raw_reqs = handle.read().strip().split("\n") + reqs = [req for req in raw_reqs] + return reqs + + WORKING_DIR = path.abspath(path.dirname(__file__)) +REQUIREMENTS = load_requirements("requirements.txt") +TEST_REQUIREMENTS = load_requirements("requirements_dev.txt") # Get long description from README.md with io.open(path.join(WORKING_DIR, "README.md"), encoding="utf-8") as f: long_description = f.read() - setup( author="Dave Gallant", description="CLI for RedFlagDeals.com", entry_points={"console_scripts": ["rfd = rfd.rfd_cli:cli"]}, - install_requires=[ - "beautifulsoup4>=4.6.0", - "click>=7.0", - "colorama>=0.3.9", - "requests>=2.18.0", - ], + install_requires=REQUIREMENTS, keywords="cli redflagdeals", license="Apache License, Version 2.0", long_description=long_description, long_description_content_type="text/markdown", name="rfd", packages=find_packages(), - url="https://github.com/davegallant/rfd_cli", + url="https://github.com/davegallant/rfd", version=version, ) diff --git a/tests/test_api.py b/tests/test_api.py index ac5c9a0..c3d8d2d 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -6,47 +6,74 @@ def test_build_web_path(): def test_extract_post_id(): - assert extract_post_id( - "https://forums.redflagdeals.com/targeted-bob-2173603/120") == '2173603' - assert extract_post_id( - "http://forums.redflagdeals.com/targeted-2173604/120") == '2173604' + assert ( + extract_post_id("https://forums.redflagdeals.com/targeted-bob-2173603/120") + == "2173603" + ) + assert ( + extract_post_id("http://forums.redflagdeals.com/targeted-2173604/120") + == "2173604" + ) def test_parse_threads(threads_api_response): assert len(parse_threads(threads_api_response, 10)) == len( - [{'score': 0, - 'title': '[Sponsored] 3 Months Free, Cable 75M, Unlimited Internet $34.99/30 ' - 'Days, Free Installation/Modem Rental', - 'url': 'https://forums.redflagdeals.com/carrytel-sponsored-3-months-free-cable-75m-unlimited-internet-34-99-30-days-free-installation-modem-rental-2197859/'}, - {'score': 92, - 'title': 'WyzeCam 1080p HD Wireless Smart Home Camera v2 $37.49', - 'url': 'https://forums.redflagdeals.com/amazon-ca-wyzecam-1080p-hd-wireless-smart-home-camera-v2-37-49-2191108/'}, - {'score': 8, - 'title': 'Jabra Elite 65T $169.99', - 'url': 'https://forums.redflagdeals.com/best-buy-jabra-elite-65t-169-99-2197916/'}, - {'score': 1, - 'title': 'Glad Cling Wrap Plastic Wrap, 300 Metre Roll - best price $9.47', - 'url': 'https://forums.redflagdeals.com/amazon-ca-glad-cling-wrap-plastic-wrap-300-metre-roll-best-price-9-47-2198211/'}, - {'score': 17, - 'title': 'Firman 3300 inverter generator $599', - 'url': 'https://forums.redflagdeals.com/costco-firman-3300-inverter-generator-599-2195171/'}, - {'score': 3, - 'title': 'HOT - KitchenAid Stand Mixer - $199', - 'url': 'https://forums.redflagdeals.com/walmart-hot-kitchenaid-stand-mixer-199-2198199/'}, - {'score': -1, - 'title': 'Seagate Expansion 4TB Portable External Hard Drive USB 3.0 ' - '(STEA4000400) $119.92', - 'url': 'https://forums.redflagdeals.com/amazon-ca-seagate-expansion-4tb-portable-external-hard-drive-usb-3-0-stea4000400-119-92-2198164/'}, - {'score': 0, - 'title': 'WORKSHOP Wet Dry Vacs Ash Vacuum Cleaner WS0500ASH, 5-Gallon Ash ' - 'Vac 65% Off, Now: $48.54', - 'url': 'https://forums.redflagdeals.com/workshop-wet-dry-vacs-ash-vacuum-cleaner-ws0500ash-5-gallon-ash-vac-65-off-now-48-54-2198212/'}, - {'score': 4, - 'title': 'NBA 2K18 (Nintendo Switch) -$19.99 or $16.99 PM', - 'url': 'https://forums.redflagdeals.com/the-source-nba-2k18-nintendo-switch-19-99-16-99-pm-2198191/'}, - {'score': 5, - 'title': 'CROCS.CA 40%OFF Select style - at checkout', - 'url': 'https://forums.redflagdeals.com/crocs-crocs-ca-40-off-select-style-checkout-2198145/'}]) + [ + { + "score": 0, + "title": "[Sponsored] 3 Months Free, Cable 75M, Unlimited Internet $34.99/30 " + "Days, Free Installation/Modem Rental", + "url": "https://forums.redflagdeals.com/carrytel-sponsored-3-months-free-cable-75m-unlimited-internet-34-99-30-days-free-installation-modem-rental-2197859/", + }, + { + "score": 92, + "title": "WyzeCam 1080p HD Wireless Smart Home Camera v2 $37.49", + "url": "https://forums.redflagdeals.com/amazon-ca-wyzecam-1080p-hd-wireless-smart-home-camera-v2-37-49-2191108/", + }, + { + "score": 8, + "title": "Jabra Elite 65T $169.99", + "url": "https://forums.redflagdeals.com/best-buy-jabra-elite-65t-169-99-2197916/", + }, + { + "score": 1, + "title": "Glad Cling Wrap Plastic Wrap, 300 Metre Roll - best price $9.47", + "url": "https://forums.redflagdeals.com/amazon-ca-glad-cling-wrap-plastic-wrap-300-metre-roll-best-price-9-47-2198211/", + }, + { + "score": 17, + "title": "Firman 3300 inverter generator $599", + "url": "https://forums.redflagdeals.com/costco-firman-3300-inverter-generator-599-2195171/", + }, + { + "score": 3, + "title": "HOT - KitchenAid Stand Mixer - $199", + "url": "https://forums.redflagdeals.com/walmart-hot-kitchenaid-stand-mixer-199-2198199/", + }, + { + "score": -1, + "title": "Seagate Expansion 4TB Portable External Hard Drive USB 3.0 " + "(STEA4000400) $119.92", + "url": "https://forums.redflagdeals.com/amazon-ca-seagate-expansion-4tb-portable-external-hard-drive-usb-3-0-stea4000400-119-92-2198164/", + }, + { + "score": 0, + "title": "WORKSHOP Wet Dry Vacs Ash Vacuum Cleaner WS0500ASH, 5-Gallon Ash " + "Vac 65% Off, Now: $48.54", + "url": "https://forums.redflagdeals.com/workshop-wet-dry-vacs-ash-vacuum-cleaner-ws0500ash-5-gallon-ash-vac-65-off-now-48-54-2198212/", + }, + { + "score": 4, + "title": "NBA 2K18 (Nintendo Switch) -$19.99 or $16.99 PM", + "url": "https://forums.redflagdeals.com/the-source-nba-2k18-nintendo-switch-19-99-16-99-pm-2198191/", + }, + { + "score": 5, + "title": "CROCS.CA 40%OFF Select style - at checkout", + "url": "https://forums.redflagdeals.com/crocs-crocs-ca-40-off-select-style-checkout-2198145/", + }, + ] + ) assert len(parse_threads(None, 10)) == 0