2020-03-06 23:37:21 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# encoding: utf-8
|
|
|
|
|
|
|
|
import npyscreen
|
|
|
|
import json
|
2020-03-10 16:11:51 +01:00
|
|
|
from datetime import date
|
2020-03-06 23:37:21 +01:00
|
|
|
from sys import argv
|
|
|
|
|
|
|
|
|
|
|
|
class FormApp(npyscreen.NPSAppManaged):
|
|
|
|
def __init__(self, member_struct):
|
|
|
|
super().__init__()
|
|
|
|
self.member = member_struct
|
|
|
|
|
|
|
|
def main(self):
|
|
|
|
f = npyscreen.Form(name='Edit Member data')
|
2020-03-14 10:43:38 +01:00
|
|
|
|
2020-03-06 23:37:21 +01:00
|
|
|
sd = self.member['stammdaten']
|
2020-03-14 10:43:38 +01:00
|
|
|
base_data_widgets = {}
|
|
|
|
base_data_widgets['fullname'] = f.add(
|
|
|
|
npyscreen.TitleText, name="Name: ", value=sd['fullname'])
|
|
|
|
base_data_widgets['nickname'] = f.add(npyscreen.TitleText, name="Nickname: ",
|
|
|
|
value=sd['nickname'])
|
|
|
|
base_data_widgets['address_street'] = f.add(
|
2020-03-10 16:00:18 +01:00
|
|
|
npyscreen.TitleText, name="Adresse - Straße: ", value=sd['address_street'])
|
2020-03-14 10:43:38 +01:00
|
|
|
base_data_widgets['address_locality'] = f.add(
|
2020-03-10 16:00:18 +01:00
|
|
|
npyscreen.TitleText, name="Adresse - Stadt: ", value=sd['address_locality'])
|
2020-03-14 10:43:38 +01:00
|
|
|
base_data_widgets['address_code'] = f.add(npyscreen.TitleText,
|
|
|
|
name="Adresse - PLZ: ", value=sd['address_code'])
|
|
|
|
base_data_widgets['address_country'] = f.add(
|
2020-03-10 16:00:18 +01:00
|
|
|
npyscreen.TitleText, name="Adresse - Land: ", value=sd['address_country'])
|
2020-03-14 10:43:38 +01:00
|
|
|
base_data_widgets['birth_date'] = f.add(npyscreen.TitleText,
|
|
|
|
name="Geburtstag: ", value=sd['birth_date'])
|
|
|
|
base_data_widgets['birth_location'] = f.add(
|
2020-03-10 16:00:18 +01:00
|
|
|
npyscreen.TitleText, name="Geburtsort: ", value=sd['birth_location'])
|
2020-03-14 10:43:38 +01:00
|
|
|
base_data_widgets['email'] = f.add(npyscreen.TitleText,
|
|
|
|
name="email: ", value=sd['email'])
|
|
|
|
base_data_widgets['pgp-key'] = f.add(npyscreen.TitleText,
|
|
|
|
name="URI PGP Key: ", value=sd['pgp-key'])
|
|
|
|
base_data_widgets['ssh-key'] = f.add(npyscreen.TitleText,
|
|
|
|
name="URI SSH Key: ", value=sd['ssh-key'])
|
|
|
|
self.base_data_widgets = base_data_widgets
|
2020-03-06 23:37:21 +01:00
|
|
|
|
|
|
|
fin = self.member['finanzdaten']
|
2020-03-14 10:43:38 +01:00
|
|
|
finance_widgets = {}
|
|
|
|
finance_widgets['iban'] = f.add(
|
|
|
|
npyscreen.TitleText, name="IBAN: ", value=fin['iban'])
|
|
|
|
finance_widgets['bic'] = f.add(
|
|
|
|
npyscreen.TitleText, name="BIC: ", value=fin['bic'])
|
|
|
|
finance_widgets['holder'] = f.add(
|
|
|
|
npyscreen.TitleText, name="Kontoinhaber: ", value=fin['holder'])
|
|
|
|
finance_widgets['issuance'] = f.add(npyscreen.TitleText, name="Tag der Erteilung Lastschriftmandat: ",
|
|
|
|
value=fin['issuance'])
|
|
|
|
finance_widgets['reference'] = f.add(npyscreen.TitleText, name="Mandatsreferenznummer: ",
|
|
|
|
value=fin['reference'])
|
|
|
|
finance_widgets['scan-sepa-mandate'] = f.add(npyscreen.TitleText, name="URI Scan SEPA-Mandat: ",
|
|
|
|
value=fin['scan-sepa-mandate'])
|
|
|
|
sefl.finance_widgets = finance_widgets
|
2020-03-06 23:37:21 +01:00
|
|
|
|
|
|
|
mem = self.member['mitgliederdaten']
|
2020-03-14 10:43:38 +01:00
|
|
|
member_widgets = {}
|
|
|
|
member_widgets['status'] = f.add(
|
|
|
|
npyscreen.TitleText, name="Status: ", value=mem['status'])
|
|
|
|
member_widgets['von'] = f.add(
|
|
|
|
npyscreen.TitleText, name="Von: ", value=mem['von'])
|
|
|
|
member_widgets['bis'] = f.add(
|
|
|
|
npyscreen.TitleText, name="Bis: ", value=mem['bis'])
|
|
|
|
member_widgets['mitgliedsbeitrag'] = f.add(npyscreen.TitleText, name="Mitgliedsbeitrag: ",
|
|
|
|
value=mem['mitgliedsbeitrag'])
|
|
|
|
member_widgets['schliessberechtigung'] = f.add(npyscreen.TitleText, name="Schliessberechtigung: ",
|
|
|
|
value=mem['schliessberechtigung'])
|
|
|
|
member_widgets['scan-antrag'] = f.add(npyscreen.TitleText, name="URI Scan Antrag: ",
|
|
|
|
value=mem['scan-antrag'])
|
|
|
|
self.member_widgets = member_widgets
|
2020-03-06 23:37:21 +01:00
|
|
|
|
|
|
|
f.edit()
|
|
|
|
|
|
|
|
|
|
|
|
def main(*_args):
|
|
|
|
if len(argv) > 1:
|
|
|
|
member_struct = json.load(open(argv[1], 'r'))
|
|
|
|
else:
|
|
|
|
member_struct = json.load(open('example.json', 'r'))
|
|
|
|
app = FormApp(member_struct)
|
|
|
|
app.run()
|
2020-03-14 10:43:38 +01:00
|
|
|
|
2020-03-10 16:00:18 +01:00
|
|
|
new_data = {}
|
2020-03-14 10:43:38 +01:00
|
|
|
new_data['stammdaten'] = dict(
|
|
|
|
zip(app.sd2.keys(), map(lambda f: f.value, app.base_data_widgets.values())))
|
|
|
|
new_data['finanzdaten'] = dict(
|
|
|
|
zip(app.fin2.keys(), map(lambda f: f.value, app.finance_widgets.values())))
|
|
|
|
new_data['mitgliederdaten'] = dict(
|
|
|
|
zip(app.mem2.keys(), map(lambda f: f.value, app.member_widgets.values())))
|
2020-03-14 10:43:03 +01:00
|
|
|
new_data['stammdaten']['address_label'] = \
|
|
|
|
f"{new_data['stammdaten']['fullname']}\n \
|
|
|
|
{new_data['stammdaten']['address_street']}\n \
|
|
|
|
{new_data['stammdaten']['address_code']} {new_data['stammdaten']["address_locality"]}"
|
|
|
|
|
2020-03-14 10:43:38 +01:00
|
|
|
outfile_name = '{}_{}.json'.format(date.today().isoformat(
|
|
|
|
), '_'.join(new_data['stammdaten']['fullname'].split()))
|
2020-03-10 16:11:51 +01:00
|
|
|
with open(outfile_name, 'w') as outfile:
|
2020-03-10 16:00:18 +01:00
|
|
|
json.dump(new_data, outfile, sort_keys=True, indent=4)
|
2020-03-06 23:37:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
npyscreen.wrapper_basic(main)
|