133 lines
4.4 KiB
Python
133 lines
4.4 KiB
Python
#! python3
|
|
#get_group_list.py
|
|
#A tool to process Compass Records and produce a list of Groups by County
|
|
#Licence: GPL-3.0-or-later
|
|
#Written by Stuart Griffiths, stuart.griffiths@birminghamscouts.org.uk
|
|
#Started 25/09/2022
|
|
#Version:0.1
|
|
#Released: 25/09/2022
|
|
#Status: Working
|
|
#Inputs: CSV
|
|
#Outputs: text file
|
|
#Next Steps:
|
|
#Issues:
|
|
#Background IP: https://automatetheboringstuff.com/, Chapter 16
|
|
|
|
#Notes - CSV Column Numbers
|
|
#District = 25
|
|
#Scout_Group = 27
|
|
|
|
|
|
#Libraries
|
|
import os #Enables file IO
|
|
from pathlib import Path #to work out current working directory
|
|
import csv #required to handle csv files
|
|
|
|
|
|
#1. Set up Output files
|
|
#text files
|
|
group_file = open('_group_list.txt', 'w')
|
|
|
|
#Modules
|
|
def group_collecting():
|
|
#2. Open the file
|
|
file_name = str(Path.cwd()) + '/' + str('County Member Directory (Updated).csv')
|
|
input_file = open(file_name) #assumes file is in working directory
|
|
#Create a list using the CSV file
|
|
input_data_reader = csv.reader(input_file)
|
|
input_data = list(input_data_reader)
|
|
#Set up lists
|
|
group_list = [] #used to catch all groups
|
|
CVS_list = []
|
|
rea_list = []
|
|
spitfire_list = []
|
|
SCE_list = []
|
|
SCW_list = []
|
|
tame_list = []
|
|
|
|
#3. Process the data
|
|
#Start at row 4 for the OSM output
|
|
line_num = int(2) #strips header out
|
|
while line_num < (len(input_data)-1): #while there is an entry to handle, do this
|
|
#3.1. Test 1 - Should the role have a Woodbadge?
|
|
#Read the column
|
|
group_name = input_data[line_num][27]
|
|
#Check - Is it in the list?
|
|
if group_name in group_list:
|
|
#check if already caught and dealt with
|
|
print("caught that one already")
|
|
else:
|
|
group_list.append(group_name)
|
|
district_name = input_data[line_num][25]
|
|
if district_name == 'Cole Valley South':
|
|
CVS_list.append(group_name)
|
|
if district_name == 'Rea Valley':
|
|
rea_list.append(group_name)
|
|
if district_name == 'Birmingham Spitfire District Scout Association':
|
|
spitfire_list.append(group_name)
|
|
if district_name == 'Sutton Coldfield East':
|
|
SCE_list.append(group_name)
|
|
if district_name == 'Sutton Coldfield West':
|
|
SCW_list.append(group_name)
|
|
if district_name == 'Tame Valley Birmingham':
|
|
tame_list.append(group_name)
|
|
line_num = line_num + 1 #continues the loop
|
|
|
|
print("group list = " + str(len(group_list)))
|
|
print("CVS list = " + str(len(CVS_list)))
|
|
print("rea list = " + str(len(rea_list)))
|
|
print("spitfire list = " + str(len(spitfire_list)))
|
|
print("SCE list = " + str(len(SCE_list)))
|
|
print("SCW list = " + str(len(SCW_list)))
|
|
print("tame list = " + str(len(tame_list)))
|
|
|
|
#3.3 Produce the output file
|
|
group_file.write('Group List For Birmingham County\n')
|
|
group_file.write('================================\n')
|
|
group_file.write('\n')
|
|
group_file.write('Cole Valley South Roles\n')
|
|
group_file.write('=======================\n')
|
|
for x in range(len(CVS_list)):
|
|
group_file.write(CVS_list[x])
|
|
group_file.write('\n')
|
|
group_file.write('\n')
|
|
group_file.write('Rea Valley Roles\n')
|
|
group_file.write('================\n')
|
|
for x in range(len(rea_list)):
|
|
group_file.write(rea_list[x])
|
|
group_file.write('\n')
|
|
group_file.write('\n')
|
|
group_file.write('Spitfire Roles\n')
|
|
group_file.write('==============\n')
|
|
for x in range(len(spitfire_list)):
|
|
group_file.write(spitfire_list[x])
|
|
group_file.write('\n')
|
|
group_file.write('\n')
|
|
group_file.write('Sutton Coldfield East Roles\n')
|
|
group_file.write('===========================\n')
|
|
for x in range(len(SCE_list)):
|
|
group_file.write(SCE_list[x])
|
|
group_file.write('\n')
|
|
group_file.write('\n')
|
|
group_file.write('Sutton Coldfield West Roles\n')
|
|
group_file.write('===========================\n')
|
|
for x in range(len(SCW_list)):
|
|
group_file.write(SCW_list[x])
|
|
group_file.write('\n')
|
|
group_file.write('\n')
|
|
group_file.write('Tame Valley Roles\n')
|
|
group_file.write('===========================\n')
|
|
for x in range(len(tame_list)):
|
|
group_file.write(tame_list[x])
|
|
group_file.write('\n')
|
|
group_file.write('\n')
|
|
|
|
#4: Close files to show they are done
|
|
|
|
group_file.close()
|
|
print("Finished collecting groups!")
|
|
|
|
#Program
|
|
group_collecting()
|
|
|