#!/usr/bin/env python # encoding: utf-8 import npyscreen import json 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') sd = self.member['stammdaten'] self.sd2 = {} self.sd2['fullname'] = f.add(npyscreen.TitleText, name="Name: ", value=sd['fullname']) self.sd2['nickname'] = f.add(npyscreen.TitleText, name="Nickname: ", value=sd['nickname']) self.sd2['address_street'] = f.add( npyscreen.TitleText, name="Adresse - Straße: ", value=sd['address_street']) self.sd2['address_locality'] = f.add( npyscreen.TitleText, name="Adresse - Stadt: ", value=sd['address_locality']) self.sd2['address_code'] = f.add(npyscreen.TitleText, name="Adresse - PLZ: ", value=sd['address_code']) self.sd2['address_country'] = f.add( npyscreen.TitleText, name="Adresse - Land: ", value=sd['address_country']) self.sd2['birth_date'] = f.add(npyscreen.TitleText, name="Geburtstag: ", value=sd['birth_date']) self.sd2['birth_location'] = f.add( npyscreen.TitleText, name="Geburtsort: ", value=sd['birth_location']) self.sd2['email'] = f.add(npyscreen.TitleText, name="email: ", value=sd['email']) self.sd2['pgp-key'] = f.add(npyscreen.TitleText, name="URI PGP Key: ", value=sd['pgp-key']) self.sd2['ssh-key'] = f.add(npyscreen.TitleText, name="URI SSH Key: ", value=sd['ssh-key']) fin = self.member['finanzdaten'] self.fin2 = {} self.fin2['iban'] = f.add(npyscreen.TitleText, name="IBAN: ", value=fin['iban']) self.fin2['bic'] = f.add(npyscreen.TitleText, name="BIC: ", value=fin['bic']) self.fin2['holder'] = f.add(npyscreen.TitleText, name="Kontoinhaber: ", value=fin['holder']) self.fin2['issuance'] = f.add(npyscreen.TitleText, name="Tag der Erteilung Lastschriftmandat: ", value=fin['issuance']) self.fin2['reference'] = f.add(npyscreen.TitleText, name="Mandatsreferenznummer: ", value=fin['reference']) self.fin2['scan-sepa-mandate'] = f.add(npyscreen.TitleText, name="URI Scan SEPA-Mandat: ", value=fin['scan-sepa-mandate']) mem = self.member['mitgliederdaten'] self.mem2 = {} self.mem2['status'] = f.add(npyscreen.TitleText, name="Status: ", value=mem['status']) self.mem2['von'] = f.add(npyscreen.TitleText, name="Von: ", value=mem['von']) self.mem2['bis'] = f.add(npyscreen.TitleText, name="Bis: ", value=mem['bis']) self.mem2['mitgliedsbeitrag'] = f.add(npyscreen.TitleText, name="Mitgliedsbeitrag: ", value=mem['mitgliedsbeitrag']) self.mem2['schliessberechtigung'] = f.add(npyscreen.TitleText, name="Schliessberechtigung: ", value=mem['schliessberechtigung']) self.mem2['scan-antrag'] = f.add(npyscreen.TitleText, name="URI Scan Antrag: ", value=mem['scan-antrag']) 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() new_data = {} new_data['stammdaten'] = dict(zip(app.sd2.keys(), map(lambda f: f.value, app.sd2.values()))) new_data['finanzdaten'] = dict(zip(app.fin2.keys(), map(lambda f: f.value, app.fin2.values()))) new_data['mitgliederdaten'] = dict(zip(app.mem2.keys(), map(lambda f: f.value, app.mem2.values()))) with open('foo.json', 'w') as outfile: json.dump(new_data, outfile, sort_keys=True, indent=4) if __name__ == "__main__": npyscreen.wrapper_basic(main)