diff --git a/.gitignore b/.gitignore index 3af3c9c..d6d44c9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# Shammer stuff +config.json + # ---> Python # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/main.py b/main.py index 1cbc74b..5906d81 100644 --- a/main.py +++ b/main.py @@ -4,15 +4,39 @@ import re import logging as log import time import random +import json # Init logging log.basicConfig(level=log.INFO, format="%(asctime)-15s %(levelname)-8s %(message)s") log.info("Shammer is getting ready...") +# Init config +try: + log.info("Loading 'config.json'...") + f = open("config.json", "r") + config = json.load(f) + f.close() +except IOError as e: + # Doesn't exist yet + log.warn("Couldn't open 'config.json'") + log.warn("%s"%e) + log.info("Creating default configuration file...") + config = {"INDEX_URL":"https://bitscuit.be/", "MAX_CONTENT_LENGTH":500000, "REQUESTS_PER_MINUTE":10} + f = open("config.json", "w") + json.dump(config, f, indent="\t") + f.close() + log.info("Done. Please edit 'config.json' before running Shammer again!") + exit() +except Exception as e: + # Other error + log.warn("Couldn't open 'config.json'") + log.warn("%s"%e) + exit() + # Init static vars -INDEX_URL = "https://bitscuit.be/" -MAX_CONTENT_LENGTH = 500000 -REQUESTS_PER_MINUTE = 10 +INDEX_URL = config["INDEX_URL"] +MAX_CONTENT_LENGTH = config["MAX_CONTENT_LENGTH"] +REQUESTS_PER_MINUTE = config["REQUESTS_PER_MINUTE"] # Create session session = requests.Session()