Moved static vars to configuration file and added code to create default config

This commit is contained in:
bitscuit 2021-05-09 07:51:34 +02:00
parent 477814c480
commit 8ed9889267
2 changed files with 30 additions and 3 deletions

3
.gitignore vendored
View File

@ -1,3 +1,6 @@
# Shammer stuff
config.json
# ---> Python
# Byte-compiled / optimized / DLL files
__pycache__/

30
main.py
View File

@ -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()