Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
##################################################
# Benjamin Grant
import json
import pickle
#Opens names.json, updates it with the new name
async def set_name(id, name):
with open("names.json") as f:
names = json.load(f)
names[str(id)] = name
with open("names.json", "w+") as f:
json.dump(names, f)
#Opens names.json, checks if the user has a name and returns None if not. IMPORTANT TO CHECK FOR NONE, DO NOT ASSUME NAME EXISTS
async def get_name(id):
with open("names.json") as f:
names = json.load(f)
if str(id) in names:
return names[str(id)].capitalize()
else:
return None
#Same functionality as get_name() but it uses the pickle module
async def get_name_pickle(id):
f = open("names.pck", "rb")
names = pickle.load(f)
f.close()
if str(id) in names:
return names[str(id)].capitalize()
else:
return None
#Same functionality as set_name() but it uses the pickle module
async def set_name_pickle(id, name):
f = open("names.pck", "rb")
names = pickle.load(f)
f.close()
names[str(id)] = name
f = open("names.pck", "wb")
pickle.dump(names, f)
f.close()
##################################################