Better makeFiles()

This commit is contained in:
Nikolaj Danger
2020-08-05 11:50:29 +02:00
parent b241dc13a8
commit e799eb792e
3 changed files with 117 additions and 193 deletions

View File

@ -13,6 +13,7 @@ logging.basicConfig(filename="gwendolyn.log", level=logging.INFO)
# Capitalizes all words except some of them # Capitalizes all words except some of them
no_caps_list = ["of","the"] no_caps_list = ["of","the"]
def cap(s): def cap(s):
# Capitalizes a strink like a movie title
word_number = 0 word_number = 0
lst = s.split() lst = s.split()
res = '' res = ''
@ -25,7 +26,7 @@ def cap(s):
return res return res
def time_in_range(start, end, x): def time_in_range(start, end, x):
"""Return true if x is in the range [start, end]""" # Return true if x is in the range [start, end]
if start <= end: if start <= end:
return start <= x <= end return start <= x <= end
else: else:
@ -134,146 +135,45 @@ def findWikiPage(search : str):
logThis("Couldn't find the page (error code 1002)") logThis("Couldn't find the page (error code 1002)")
return "", "Couldn't find page (error code 1002)", "" return "", "Couldn't find page (error code 1002)", ""
def makeJsonFile(path,content):
# Creates json file if it doesn't exist
try:
f = open(path,"r")
except:
logThis(path.split("/")[-1]+" didn't exist. Making it now.")
with open(path,"w") as f:
json.dump(content,f,indent = 4)
finally:
f.close()
def makeTxtFile(path,content):
# Creates txt file if it doesn't exist
try:
f = open(path,"r")
except:
logThis(path.split("/")[-1]+" didn't exist. Making it now.")
with open(path,"w") as f:
f.write(content)
finally:
f.close()
def makeFolder(path):
if os.path.isdir(path) == False:
os.makedirs(path)
logThis("The "+path.split("/")[-1]+" directory didn't exist")
def makeFiles(): def makeFiles():
# Creates swcharacters.json if it doesn't exist with open("resources/startingFiles.json") as f:
try: data = json.load(f)
f = open("resources/starWars/swcharacters.json","r")
except:
logThis("swcharacters.json didn't exist. Making it now.")
emptyDict = {}
with open("resources/starWars/swcharacters.json","w") as f:
json.dump(emptyDict,f,indent = 4)
finally:
f.close()
# Creates games.json if it doesn't exist for path, content in data["json"].items():
try: makeJsonFile(path,content)
f = open("resources/games/games.json","r")
except:
logThis("games.json didn't exist. Making it now.")
data = {"trivia questions":{},"blackjack games":{},"4 in a row games": {},"users":{}}
with open("resources/games/games.json","w") as f:
json.dump(data,f,indent = 4)
finally:
f.close()
# Creates hexGames.json if it doesn't exist for path, content in data["txt"].items():
try: makeTxtFile(path,content)
f = open("resources/games/hexGames.json","r")
except:
logThis("hexGames.json didn't exist. Making it now.")
data = {}
with open("resources/games/hexGames.json","w") as f:
json.dump(data,f,indent = 4)
finally:
f.close()
# Creates monsters.json if it doesn't exist for path in data["folder"]:
try: makeFolder(path)
f = open("resources/lookup/monsters.json","r")
except:
logThis("monsters.json didn't exist. Making it now.")
with open("resources/lookup/lookupExamples.json") as f:
data = json.load(f)["monster"]
with open("resources/lookup/monsters.json","w") as f:
json.dump(data,f,indent = 4)
finally:
f.close()
# Creates spells.json if it doesn't exist
try:
f = open("resources/lookup/spells.json","r")
except:
logThis("spells.json didn't exist. Making it now.")
with open("resources/lookup/lookupExamples.json") as f:
data = json.load(f)["spell"]
with open("resources/lookup/spells.json","w") as f:
json.dump(data,f,indent = 4)
finally:
f.close()
# Creates users.json if it doesn't exist
try:
f = open("resources/users.json","r")
except:
logThis("users.json didn't exist. Making it now.")
data = {}
with open("resources/users.json","w") as f:
json.dump(data,f,indent = 4)
finally:
f.close()
# Creates destinyPoints.txt if it doesn't exist
try:
f = open("resources/starWars/destinyPoints.txt","r")
except:
logThis("destinyPoints.txt didn't exist. Making it now.")
with open("resources/starWars/destinyPoints.txt","w") as f:
f.write("")
finally:
f.close()
# Creates movies.txt if it doesn't exist
try:
f = open("resources/movies.txt","r")
except:
logThis("movies.txt didn't exist. Making it now.")
with open("resources/movies.txt","w") as f:
f.write("The Room")
finally:
f.close()
# Creates names.txt if it doesn't exist
try:
f = open("resources/names.txt","r")
except:
logThis("names.txt didn't exist. Making it now.")
with open("resources/names.txt","w") as f:
f.write("Gandalf")
finally:
f.close()
# Creates token.txt if it doesn't exist
try:
f = open("token.txt","r")
except:
logThis("token.txt didn't exist. Write your bot token below, or in token.txt later.")
token = input()
with open("token.txt","w") as f:
f.write(token)
finally:
f.close()
# Creates the blackjacktables foulder if it doesn't exist
if os.path.isdir("resources/games/blackjackTables") == False:
os.makedirs("resources/games/blackjackTables")
logThis("The tables directory didn't exist")
# Creates the 4InARowBoards foulder if it doesn't exist
if os.path.isdir("resources/games/4InARowBoards") == False:
os.makedirs("resources/games/4InARowBoards")
logThis("The 4 in a row boards directory didn't exist")
# Creates the hexBoards foulder if it doesn't exist
if os.path.isdir("resources/games/hexBoards") == False:
os.makedirs("resources/games/hexBoards")
logThis("The Hex boards directory didn't exist")
# Creates the oldImages foulder if it doesn't exist
if os.path.isdir("resources/games/oldImages") == False:
os.makedirs("resources/games/oldImages")
logThis("The old images directory didn't exist")
# Creates the blackjackCards foulder if it doesn't exist
if os.path.isdir("resources/games/blackjackCards") == False:
os.makedirs("resources/games/blackjackCards")
logThis("The blackjack cards directory didn't exist")
# Creates the hilo foulder if it doesn't exist
if os.path.isdir("resources/games/hilo") == False:
os.makedirs("resources/games/hilo")
logThis("The hi-lo directory didn't exist")
# Replaces multiple things with the same thing # Replaces multiple things with the same thing
def replaceMultiple(mainString, toBeReplaces, newString): def replaceMultiple(mainString, toBeReplaces, newString):

