mirror of
https://github.com/davegallant/rfd.git
synced 2025-08-06 00:33:40 +00:00
fix 0 score bug and pip 10 requirements (#5)
* fix 0 score bug and pip 10 requirements * calculate score for both topic and posts using same function.
This commit is contained in:
9
Pipfile
9
Pipfile
@@ -1,14 +1,21 @@
|
||||
[[source]]
|
||||
|
||||
name = "pypi"
|
||||
url = "https://pypi.python.org/simple"
|
||||
verify_ssl = true
|
||||
|
||||
|
||||
[packages]
|
||||
beautifulsoup4 = "*"
|
||||
|
||||
"beautifulsoup4" = "*"
|
||||
click = "*"
|
||||
colorama = "*"
|
||||
requests = "*"
|
||||
|
||||
|
||||
[dev-packages]
|
||||
|
||||
pylint = "*"
|
||||
pytest = "*"
|
||||
"autopep8" = "*"
|
||||
rope = "*"
|
||||
|
32
Pipfile.lock
generated
32
Pipfile.lock
generated
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "a09db029f4e056a84d39e595ac01668503071a9ec6272e1e721e909be02adc56"
|
||||
"sha256": "59a16b0c3d0df550a0ea78a93a327aad8fde804dd099c7f14190c1d9cfd4bb36"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {},
|
||||
@@ -24,10 +24,10 @@
|
||||
},
|
||||
"certifi": {
|
||||
"hashes": [
|
||||
"sha256:14131608ad2fd56836d33a71ee60fa1c82bc9d2c8d98b7bdbc631fe1b3cd1296",
|
||||
"sha256:edbc3f203427eef571f79a7692bb160a2b0f7ccaa31953e99bd17e307cf63f7d"
|
||||
"sha256:13e698f54293db9f89122b0581843a782ad0934a4fe0172d2a980ba77fc61bb7",
|
||||
"sha256:9fa520c1bacfb634fa7af20a76bcbd3d5fb390481724c597da32c719a7dca4b0"
|
||||
],
|
||||
"version": "==2018.1.18"
|
||||
"version": "==2018.4.16"
|
||||
},
|
||||
"chardet": {
|
||||
"hashes": [
|
||||
@@ -87,6 +87,12 @@
|
||||
],
|
||||
"version": "==17.4.0"
|
||||
},
|
||||
"autopep8": {
|
||||
"hashes": [
|
||||
"sha256:2284d4ae2052fedb9f466c09728e30d2e231cfded5ffd7b1a20c34123fdc4ba4"
|
||||
],
|
||||
"version": "==1.3.5"
|
||||
},
|
||||
"backports.functools-lru-cache": {
|
||||
"hashes": [
|
||||
"sha256:9d98697f088eb1b0fa451391f91afb5e3ebde16bbdb272819fd091151fda4f1a",
|
||||
@@ -186,7 +192,9 @@
|
||||
},
|
||||
"pluggy": {
|
||||
"hashes": [
|
||||
"sha256:7f8ae7f5bdf75671a718d2daf0a64b7885f74510bcd98b1a0bb420eb9a9d0cff"
|
||||
"sha256:7f8ae7f5bdf75671a718d2daf0a64b7885f74510bcd98b1a0bb420eb9a9d0cff",
|
||||
"sha256:d345c8fe681115900d6da8d048ba67c25df42973bda370783cd58826442dcd7c",
|
||||
"sha256:e160a7fcf25762bb60efc7e171d4497ff1d8d2d75a3d0df7a21b76821ecbf5c5"
|
||||
],
|
||||
"version": "==0.6.0"
|
||||
},
|
||||
@@ -197,6 +205,14 @@
|
||||
],
|
||||
"version": "==1.5.3"
|
||||
},
|
||||
"pycodestyle": {
|
||||
"hashes": [
|
||||
"sha256:74abc4e221d393ea5ce1f129ea6903209940c1ecd29e002e8c6933c2b21026e0",
|
||||
"sha256:cbc619d09254895b0d12c2c691e237b2e91e9b2ecf5e84c26b35400f93dcfb83",
|
||||
"sha256:cbfca99bd594a10f674d0cd97a3d802a1fdef635d4361e1a2658de47ed261e3a"
|
||||
],
|
||||
"version": "==2.4.0"
|
||||
},
|
||||
"pylint": {
|
||||
"hashes": [
|
||||
"sha256:0b7e6b5d9f1d4e0b554b5d948f14ed7969e8cdf9a0120853e6e5af60813b18ab",
|
||||
@@ -211,6 +227,12 @@
|
||||
],
|
||||
"version": "==3.5.0"
|
||||
},
|
||||
"rope": {
|
||||
"hashes": [
|
||||
"sha256:a09edfd2034fd50099a67822f9bd851fbd0f4e98d3b87519f6267b60e50d80d1"
|
||||
],
|
||||
"version": "==0.10.7"
|
||||
},
|
||||
"singledispatch": {
|
||||
"hashes": [
|
||||
"sha256:5b06af87df13818d14f08a028e42f566640aef80805c3b50c5056b086e3c2b9c",
|
||||
|
@@ -1,4 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
__version__ = '0.0.8'
|
||||
__version__ = '0.1.0'
|
||||
|
24
rfd/api.py
24
rfd/api.py
@@ -26,8 +26,23 @@ def is_int(number):
|
||||
return False
|
||||
|
||||
|
||||
def get_vote_score(up_vote, down_vote):
|
||||
return up_vote - down_vote
|
||||
def calculate_score(post):
|
||||
"""Calculate either topic or post score. If votes cannot be retrieved, the score is 0.
|
||||
|
||||
Arguments:
|
||||
post {dict} -- pass in the topic/post object
|
||||
|
||||
Returns:
|
||||
int -- score
|
||||
"""
|
||||
score = 0
|
||||
try:
|
||||
score = int(post.get('votes').get('total_up')) - \
|
||||
int(post.get('votes').get('total_down'))
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
return score
|
||||
|
||||
|
||||
def get_safe_per_page(limit):
|
||||
@@ -61,7 +76,7 @@ def get_threads(forum_id, limit):
|
||||
for topic in response.json().get('topics'):
|
||||
threads.append({
|
||||
'title': topic.get('title'),
|
||||
'score': get_vote_score(topic.get('votes').get('total_up'), topic.get('votes').get('total_down')),
|
||||
'score': calculate_score(topic),
|
||||
'url': build_web_path(topic.get('web_path')),
|
||||
})
|
||||
return threads[:limit]
|
||||
@@ -134,8 +149,7 @@ def get_posts(post, count=5, tail=False, per_page=40):
|
||||
return
|
||||
# Sometimes votes is null
|
||||
if _post.get('votes') is not None:
|
||||
calculated_score = get_vote_score(_post.get('votes').get(
|
||||
'total_up'), _post.get('votes').get('total_down'))
|
||||
calculated_score = calculate_score(_post)
|
||||
else:
|
||||
calculated_score = 0
|
||||
yield{
|
||||
|
10
setup.py
10
setup.py
@@ -1,7 +1,10 @@
|
||||
import io # for python2
|
||||
from os import path
|
||||
from setuptools import setup
|
||||
from pip.req import parse_requirements
|
||||
try: # for pip >= 10
|
||||
from pip._internal.req import parse_requirements
|
||||
except ImportError: # for pip <= 9.0.3
|
||||
from pip.req import parse_requirements
|
||||
from version import __version__ as version
|
||||
|
||||
WORKING_DIR = path.abspath(path.dirname(__file__))
|
||||
@@ -11,7 +14,8 @@ with io.open(path.join(WORKING_DIR, 'README.rst'), encoding='utf-8') as f:
|
||||
long_description = f.read()
|
||||
|
||||
# read requirements.txt and load into list
|
||||
REQUIREMENTS_TXT = parse_requirements(path.join(WORKING_DIR, "requirements.txt"), session='my_session')
|
||||
REQUIREMENTS_TXT = parse_requirements(
|
||||
path.join(WORKING_DIR, "requirements.txt"), session='my_session')
|
||||
REQUIREMENTS = [str(r.req) for r in REQUIREMENTS_TXT]
|
||||
|
||||
setup(
|
||||
@@ -21,7 +25,7 @@ setup(
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
'rfd = rfd.rfd_cli:cli',
|
||||
],
|
||||
],
|
||||
},
|
||||
install_requires=REQUIREMENTS,
|
||||
keywords='cli redflagdeals',
|
||||
|
Reference in New Issue
Block a user