Esempio n. 1
0
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)
Esempio n. 2
0
def admin():
    data = readfile('meets')
    pools = readfile('pools')
    for meetid, meet in data['meets'].items():
        location = meet['location']
        image_url = pools[location]['image']
        meet['image'] = image_url
        meet['location'] = pools[location]['name']

    return render_template('admin.html', title='Admin', meets=data['meets'])
Esempio n. 3
0
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']
Esempio n. 4
0
def view_meet():
    meetid = request.args.get('meet')
    pub, entries, results = view_res(meetid)

    meet = readfile(meetid)
    pools = readfile('pools')

    # get the meetid and find the relevant meet from the json file
    # meet = fulldata['meets'][meetid]
    meet['location'] = pools[meet['location']]['name']

    return render_template('view_meet.html',
                           entries=entries,
                           results=results,
                           meet=meet)
Esempio n. 5
0
def meet():
    meetid = request.args.get('meet')
    meet = readfile(meetid)
    print(meet)

    # get the meetid and find the relevant meet from the json file

    # meet = fulldata['meets'][meetid]

    # check if entry folder is present and send a message
    data, men_ents, wmen_ents = meetfolder(meetid)
    flash(f'' + data['message'], data['category'])

    ev_list = eventLister(data['file'], meet['meettype'])
    results = saved_results(meetid, ev_list)
    # get published results
    # pub_res_data = readfile('publish')
    # pub_res = pub_res_data[meetid]

    return render_template('meet.html',
                           title='meet ' + str(meetid),
                           meet=meet,
                           men_ents=men_ents,
                           wmen_ents=wmen_ents,
                           file_status=data['file'],
                           ev_list=ev_list,
                           results=results)
Esempio n. 6
0
def process():
    data = request.get_json()
    meetid = data['meetid']

    meet = readfile(meetid)
    # meet = fulldata['meets'][meetid]
    sheet = meet['eventid']

    results = resultPull(meetid, sheet, data['event'], data['gender'])
    return jsonify(results)
Esempio n. 7
0
def entries():
    meetid = request.args.get('meet')

    meet = readfile(meetid)
    # meet = fulldata['meets'][meetid]

    men, wmen = drivesync(meetid, meet['sheetname'])
    event_organizer(men, 'men', meetid)
    event_organizer(wmen, 'women', meetid)

    return redirect(url_for('meet', meet=meetid))
Esempio n. 8
0
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)
Esempio n. 9
0
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']
Esempio n. 10
0
def view_res(meetid):
    pub_res = readfile(meetid)
    meet = pub_res['pub_settings']

    # get the published entries
    if meet['events']:
        with open('swimanager/meet_data/publish/' + str(meetid) + '/events/' +
                  str(meetid) + '_men.json') as json_file:
            men = json.load(json_file)
        with open('swimanager/meet_data/publish/' + str(meetid) + '/events/' +
                  str(meetid) + '_women.json') as json_file:
            women = json.load(json_file)

        entries = [men, women]
    else:
        entries = []

    # get the published results
    data = {'men': {}, 'women': {}}
    genders = ['men', 'women']

    for g in genders:
        if g == 'men':
            files = meet['results']['boys']
        else:
            files = meet['results']['girls']

        for i in files:
            filename = i + '-' + g + '.csv'
            # print(filename)
            with open('swimanager/meet_data/publish/' + meetid + '/results/' +
                      filename) as csvfile:
                readCSV = csv.reader(csvfile, delimiter=',')
                result_data = []
                next(readCSV)
                for row in readCSV:
                    result_data.append(row)
            data[g][i] = result_data
    return (meet, entries, data)
Esempio n. 11
0
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
Esempio n. 12
0
def home():
    # pub_meets = readfile('publish')
    meets = readfile('meets')

    return render_template('home.html', meets=meets['meets'])
Esempio n. 13
0
def createfile(name, startdate, location, boysteams, girlsteams):
	meta_data = readfile('meets')
	now = datetime.datetime.now()
	now = str(now)
	date=now.split('-')
	meetname = name
	meetdate = date[0]

	count = meta_data['count']
	count += 1
	meta_data['count'] = count

	sheetname = str(count)+' Entries '+meetname+' '+meetdate

	data = {}
	meta_new = {}
	meta_new['meetid'] = data['meetid'] = count
	meta_new['meetype'] = data['meettype'] = name
	data['time_created'] = now
	meta_new['startdate'] = data['startdate'] = str(startdate)
	meta_new['location'] = data['location'] = location
	data['boys'] = boysteams
	data['girls'] = girlsteams
	data['sheetname'] = sheetname
	data['eventstat'] = False
	data['eventid'] = ''

	if name == 'IF':
		meta_new['meettitle'] = data['meettitle'] = 'Inter Faculty Swimming Championship - ' + meetdate
		meta_new['shortname'] = data['shortname'] = 'Inter-Fac' + meetdate
		meta_new['image'] = data['image'] = 'images/IF.jpg'
	else:
		meta_new['meettitle'] = data['meettitle'] = 'Inter Faculty Freshers\' Swimming Championship - ' + meetdate
		meta_new['shortname'] = data['shortname'] = 'Inter-Fac Freshers\'' + meetdate
		meta_new['image'] = data['image'] = 'images/IFF.jpeg'


	meta_new['meet'] = False
	meta_data['meets'][count] = meta_new

	# publish details update
	# pub_data = readfile('publish')
	data['pub_settings'] = {
		'events': False,
		'meet': False,
		'results': {
			'boys': [],
			'girls': []
		}
	}

	# pub_data[count] = pub_settings

	# with open('swimanager/meet_data/publish.json','w') as outfile:
	# 	json.dump(pub_data, outfile,indent=4)

	# create the meet folders needed
	if not os.path.exists("swimanager/meet_data/entries/"+str(count)):
			os.makedirs("swimanager/meet_data/entries/"+str(count))

	if not os.path.exists("swimanager/meet_data/publish/"+str(count)):
			os.makedirs("swimanager/meet_data/publish/"+str(count))

	if not os.path.exists("swimanager/meet_data/publish/"+str(count)+"/events"):
			os.makedirs("swimanager/meet_data/publish/"+str(count)+"/events")

	if not os.path.exists("swimanager/meet_data/publish/"+str(count)+"/results"):
			os.makedirs("swimanager/meet_data/publish/"+str(count)+"/results")

	if not os.path.exists("swimanager/meet_data/results/"+str(count)):
			os.makedirs("swimanager/meet_data/results/"+str(count))

	file_creator(sheetname,meetname,boysteams,girlsteams,meta_data,data,count)