```python # near beginning of script blacklist_json = "vpn_blacklist.json" suspicious_ips_json = "vpn_suspectlist.json" def flag(IP, **kwargs): write_file = False print(suspicious_ips) passed_reason = kwargs.get("reason", "Suspicious Activity") if IP in suspicious_ips.keys(): if suspicious_ips[IP] >= max_global_attempts: task_queue.put(blacklist(IP, 10080, reason=passed_reason)) #logging.info(f"Blacklisted: {i.IP},") #print else: suspicious_ips[IP] += 1 logging.debug(f"Logged attempt from {IP},") write_file=True #suspicious_ips.append(Sus_Conn(IP,int(1))) #print("Logged") else: write_file=True print(str(IP in suspicious_ips) + "\nIP not yet added, adding.") #print(Sus_Conn(IP,int(1))) suspicious_ips[IP] = int(1) print("Logged. Current dictionary: " + ', '.join(str(y) for y in suspicious_ips.keys())) print(suspicious_ips) logging.debug(f"IP {IP}, added to suspicious list." + ', '.join(str(y) for y in suspicious_ips.keys())) if write_file: with open(suspicious_ips_json, 'w') as outfile: json_data = json.dump(suspicious_ips, outfile) #print(suspicious_ips) def main_run(date): global blacklisted, suspicious_ips with open(blacklist_json,'r') as infile: blacklisted = json.load(infile) print(blacklisted.keys()) logging.info("Blacklist file loaded.") with open(suspicious_ips_json,'r') as infile: suspicious_ips = json.load(infile) print(suspicious_ips.keys()) logging.info("Suspicious list file loaded.") start_date = datetime.today().strftime('%Y%m%d') print(start_date) if __name__ == "__main__": main_run(start_date)```
To alter a global variable, it must first exist