def load_abstimmungen(engine): _Abstimmung = sl.get_table(engine, 'abstimmung') i = 0 for row in sl.distinct(engine, _Abstimmung, 'subject', 'date'): thema = row.get('subject') abst = Abstimmung.query.filter_by(thema=thema).first() if abst is None: abst = Abstimmung() abst.thema = thema abst.datum = date(row.get('date')) db.session.add(abst) for stimme_ in sl.find(engine, _Abstimmung, subject=thema, matched=True): if i % 1000 == 0: sys.stdout.write(".") sys.stdout.flush() i += 1 person = Person.query.filter_by( fingerprint=stimme_.get('fingerprint')).first() if person is None: continue stimme = Stimme.query.filter_by( abstimmung=abst).filter_by( person=person).first() if stimme is not None: continue stimme = Stimme() stimme.entscheidung = stimme_['vote'] stimme.person = person stimme.abstimmung = abst db.session.add(stimme) db.session.commit()
def load_abstimmung(engine, source_url): table = sl.get_table(engine, 'abstimmung') stimmen = list(sl.find(engine, table, source_url=source_url, matched=True)) if not len(stimmen): log.error("No reconciled votes, signals deeper trouble?") return thema = stimmen[0].get('subject') abst = Abstimmung.query.filter_by(thema=thema).first() if abst is None: abst = Abstimmung() abst.thema = thema abst.datum = to_date(stimmen[0].get('date')) db.session.add(abst) db.session.flush() for stimme_ in stimmen: person = Person.query.filter_by( fingerprint=stimme_.get('fingerprint')).first() if person is None: continue stimme = Stimme.query.filter_by( abstimmung=abst).filter_by( person=person).first() if stimme is not None: continue stimme = Stimme() stimme.entscheidung = stimme_['vote'] stimme.person = person stimme.abstimmung = abst db.session.add(stimme) db.session.commit()
def load_abstimmung(engine, source_url): table = sl.get_table(engine, 'abstimmung') stimmen = list(sl.find(engine, table, source_url=source_url, matched=True)) if not len(stimmen): log.error("No reconciled votes, signals deeper trouble?") return thema = stimmen[0].get('subject') abst = Abstimmung.query.filter_by(thema=thema).first() if abst is None: abst = Abstimmung() abst.thema = thema abst.datum = to_date(stimmen[0].get('date')) db.session.add(abst) db.session.flush() for stimme_ in stimmen: person = Person.query.filter_by( fingerprint=stimme_.get('fingerprint')).first() if person is None: continue stimme = Stimme.query.filter_by(abstimmung=abst).filter_by( person=person).first() if stimme is not None: continue stimme = Stimme() stimme.entscheidung = stimme_['vote'] stimme.person = person stimme.abstimmung = abst db.session.add(stimme) db.session.commit()
def load_abstimmungen(ws): for thema in ws['abstimmung'].distinct('subject'): thema = thema.get('subject') abst = Abstimmung.query.filter_by(thema=thema).first() if abst is None: abst = Abstimmung() abst.thema = thema db.session.add(abst) for stimme_ in ws['abstimmung'].traverse(subject=thema): person = Person.query.filter_by( fingerprint=stimme_.get('fingerprint')).first() if person is None: continue stimme = Stimme() stimme.entscheidung = stimme_['vote'] stimme.person = person stimme.abstimmung = abst db.session.add(stimme) db.session.commit()