View File

@ -1,56 +0,0 @@
{
"monster" : [
{
"name": "Bandit",
"size": "Medium",
"type": "humanoid",
"subtype": "any race",
"alignment": "any non-lawful alignment",
"armor_class": 12,
"hit_points": 11,
"hit_dice": "2d8",
"speed": "30 ft.",
"strength": 11,
"dexterity": 12,
"constitution": 12,
"intelligence": 10,
"wisdom": 10,
"charisma": 10,
"damage_vulnerabilities": "",
"damage_resistances": "",
"damage_immunities": "",
"condition_immunities": "",
"senses": "passive Perception 10",
"languages": "any one language (usually Common)",
"challenge_rating": "1/8",
"actions": [
{
"name": "Scimitar",
"desc": "Melee Weapon Attack: +3 to hit, reach 5 ft., one target. Hit: 4 (1d6 + 1) slashing damage.",
"attack_bonus": 3,
"damage_dice": "1d6",
"damage_bonus": 1
},
{
"name": "Light Crossbow",
"desc": "Ranged Weapon Attack: +3 to hit, range 80 ft./320 ft., one target. Hit: 5 (1d8 + 1) piercing damage.",
"attack_bonus": 3,
"damage_dice": "1d8",
"damage_bonus": 1
}
]
}
],
"spell": {
"Fireball" : {
"casting_time" : "1 action",
"components" : "V, S, M (a tiny ball of bat guano and sulfur)",
"description" : "A bright streak flashes from your pointing finger to a point you choose within range and then blossoms with a low roar into an explosion of flame. Each creature in a 20-foot-radius sphere centered on that point must make a Dexterity saving throw. A target takes 8d6 fire damage on a failed save, or half as much damage on a successful one. The fire spreads around corners. It ignites flammable objects in the area that arent being worn or carried. At Higher Levels. When you cast this spell using a spell slot of 4th level or higher, the damage increases by 1d6 for each slot level above 3rd.",
"duration" : "Instantaneous",
"level" : "3rd",
"range" : "150 feet",
"school" : "Evocation",
"ritual" : false
}
}
}

