mirror of
https://github.com/davegallant/rfd.git
synced 2025-08-07 09:02:32 +00:00
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>
This commit is contained in:
16
rfd/api.py
16
rfd/api.py
@@ -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"))
|
||||
|
||||
|
@@ -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))
|
||||
|
||||
|
||||
|
11
rfd/posts.py
11
rfd/posts.py
@@ -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
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user