Skip to content

Commit

Permalink
Start processing "unit pin" data and store it to use later.
Browse files Browse the repository at this point in the history
Step one in Be able to pull unit information from the unit pin report #6
  • Loading branch information
billnapier committed Sep 5, 2023
1 parent 849faf9 commit 208871a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
data
.venv
__pycache__
36 changes: 34 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def UnitNameToNumber(name):
return str(int(num))


@app.route("/upload", methods=['POST'])
def upload():
@app.route("/upload_key3", methods=['POST'])
def upload_key3():
logging.warning("%s" % request.files)
if 'file' not in request.files:
return 'No file part'
Expand Down Expand Up @@ -77,6 +77,38 @@ def upload():
return redirect('/')


@app.route("/upload_pin", methods=['POST'])
def upload_pin():
logging.warning("%s" % request.files)
if 'file' not in request.files:
return 'No file part'
fp = request.files['file'].stream

with io.StringIO(fp.read().decode()) as f:
for row in csv.DictReader(f):
full_unit_name = row['Unit_Name']
unit_name = full_unit_name.split(', ')[0]

unit_type = UnitNameToUnitLetter(unit_name)
unit_num = UnitNameToNumber(unit_name)

key = '%s %s' % (unit_type, unit_num)

addrline = row['Unit_BeAScout_Address']
city = row['City']
state = row['State']
zipcode = row['ZIPCODE']
last_modified_date = row['Last_Modified_Date']

unit_entry = dict(key=key, unit_type=UnitNameToUnitType(row['Unit_Name']),
unit_num=unit_num, pin_info=dict(address_line=addrline, city=city, state=state, zipcode=zipcode, last_modified_date=last_modified_date), website=row['Unit_Website'])

db.collection('units').document(key).set(unit_entry, merge=True)

logging.error(unit_name)
return redirect('/')


def get_contacts_from_unit(unit):
return [contact for contact in [unit.get('leader'), unit.get('cor'), unit.get('cc')] if contact is not None]

Expand Down
12 changes: 9 additions & 3 deletions templates/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@
<li><a href="{{url_for('send_email', unit_type='PACK')}}">Email Packs</a>
<li><a href="{{url_for('send_email', unit_type='TROOP')}}">Email Troops</a>
</ul>
<H1>Upload New Unit CSV</H1>
<form enctype="multipart/form-data" action="upload" method="POST">
<H1>Upload Key 3 CSV</H1>
<form enctype="multipart/form-data" action="{{url_for('upload_key3')}}" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="file" type="file" /><br />
Choose a file to upload: <input name="file" type="file" />
<input type="submit" value="Upload File" />
</form>
<H1>Upload Unit Pin CSV</H1>
<form enctype="multipart/form-data" action="{{url_for('upload_pin')}}" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="file" type="file" />
<input type="submit" value="Upload File" />
</form>
</BODY>

</HTML>

0 comments on commit 208871a

Please sign in to comment.