Skip to content
Snippets Groups Projects
Select Git revision
  • c3a8f4f648666047b749281407310bdc6591d06f
  • main default protected
  • threads
3 results

arubaModels.py

Blame
  • example2.py 1.08 KiB
    from sys import stderr
    from math import inf
    
    from sqlalchemy.exc import SQLAlchemyError
    from values import ValueDatabase, Value
    
    from kivy.app import App
    from kivy.properties import NumericProperty
    
    
    class Example2App(App):
        smallest_positive = NumericProperty(inf)
    
        @staticmethod
        def _find_smallest_positive(values):
            result = inf
            for value in values:
                if 0 < value < result:
                    result = value
            return result
    
        def on_start(self):
            url = ValueDatabase.construct_mysql_url('localhost', 3306, 'values', 'root', 'cse1208')
            value_database = ValueDatabase(url)
            session = value_database.create_session()
            values = [record.value for record in session.query(Value).all()]
            self.smallest_positive = Example2App._find_smallest_positive(values)
    
    
    def main():
        try:
            app = Example2App()
            app.run()
        except SQLAlchemyError as exception:
            print('Database connection failed!', file=stderr)
            print(f'Cause: {exception}', file=stderr)
            exit(1)
    
    
    if __name__ == '__main__':
        main()