def Archive( thread, board, path, nothumbs, thumbsonly, delay ):
        
        # Set a default path if none is given
        if (path == None):
          path = os.path.join(os.getcwd() + os.path.sep + _DEFAULT_FOLDER)

        # Initiate py4chan object
        curr_board = py4chan.Board(board)
        curr_thread = curr_board.getThread(int(thread))

        # Switch to tell first run
        firstIteration = True

        # try/except to handle Ctrl-C
        try:
          while 1:
          # don't run this code the first time
          if (firstIteration == False):
              # Wait to execute code again
              self._log_callback("Waiting %s seconds before retrying (Type Ctrl-C to stop)\n" % delay)
              time.sleep(int(delay))
              
              if curr_thread.is_404:
            self._log_callback("[Thread 404'ed or Connection Lost]")
            break
              
              # Update thread and check if new replies have appeared
              newReplies = curr_thread.update()
              if (newReplies == 0):
            continue
              else:
            self._log_callback("%s new replies found!" % newReplies)
예제 #2
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 = py4chan.Board(sys.argv[1])
    thread = board.get_thread(int(sys.argv[2]))
    for file in thread.files():
        print(file)
예제 #3
0
def main():
    v = py4chan.Board('v')
    thread = v.getThread(152900882)
    print thread
    print 'Sticky?', thread.Sticky
    print 'Closed?', thread.Closed
    topic = thread.topic
    print 'Topic Repr', topic
    print 'PostNumber', topic.PostNumber
    print 'Timestamp', topic.Timestamp
    print 'DateTime', repr(topic.Datetime)
    print 'FileMd5Hex', topic.FileMd5Hex
    print 'FileUrl', topic.FileUrl
    print 'Subject', topic.Subject
    print 'Comment', topic.Comment
    print 'ThumbnailUrl', topic.ThumbnailUrl
    print 'Replies', thread.replies
예제 #4
0
def main():
    v = py4chan.Board('v')
    thread = v.get_thread(152900882)
    print(thread)
    print('Sticky?', thread.sticky)
    print('Closed?', thread.closed)
    topic = thread.topic
    print('Topic Repr', topic)
    print('Postnumber', topic.post_number)
    print('Timestamp', topic.timestamp)
    print('Datetime', repr(topic.datetime))
    print('Filemd5hex', topic.file_md5_hex)
    print('Fileurl', topic.file_url)
    print('Subject', topic.subject)
    print('Comment', topic.comment)
    print('Thumbnailurl', topic.thumbnail_url)
    print('Replies', thread.replies)
    print('All posts', thread.all_posts)
예제 #5
0
# credits to Anarov for improved example.py
# https://github.com/Anorov/py-4chan

import sys
sys.path.insert(0, '../')

import py4chan

b = py4chan.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.post_url)
예제 #6
0
def main(args):
    """
        Check 4chan API for new content, and recursively dump thread
    """
    # Stop the script if the given URL is malformed
    if (check_url(args.get('<url>')) == ""):
        print(_TAG + "The URL is invalid, or it isn't a 4chan thread URL.")
        raise SystemExit(0)

    # Copy data from docopt arguments
    thread = args.get('<url>').split('/')[5]
    board = args.get('<url>').split('/')[3]
    path = args.get('--path')
    runonce = args.get('--runonce', False)
    #    silent = args.get('--silent', False)       # must implement silent later
    delay = args.get('--delay')
    nothumbs = args.get('--nothumbs', False)
    thumbsonly = args.get('--thumbsonly', False)
    enablessl = args.get('--enablessl', False)

    # Set a default path if none is given
    if (path == None):
        path = os.path.join(os.getcwd() + os.path.sep + _DEFAULT_FOLDER)

    # Set destination directory
    dst_dir = os.path.join(path, board, thread)

    # Initialize py4chan Board object, enable https
    curr_board = py4chan.Board(board, https=enablessl)

    # Check if the thread exists, then create py4chan thread object. Stop if not found
    try:
        if (curr_board.threadExists(int(thread))):
            curr_thread = curr_board.getThread(int(thread))


#      if (curr_board.thread_exists(int(thread))):
#        curr_thread = curr_board.get_thread(int(thread))       # BA py-4chan 0.3
        else:
            print(_TAG + "Thread %s not found." % thread)
            print(
                _TAG +
                "Either the thread already 404'ed, your URL is incorrect, or you aren't connected to the internet"
            )
            raise SystemExit(0)
    # FIXME: Handles the error of no internet connection, but better to except requests.exceptions.ConnectionError:
    except:
        print(_TAG + "Unable to connect to the internet.")
        raise SystemExit(0)

    # header
    print(_TAG + 'Board : 4chan /%s/' % board)
    print(_TAG + 'Thread: %s' % thread)
    print(_TAG + 'Folder: %s' % dst_dir)

    # Using try/except loop to handle Ctrl-C
    try:
        # Switch to check for first run
        first_iteration = True

        running = True

        while running:
            # don't run this code the first time
            if (first_iteration == False):

                # Wait to execute code again
                print(
                    "\n" + _TAG +
                    "Waiting %s seconds before retrying (Type Ctrl-C to stop)"
                    % delay)
                time.sleep(int(delay))

                if curr_thread.is_404:
                    # Stop when thread gets 404'ed
                    print(_TAG + "%s - [Thread 404'ed or Connection Lost]" %
                          timestamp())
                    print(
                        " :: Dump complete. To resume dumping the same thread,\nrun this script again."
                    )
                    raise SystemExit(0)

                # Update thread and check if new replies have appeared
                new_replies = curr_thread.update()
                if (new_replies == 0):
                    print(_TAG + "%s - [No new posts.]" % timestamp())
                    continue

                else:
                    print(_TAG + "%s - [%s new post(s) found!]" %
                          (timestamp(), new_replies))

                # If all tests are OK, dump thread again
                dump(dst_dir,
                     board,
                     thread,
                     curr_thread,
                     nothumbs,
                     thumbsonly,
                     https=enablessl)

                # If the 'runonce' flag is set, then end the loop and exit early
                if runonce: running = False

            else:
                # dump thread for the first time
                dump(dst_dir,
                     board,
                     thread,
                     curr_thread,
                     nothumbs,
                     thumbsonly,
                     https=enablessl)

                # first iteration is complete
                first_iteration = False

    except KeyboardInterrupt:
        """ Stop try/except loop when [Ctrl-C] is pressed"""
        print("\n")
        print(
            " :: Dump complete. To resume dumping the same thread,\nrun this script again."
        )
        raise SystemExit(0)