Skip to Content
Python GUI Programming with Tkinter
book

Python GUI Programming with Tkinter

by Alan D. Moore
May 2018
Beginner to intermediate content levelBeginner to intermediate
452 pages
11h 26m
English
Packt Publishing
Content preview from Python GUI Programming with Tkinter

Implementing the SQLModel.add_weather_data() method

Over in models.py, let's add a new method to the SQLModel class called add_weather_data(), which takes a data dict as its only argument.

Let's start this method by writing an INSERT query as follows:

    def add_weather_data(self, data):
        query = (
            'INSERT INTO local_weather VALUES '
            '(%(observation_time_rfc822)s, %(temp_c)s, '
            '%(relative_humidity)s, %(pressure_mb)s, '
            '%(weather)s)'
        )

This is a straightforward parameterized INSERT query using variable names that match the dict keys that the get_local_weather() function extracts from the XML data. We should only need to pass this query and the data dict into our query() method.

There is one problem, however; if we get a duplicate timestamp, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python GUI Programming with Tkinter - Second Edition

Python GUI Programming with Tkinter - Second Edition

Alan D. Moore

Publisher Resources

ISBN: 9781788835886Supplemental Content