Skip to content
This repository has been archived by the owner on Sep 24, 2019. It is now read-only.

Commit

Permalink
Merge pull request #56 from BenHargreaves/featureGenerateEmptyJson
Browse files Browse the repository at this point in the history
utils.py generates required Json files when called
  • Loading branch information
zachkont authored Oct 30, 2018
2 parents 04705f2 + 643137d commit 7849f99
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import json
import re
import datetime
import os.path
from sortedcontainers import SortedDict
from datetime import datetime
from settings import BOT_TOKEN
Expand All @@ -16,6 +17,29 @@

uptime = datetime.now()

# check for presence of required json files
generateEmptyJson()

def generateEmptyJson():
jsonFiles = [
"previousblogposts",
"previouscyborgmatt",
"previousjasons",
"previousmagesunite",
"previoussirbelvedere",
"previouswykrhm",
"userlist",
"grouplist"
]

for file in jsonFiles:
filename = file + ".json"
# prevent overwriting of file if it already exists
if not os.path.isfile(filename):
f = open(filename, "w+")
f.writelines("{\n\n}")
f.close()

def getCID(message):
return message.chat.id

Expand Down Expand Up @@ -43,6 +67,8 @@ def addUser(userID, userName, filename):
json.dump(data, f)

def loadjson(filename):
# make sure Json files are properly created before loading.
generateEmptyJson()
with open(filename + '.json') as f:
data = json.load(f)
if filename == "suggestion" or filename == 'todo':
Expand Down

0 comments on commit 7849f99

Please sign in to comment.