Пример #1
0
def main():
    SessionMaker = connect.connect('members', 'members', 'localhost',
                                   'members')
    session = SessionMaker()

    memberdictlist = csvimporter.parse_csv(sys.argv[1], ',', '"')
    for memberdict in memberdictlist:
        new_member = create_phux(session)

        csvimporter.update_contact_info(new_member, memberdict, dry_run=False)

        birthdate = memberdict["birthDate_fld_format"]
        if birthdate:
            datelist = [int(s) for s in birthdate.split('.')]
            datelist.reverse()
            new_member.birthDate_fld = datetime.datetime(*datelist)

        if memberdict["subscribedtomodulen_fld_format"]:
            new_member.subscribedtomodulen_fld = 0

        departmentstr = memberdict["department_format"]
        if departmentstr:
            department = get_department(session,
                                        DEPARTMENTS[int(departmentstr) - 1])
            new_departmentmship = create_row(DepartmentMembership, session)
            new_departmentmship.member = new_member
            new_departmentmship.department = department
            new_departmentmship.startTime_fld = datetime.datetime(
                day=29, month=8, year=int(memberdict["registeredYear"]))
            session.add(new_departmentmship)

        genderstr = memberdict["gender_fld_format"]
        if genderstr:
            new_member.gender_fld = int(genderstr)

    print("Dirty: ", session.dirty)
    print("New: ", session.new)
    session.commit()
Пример #2
0
def main():
    SessionMaker = connect.connect('members', 'members', 'localhost', 'members')
    session = SessionMaker()

    memberdictlist = csvimporter.parse_csv(sys.argv[1], ',', '"')
    for memberdict in memberdictlist:
        new_member = create_phux(session)

        csvimporter.update_contact_info(new_member, memberdict, dry_run = False)

        birthdate = memberdict["birthDate_fld_format"]
        if birthdate:
            datelist = [int(s) for s in
                    birthdate.split('.')]
            datelist.reverse()
            new_member.birthDate_fld = datetime.datetime(*datelist)

        if memberdict["subscribedtomodulen_fld_format"]:
            new_member.subscribedtomodulen_fld = 0;

        departmentstr = memberdict["department_format"]
        if departmentstr:
            department = get_department(session,
                        DEPARTMENTS[int(departmentstr) - 1])
            new_departmentmship = create_row(DepartmentMembership, session)
            new_departmentmship.member = new_member
            new_departmentmship.department = department
            new_departmentmship.startTime_fld = datetime.datetime(day=29, month=8,
                    year=int(memberdict["registeredYear"]))
            session.add(new_departmentmship)

        genderstr = memberdict["gender_fld_format"]
        if genderstr:
            new_member.gender_fld = int(genderstr)

    print("Dirty: ", session.dirty)
    print("New: ", session.new)
    session.commit()
Пример #3
0
def main():
    SessionMaker = connect.connect('members',
        'members', 'localhost', 'members')
    session = SessionMaker()

    memberdictlist = csvimporter.parse_csv(sys.argv[1], ',', None)
    for memberdict in memberdictlist:
        memberquery = session.query(Member).filter(Member.surName_fld ==
                memberdict["Efternamn"])
        birthdatestr = ""
        try:
            birthdatestr = memberdict["födelsedatum"]
        except KeyError:
            pass
        if birthdatestr:
            datelist = [int(s) for s in
                    birthdatestr.split('.')]
            datelist.reverse()
            birthdate = datetime.datetime(*datelist)

            memberquery = memberquery.filter(Member.birthDate_fld ==
                            birthdate)
        else:
            memberquery = memberquery.join(
                    ContactInformation).filter(
                    ContactInformation.phone_fld == memberdict["Telefon"])

        try:
            member = memberquery.one()

            member.contactinfo.email_fld = memberdict["e-post"]
        except sqlalchemy.orm.exc.NoResultFound:
            print("Not found: ", memberquery)


    session.commit()