Skip to content
Snippets Groups Projects
Forked from AURA / engine
1704 commits behind, 92 commits ahead of the upstream repository.
test.py 1.01 KiB
#!/usr/bin/python3

from libraries.database.broadcasts import *
import simplejson
import sqlalchemy

def alchemyencoder(obj):
    """JSON encoder function for SQLAlchemy special classes."""
    if isinstance(obj, datetime.date):
        return obj.isoformat()
    elif isinstance(obj, decimal.Decimal):
        return float(obj)
    elif isinstance(obj, sqlalchemy.orm.state.InstanceState):
        return ""
    #elif isinstance(obj, Schedule):
    #    return simplejson.dumps([obj._asdict()], default=alchemyencoder)
    else:
        return str(obj)

def select_with_relationship():
    se = TrackServiceScheduleEntry.select_all()
    for e in se:
        print(e._asdict())

#    programme_as_string = simplejson.dumps([se[0]._asdict()], default=alchemyencoder)
#    print(programme_as_string)

# # ## ## ## ## ## # #
# # ENTRY FUNCTION # #
# # ## ## ## ## ## # #
def main():
    select_with_relationship()
# # ## ## ## ## ## ## # #
# # End ENTRY FUNCTION # #
# # ## ## ## ## ## ## # #


if __name__ == "__main__":
    main()