def main():
    if len(sys.argv) < 2 or len(sys.argv) > 3:
        print("Quick and dirty 4chan Archiver")
        print("%s - Save the JSON and all images for an 4chan post." % (sys.argv[0]))
        print("\tUsage: %s <board> <thread_id>" % (sys.argv[0]))
        sys.exit(1)

    board_name = sys.argv[1]
    thread_id = sys.argv[2]

    # grab the first thread on the board by checking first page
    board = basc_py4chan.get_board(board_name)
    thread = board.get_thread(thread_id)

    # create folders according to chan.arc standard
    path = os.path.join(os.getcwd(), "4chan", board_name, thread_id)
    images_path = os.path.join(path, "images")
    mkdirs(images_path)

    # archive the thread JSON
    url_builder = basc_py4chan.Url(board_name)
    json_url = url_builder.thread_api_url(thread_id)
    print(url_builder.thread_api_url(thread_id))
    download_json(os.path.join(path, "%s.json" % thread_id), json_url)

    # record the url of every file on the first thread, even extra files in posts
    for img in thread.file_objects():
        print("Downloading %s..." % img.file_url)
        download_file(os.path.join(images_path, "%s" % img.filename), img.file_url)
Esempio n. 2
0
def main():
    # grab the first thread on the board by checking first page
    board = basc_py4chan.get_board('v')
    all_thread_ids = board.get_all_thread_ids()
    first_thread_id = all_thread_ids[0]
    thread = board.get_thread(first_thread_id)

    # thread information
    print(thread)
    print('Sticky?', thread.sticky)
    print('Closed?', thread.closed)

    # topic information
    topic = thread.topic
    print('Topic Repr', topic)
    print('Postnumber', topic.post_number)
    print('Timestamp', topic.timestamp)
    print('Datetime', repr(topic.datetime))
    print('Subject', topic.subject)
    print('Comment', topic.text_comment)
    print('Replies', thread.replies)

    # file information
    for f in thread.file_objects():
        print('Filename', f.filename)
        print('  Filemd5hex', f.file_md5_hex)
        print('  Fileurl', f.file_url)
        print('  Thumbnailurl', f.thumbnail_url)
        print()
Esempio n. 3
0
def main():
    # grab the first thread on the board by checking first page
    board = basc_py4chan.get_board('v')
    all_thread_ids = board.get_all_thread_ids()
    first_thread_id = all_thread_ids[0]
    thread = board.get_thread(first_thread_id)

    # display the url of every file on the first thread, even extra files in posts
    for url in thread.files():
        print(url)
Esempio n. 4
0
def main():
    if len(sys.argv) != 3:
        print("Usage: python %s [board] [thread]" % sys.argv[0])
        print("Shows the URL of all the files in the thread.")
        print("Example (download all files in thread): python %s v 12351234 | xargs wget"
              % sys.argv[0])
        return

    board = basc_py4chan.get_board(sys.argv[1])
    thread = board.get_thread(int(sys.argv[2]))
    for f in thread.files():
        print(f)
def main():
    # grab the first thread on the board by checking first page
    board = basc_py4chan.get_board("v")
    all_thread_ids = board.get_all_thread_ids()
    first_thread_id = all_thread_ids[0]
    thread = board.get_thread(first_thread_id)

    # display info about every file on the first thread, even extra files in posts
    for post in thread.all_posts:
        if post.has_file:
            print(":: Post #", post.post_number)
            print("  ", post.file.filename)
            print("  ", post.file.file_md5_hex)
            print("  ", post.file.file_url)
            print("  ", post.file.thumbnail_url)
            print()
Esempio n. 6
0
# credits to Anarov for improved example.py
from __future__ import print_function

import basc_py4chan

b = basc_py4chan.get_board('b')
threads = b.get_threads()
print("Got %i threads" % len(threads))
first_thread = threads[0]
print("First thread: %r" % first_thread)
print("Replies: %r" % first_thread.replies)
print("Updating first thread...")
first_thread.update()
print("First thread now: %r" % first_thread)
for post in first_thread.replies:
    print(post.url)