def test_check_if_spam_json(data, match): is_spam, reason, _ = check_if_spam_json(data) assert match == is_spam # Check that a malformed post isn't reported as spam is_spam, reason, _ = check_if_spam_json(None) assert not is_spam
GlobalVars.charcoal_hq.watch_socket(watcher) GlobalVars.tavern_on_the_meta.watch_socket(watcher) GlobalVars.socvr.watch_socket(watcher) if "first_start" in sys.argv and GlobalVars.on_master: GlobalVars.charcoal_hq.send_message(GlobalVars.s) GlobalVars.bayesian_testroom.send_message(GlobalVars.s) elif "first_start" in sys.argv and not GlobalVars.on_master: GlobalVars.charcoal_hq.send_message(GlobalVars.s_reverted) GlobalVars.bayesian_testroom.send_message(GlobalVars.s_reverted) while True: try: a = ws.recv() if a is not None and a != "": is_spam, reason, why = check_if_spam_json(a) if is_spam: t = Thread(target=GlobalVars.bodyfetcher.add_to_queue, args=(a, True)) t.start() print("Active threads: " + str(threading.active_count())) else: t = Thread(target=GlobalVars.bodyfetcher.add_to_queue, args=(a,)) t.start() print("Active threads: " + str(threading.active_count())) except Exception, e: exc_type, exc_obj, exc_tb = sys.exc_info() now = datetime.utcnow() delta = now - UtcDate.startup_utc_date seconds = delta.total_seconds()
metasmoke_ws_t = Thread(name="metasmoke websocket", target=Metasmoke.init_websocket) metasmoke_ws_t.start() Metasmoke.check_last_pingtime() # This will call itself every 10 seconds or so while True: try: a = ws.recv() if a is not None and a != "": action = json.loads(a)["action"] if action == "hb": ws.send("hb") if action == "155-questions-active": is_spam, reason, why = check_if_spam_json(a) t = Thread(name="bodyfetcher post enqueing", target=GlobalVars.bodyfetcher.add_to_queue, args=(a, True if is_spam else None)) t.start() except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() now = datetime.utcnow() delta = now - UtcDate.startup_utc_date seconds = delta.total_seconds() tr = traceback.format_exc() exception_only = ''.join(traceback.format_exception_only(type(e), e))\ .strip() n = os.linesep logged_msg = str(now) + " UTC" + n + exception_only + n + tr + n + n
def test_check_if_spam_json(data, match): is_spam, reason, _ = check_if_spam_json(data) assert match == is_spam
Thread(target=restart_automatically, args=(21600,)).start() Thread(target=watch_ci, args=()).start() ws = websocket.create_connection("ws://qa.sockets.stackexchange.com/") ws.send("155-questions-active") GlobalVars.charcoal_hq.join() GlobalVars.tavern_on_the_meta.join() GlobalVars.charcoal_hq.watch_socket(watcher) GlobalVars.tavern_on_the_meta.watch_socket(watcher) while True: try: a = ws.recv() if a is not None and a != "": is_spam, reason = check_if_spam_json(a) if is_spam: handle_spam_json(a, reason) else: t = Thread(target=GlobalVars.bodyfetcher.add_to_queue, args=(a,)) t.start() except Exception, e: exc_type, exc_obj, exc_tb = sys.exc_info() now = datetime.utcnow() delta = now - UtcDate.startup_utc_date seconds = delta.total_seconds() tr = traceback.format_exc() exception_only = ''.join(traceback.format_exception_only(type(e), e))\ .strip() n = os.linesep