mirror of
https://github.com/davegallant/rfd.git
synced 2025-08-07 00:58:14 +00:00
Add json output flag (#139)
This commit is contained in:
12
rfd/posts.py
12
rfd/posts.py
@@ -1,5 +1,6 @@
|
||||
# pylint: disable=old-style-class
|
||||
import os
|
||||
import json
|
||||
from colorama import Fore, Style
|
||||
from .scores import get_vote_color
|
||||
|
||||
@@ -11,6 +12,17 @@ class Post:
|
||||
self.user = user
|
||||
|
||||
|
||||
class PostEncoder(json.JSONEncoder):
|
||||
def default(self, o):
|
||||
if isinstance(o, Post):
|
||||
return dict(
|
||||
body=o.body,
|
||||
score=o.score,
|
||||
user=o.user,
|
||||
)
|
||||
return json.JSONEncoder.default(self, o)
|
||||
|
||||
|
||||
def get_terminal_width():
|
||||
_, columns = os.popen("stty size", "r").read().split()
|
||||
return int(columns)
|
||||
|
Reference in New Issue
Block a user