Skip to content
Snippets Groups Projects
Select Git revision
  • cd3dbef71bb5f2af645d846213ab6e9027526d47
  • class default protected
2 results

ProgrammingAssignment1.ipynb

Blame
  • Forked from Zeynep Hakguder / csce478
    Source project has a limited visibility.
    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()