View File

@ -0,0 +1,80 @@
{
"json":{
"resources/starWars/swcharacters.json" : {},
"resources/games/hexGames.json": {},
"resources/users.json" : {},
"resources/games/games.json" : {
"trivia questions":{},
"blackjack games":{},
"4 in a row games": {}
},
"resources/lookup/spells.json" : {
"Fireball" : {
"casting_time" : "1 action",
"components" : "V, S, M (a tiny ball of bat guano and sulfur)",
"description" : "A bright streak flashes from your pointing finger to a point you choose within range and then blossoms with a low roar into an explosion of flame. Each creature in a 20-foot-radius sphere centered on that point must make a Dexterity saving throw. A target takes 8d6 fire damage on a failed save, or half as much damage on a successful one. The fire spreads around corners. It ignites flammable objects in the area that arent being worn or carried. At Higher Levels. When you cast this spell using a spell slot of 4th level or higher, the damage increases by 1d6 for each slot level above 3rd.",
"duration" : "Instantaneous",
"level" : "3rd",
"range" : "150 feet",
"school" : "Evocation",
"ritual" : false
}
},
"resources/lookup/monsters.json" : [
{
"name": "Bandit",
"size": "Medium",
"type": "humanoid",
"subtype": "any race",
"alignment": "any non-lawful alignment",
"armor_class": 12,
"hit_points": 11,
"hit_dice": "2d8",
"speed": "30 ft.",
"strength": 11,
"dexterity": 12,
"constitution": 12,
"intelligence": 10,
"wisdom": 10,
"charisma": 10,
"damage_vulnerabilities": "",
"damage_resistances": "",
"damage_immunities": "",
"condition_immunities": "",
"senses": "passive Perception 10",
"languages": "any one language (usually Common)",
"challenge_rating": "1/8",
"actions": [
{
"name": "Scimitar",
"desc": "Melee Weapon Attack: +3 to hit, reach 5 ft., one target. Hit: 4 (1d6 + 1) slashing damage.",
"attack_bonus": 3,
"damage_dice": "1d6",
"damage_bonus": 1
},
{
"name": "Light Crossbow",
"desc": "Ranged Weapon Attack: +3 to hit, range 80 ft./320 ft., one target. Hit: 5 (1d8 + 1) piercing damage.",
"attack_bonus": 3,
"damage_dice": "1d8",
"damage_bonus": 1
}
]
}
]
},
"txt": {
"resources/starWars/destinyPoints.txt": "",
"resources/movies.txt": "The Room",
"resources/names.txt": "Gandalf",
"token.txt" : "Write token here"
},
"folder" : [
"resources/games/blackjackTables",
"resources/games/4InARowBoards",
"resources/games/hexBoards",
"resources/games/oldImages",
"resources/games/blackjackCards",
"resources/games/hilo"
]
}