Title: [Python] fillybot.py Author: Anonymous Pastebin link: http://pastebin.com/mYunXcaQ First Edit: Tuesday 20th of September 2016 12:35:13 PM CDT Last Edit: Tuesday 20th of September 2016 12:35:13 PM CDT import b4k import sys import time import random import yotsuba import math import re   def main(argv):     threads_done = []         while True:         #log("running loop")                 fourchanpass = b4k.read("/home/bakugo/4chan-pass.txt")         fourchanpass = (fourchanpass.strip() if fourchanpass else None)                 if not fourchanpass:             log("error: no 4chan pass")             time.sleep(30)             continue                 images = b4k.scan_dir("images", True)                 if not images or not len(images):             log("error: no images")             time.sleep(30)             continue                 image = random.choice(images)                 try:             catalog = yotsuba.get({                 "type": "catalog",                 "board": "mlp"             })         except:             log("error: board catalog request failed")             time.sleep(10)             continue                 if not catalog or not len(catalog):             log("error: board catalog is empty")             time.sleep(30)             continue                 timenow = math.floor(time.time())                 thread_target = None                 for page in catalog:             for thread in page["threads"]:                 if not thread["no"] in threads_done:                     if ("sub" in thread and re.search(r'^mlp general\b', thread["sub"], re.IGNORECASE)) or ("name" in thread and re.search(r'^mlp general$', thread["name"], re.IGNORECASE)):                         if thread["replies"] < 10 and ((timenow - thread["time"]) < (60*5)):                             if thread_target == None or thread["time"] < thread_target["time"]:                                 thread_target = thread                 if not thread_target:             log("no valid target thread")             time.sleep(10)             continue                 if thread_target["replies"] < 3:             if (timenow - thread_target["time"]) < 40:                 time.sleep(max(1, ((40 - (timenow - thread_target["time"])) + random.randint(-5, 5))))                 try:             postno = yotsuba.post({                 "board": "mlp",                 "thread": thread_target["no"],                 "comment": ">filly",                 "file": open(image, "rb"),                 "filename": str(math.floor(time.time() * 1000)),                 "delpass": "ilovefillies",                 "passid": fourchanpass             })                         log("post successful (no: " + str(postno) + ")")             threads_done.append(thread_target["no"])             time.sleep(60)         except Exception as exception:             if isinstance(exception, yotsuba.PostRejectedError):                 errmsg = str(exception)                 errmsgparse = errmsg.lower()                                 log("error: post rejected - " + errmsg)                                 if "banned" in errmsgparse:                     time.sleep(600)                 elif "duplicate reply" in errmsgparse:                     time.sleep(120)                 else:                     time.sleep(10)             else:                 log("error: post failed - " + str(exception))                 time.sleep(10)                 continue         return 0   def log(string):     string = ("[" + time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime()) + "] " + string)         print(string)         b4k.write("./log.txt", (string + "\n"), False)   if __name__ == "__main__":     sys.exit(main(sys.argv))