hrt.git
hrt.py
#!/bin/python3
# hrt - survey website
# Copyright (C) 2024 ArcNyxx <me@arcnyxx.net>
# see LICENCE file for licensing information
from flask import Flask, request, send_file
app = Flask(__name__)
@app.get('/')
def index():
return send_file('hrt.html')
@app.get('/form')
def form():
return send_file('form.html')
@app.get('/<url>')
def files(url):
if url not in ['style.css', 'script.js', 'logo.webp']:
return send_file('404.html'), 404
return send_file(url)
@app.post('/form')
def entry():
# return request.form.to_dict(flat=False)
demographics = {};
demographics['date-of-birth'] = request.form['dob']
demographics['country-of-residence'] = request.form['country']
demographics['gender'] = request.form.getlist('gender')
demographics['ethnicity'] = request.form.getlist('ethnicity')
if request.form.get('hrt') not in [ 'Masculinizing', 'Feminizing' ]:
return 'Error: Type of HRT Unspecified.'
hrt = {}
hrt['type'] = request.form['hrt']
hrt['medication'] = []
j = 0
for i in range(len(request.form.getlist('hrt-med'))):
med = {}
med['method'] = request.form.getlist('hrt-method')[i]
med['medication'] = request.form.getlist('hrt-med')[i]
med['amount'] = request.form.getlist('hrt-amount')[i]
med['frequency'] = request.form.getlist('hrt-freq')[i]
med['start-date'] = request.form.getlist('hrt-start')[i]
med['is-ongoing'] = request.form.getlist('hrt-ong')[i] == 'on'
if (request.form.getlist('hrt-ong')[i] == 'off'):
med['end-date'] = request.form.getlist('hrt-end')[j]
med['reason-for-termination'] = request.form.getlist('hrt-reason')[j]
j += 1
hrt['medication'].append(med)
if request.form['hrt'] == 'Masculinizing':
hrt['general'] = request.form.getlist('me')
elif request.form['hrt'] == 'Feminizing':
hrt['general'] = request.form.getlist('fe')
hrt['general-expand'] = request.form['et']
if request.form['hrt'] == 'Feminizing':
hrt['cyclical'] = request.form.getlist('fc')
hrt['cyclical-expand'] = request.form['ct']
else:
hrt['cyclical'] = None
hrt['cyclical-expand'] = None
if request.form.get('sex') == 'on':
if request.form['hrt'] == 'Masculinizing':
hrt['sexual'] = request.form.getlist('ms')
elif request.form['hrt'] == 'Feminizing':
hrt['sexual'] = request.form.getlist('fs')
hrt['sexual-expand'] = request.form['st']
else:
hrt['sexual'] = None
health = {}
health['medication'] = request.form['info-other-meds']
health['conditions'] = request.form['info-other-cond']
health['extra-hrt-info'] = request.form['info-extra']
health['blood-test'] = request.form.get('info-blood') == 'on'
feedback = {}
feedback['heard-from'] = request.form['info-hear']
feedback['add-to-survey'] = request.form['info-add']
feedback['feedback'] = request.form['info-feedback']
form = {}
form['demographics'] = demographics
form['hrt'] = hrt
form['health'] = health
form['feedback'] = feedback
return form