def delete_meet(meetid): # delete meet folder in publish dirpath = os.path.join('swimanager/meet_data/publish', meetid) if os.path.exists(dirpath) and os.path.isdir(dirpath): shutil.rmtree(dirpath, ignore_errors=True) # remove entries folder dirpath = os.path.join('swimanager/meet_data/entries', meetid) if os.path.exists(dirpath) and os.path.isdir(dirpath): shutil.rmtree(dirpath, ignore_errors=True) # remove results folder dirpath = os.path.join('swimanager/meet_data/results', meetid) if os.path.exists(dirpath) and os.path.isdir(dirpath): shutil.rmtree(dirpath, ignore_errors=True) # remove drive sheets data = readfile(meetid) sheet_deleter(data['entryid'], data['eventid']) try: os.remove('swimanager/meet_data/' + meetid + '.json') except: print("Not able to delete the file %s" % filename) # delete meet from file meets_data = readfile('meets') del meets_data['meets'][meetid] filewriter('swimanager/meet_data/meets.json', meets_data)
def meet_publish(meetid): data = readfile('meets') meet = readfile(meetid) status = data['meets'][meetid]['meet'] meet['pub_settings']['meet'] = data['meets'][meetid]['meet'] = not status filewriter('swimanager/meet_data/meets.json', data) filewriter('swimanager/meet_data/' + meetid + '.json', meet) return data['meets'][meetid]['meet']
def statusUpdate(status, meetid): meet = readfile(meetid) # meet = data['meets'][meetid] meet[status] = True sheetname = str(meet['meetid']) + ' ' + meet['meettype'] + ' - Events' meet['eventsheet'] = sheetname files = glob.glob('swimanager/meet_data/entries/' + str(meetid) + '/*.json') # create sheet here scope = [ 'https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive' ] credentials = ServiceAccountCredentials.from_json_keyfile_name( 'swimanager/swimanager.json', scope) gc = gspread.authorize(credentials) if len(meet['eventid']) > 1: gc.del_spreadsheet(meet['eventid']) sh = gc.create(sheetname) sh.share('*****@*****.**', perm_type='user', role='writer') sh = gc.open(sheetname) meet['eventid'] = sh.id # filename = file_name + '.json' filewriter('swimanager/meet_data/' + meetid + '.json', meet) for i in files: gender = i.split('_') gender = gender[-1] gender = gender.split('.') gender = gender[0] with open(i) as json_file: data = json.load(json_file) time.sleep(3) header = [['Name', 'Reg No', 'Team', 'Time']] for p in data: # if data[p] == True: event_data = header + data[p] sh.add_worksheet(title=p + '-' + gender, rows="100", cols="20") sh.values_update(p + '-' + gender + '!A1', params={'valueInputOption': 'RAW'}, body={'values': event_data}) worksheet = sh.worksheet('Sheet1') sh.del_worksheet(worksheet)
def event_pub(meetid): src_files = os.listdir('swimanager/meet_data/entries/' + str(meetid)) for file_name in src_files: full_file_name = os.path.join( 'swimanager/meet_data/entries/' + str(meetid), file_name) if os.path.isfile(full_file_name): shutil.copy( full_file_name, 'swimanager/meet_data/publish/' + str(meetid) + '/events') data = readfile(meetid) status = data['pub_settings']['events'] data['pub_settings']['events'] = not status filewriter('swimanager/meet_data/' + meetid + '.json', data) return data['pub_settings']['events']
def event_organizer(data, gender, meetid): event_data = {} tmp = data[0] tmp = tmp["Events"] events = tmp[2:] for k in events: event_data[k] = [] for teamData in data: for i in teamData["Entries"]: entry = i[0:2] team = teamData["Name"] entry.append(team) checklist = i[2:] for ind, val in enumerate(checklist): if val != '': event_data[events[ind]].append(entry) filewriter( 'swimanager/meet_data/entries/' + str(meetid) + '/' + str(meetid) + '_' + gender + '.json', event_data)
def result_publisher(meetid, event, gender): if gender == '-men': gen = 'boys' else: gen = 'girls' data = readfile(meetid) if event not in data['pub_settings']['results'][gen]: data['pub_settings']['results'][gen].insert(0, event) status = 'Published!' else: data['pub_settings']['results'][gen].remove(event) status = 'Unpublished' shutil.copy( 'swimanager/meet_data/results/' + meetid + '/' + event + gender + '.csv', 'swimanager/meet_data/publish/' + meetid + '/results/' + event + gender + '.csv') filewriter('swimanager/meet_data/' + meetid + '.json', data) return status