Skip to content

Commit

Permalink
4ch: Add -j --json flag to store thread.json
Browse files Browse the repository at this point in the history
  • Loading branch information
sysr-q committed Oct 24, 2015
1 parent 54af59b commit 0bc651e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions 4ch
Expand Up @@ -4,6 +4,7 @@ from __future__ import print_function

import argparse
import errno
import json
import os.path
import sys
import urllib
Expand All @@ -19,8 +20,8 @@ p.add_argument("threads", type=int, nargs="+",
help="Thread res id, e.g. 12345678.")
p.add_argument("-i", "--ignore", action="store_true",
help="Ignore given threads that don't exist.")
# p.add_argument("-j", "--json", action="store_true",
# help="Store thread.json with replies and metadata.")
p.add_argument("-j", "--json", action="store_true",
help="Store thread.json with replies and metadata.")
# TODO: exponential backoff
# p.add_argument("-f", "--follow", action="store_true",
# help="Follow thread polling periodically for new images.")
Expand Down Expand Up @@ -64,6 +65,12 @@ def main():
args.out.format(board=t._board.name, thread=t.op.number))
mkdir_p(out)

if args.json:
with open(os.path.join(out, "thread.json"), "wb") as f:
f.write(json.dumps({
"op": t.op._json,
"replies": [r._json for r in t.replies]}))

images = list(t.images) # So we can len() it
header = ">>> Downloading image {{0}}/{0} from /{1}/{2}".format(
len(images), t._board.name, t.op.number)
Expand Down

0 comments on commit 0bc651e

Please sign in to comment.