PEP 8 improvements.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Sat, 20 Feb 2021 13:21:25 +0000 (14:21 +0100)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Sat, 20 Feb 2021 13:31:26 +0000 (14:31 +0100)
tests/test_wrfeed.py
wrfeed/berichte.py
wrfeed/wrfeed.py

index aed5896cb19ce8661e8ed52385f1fcec312b75d2..d4ccc5d945f71e6b956c675a977e63fb78637a59 100644 (file)
@@ -33,7 +33,8 @@ class TestDbWrfeed(WrfeedTestBase):
             # create database
             uri = make_url(wrfeed.app.config['SQLALCHEMY_DATABASE_URI'])
             self.uri = uri
-            uri_nodb = URL(uri.drivername, host=uri.host, port=uri.port, username=uri.username, password=uri.password, query=uri.query)
+            uri_nodb = URL(uri.drivername, host=uri.host, port=uri.port, username=uri.username,
+                           password=uri.password, query=uri.query)
             engine_nodb = sqlalchemy.create_engine(uri_nodb)
             engine_nodb.execute("DROP DATABASE IF EXISTS {}".format(uri.database))
             engine_nodb.execute("CREATE DATABASE {} CHARACTER SET = '{}'".format(uri.database, 'UTF8'))
@@ -50,9 +51,14 @@ class TestDbWrfeed(WrfeedTestBase):
             # update dates
             seconds_diff, = con.execute("SELECT TIMESTAMPDIFF(SECOND, '2017-03-31 07:00', now())").fetchone()
             seconds_diff = int(seconds_diff)
-            con.execute("UPDATE wrreport SET date_report = DATE(date_report + INTERVAL %s SECOND) WHERE time_report IS NULL", (seconds_diff,))
-            con.execute("UPDATE wrreport SET date_report = DATE(TIMESTAMP(date_report, time_report) + INTERVAL %s SECOND) WHERE time_report IS NOT NULL", (seconds_diff,))
-            con.execute("UPDATE wrreport SET time_report = TIME(TIMESTAMP(date_report, time_report) + INTERVAL %s SECOND) WHERE time_report IS NOT NULL", (seconds_diff,))
+            con.execute("UPDATE wrreport SET date_report = DATE(date_report + INTERVAL %s SECOND) "
+                        "WHERE time_report IS NULL", (seconds_diff,))
+            con.execute("UPDATE wrreport SET date_report = "
+                        "DATE(TIMESTAMP(date_report, time_report) + INTERVAL %s SECOND) "
+                        "WHERE time_report IS NOT NULL", (seconds_diff,))
+            con.execute("UPDATE wrreport SET time_report = "
+                        "TIME(TIMESTAMP(date_report, time_report) + INTERVAL %s SECOND) "
+                        "WHERE time_report IS NOT NULL", (seconds_diff,))
             con.execute("UPDATE wrreport SET date_entry = date_entry + INTERVAL %s SECOND", (seconds_diff,))
             con.execute("UPDATE wrreport SET date_invalid = date_invalid + INTERVAL %s SECOND", (seconds_diff,))
             con.execute("UPDATE wrreport SET delete_date = delete_date + INTERVAL %s SECOND", (seconds_diff,))
@@ -77,7 +83,8 @@ class TestDbWrfeed(WrfeedTestBase):
                 self.assertTrue(result.data.startswith(b'<?xml'))
                 root = et.fromstring(result.data)
                 self.assertIn('Rodelbahnberichte', root.find('{http://www.w3.org/2005/Atom}title').text)
-                self.assertEqual(len(root.findall('{http://www.w3.org/2005/Atom}entry')), count, '"{}" not found {} times'.format(bahn, count))
+                self.assertEqual(len(root.findall('{http://www.w3.org/2005/Atom}entry')), count,
+                                 '"{}" not found {} times'.format(bahn, count))
 
     def test_bahnen(self):
         bahnen_count = {
@@ -96,7 +103,8 @@ class TestDbWrfeed(WrfeedTestBase):
                 self.assertTrue(result.data.startswith(b'<?xml'))
                 root = et.fromstring(result.data)
                 self.assertIn('Rodelbahnberichte', root.find('{http://www.w3.org/2005/Atom}title').text)
-                self.assertEqual(len(root.findall('{http://www.w3.org/2005/Atom}entry')), count, 'bahnen "{}" not found {} times'.format(bahnen, count))
+                self.assertEqual(len(root.findall('{http://www.w3.org/2005/Atom}entry')), count,
+                                 f'bahnen "{bahnen}" not found {count} times')
 
     def test_region(self):
         region_count = {
@@ -110,4 +118,5 @@ class TestDbWrfeed(WrfeedTestBase):
                 self.assertTrue(result.data.startswith(b'<?xml'))
                 root = et.fromstring(result.data)
                 self.assertIn('Rodelbahnberichte', root.find('{http://www.w3.org/2005/Atom}title').text)
-                self.assertEqual(len(root.findall('{http://www.w3.org/2005/Atom}entry')), count, '"{}" not found {} times'.format(region, count))
+                self.assertEqual(len(root.findall('{http://www.w3.org/2005/Atom}entry')), count,
+                                 f'"{region}" not found {count} times')
index c9c312da80924107671630a0cfc8140c84739a9c..e001d0f52ef99af182df3d36ab6455b5083e585a 100644 (file)
@@ -63,21 +63,24 @@ def create_feed(db, limit, page_title=None, page_ids=None, region_name=None):
         sub_row = sub_result.fetchone()
         region_id = sub_row.id
         # (2) now we have the id of the region
-        sql = sql.where(wrreport.c.page_id.in_(db.select([wrregioncache.c.page_id]).where(region_id == wrregioncache.c.region_id)))
+        sql = sql.where(wrreport.c.page_id.in_(db.select([wrregioncache.c.page_id])
+                                               .where(region_id == wrregioncache.c.region_id)))
     else:
         # user wants to have all reports
         pass
     result = db.session.connection().execute(sql)
 
-    feed = Element("feed", xmlns="http://www.w3.org/2005/Atom", attrib={'xmlns:georss': 'http://www.georss.org/georss', 'xmlns:wr': 'http://www.winterrodeln.org/schema/wrreport'})
+    feed = Element("feed", xmlns="http://www.w3.org/2005/Atom",
+                   attrib={'xmlns:georss': 'http://www.georss.org/georss',
+                           'xmlns:wr': 'http://www.winterrodeln.org/schema/wrreport'})
     feed_title = SubElement(feed, "title")
     feed_title.text = "Winterrodeln Rodelbahnberichte"
     feed_id = SubElement(feed, "id")
-    if not page_title is None:
+    if page_title is not None:
         feed_id.text = url_for('bahn', bahn=page_title, _external=True)
-    elif not page_ids is None:
+    elif page_ids is not None:
         feed_id.text = url_for('bahnen', bahnen="+".join(map(str, page_ids)), _external=True)
-    elif not region_name is None:
+    elif region_name is not None:
         feed_id.text = url_for('region', region=region_name, _external=True)
     else:
         feed_id.text = url_for('alle', _external=True)
@@ -90,12 +93,15 @@ def create_feed(db, limit, page_title=None, page_ids=None, region_name=None):
         entry = SubElement(feed, "entry")
         entry_title = SubElement(entry, "title")
         entry_title.text = row.page_title
-        entry.append(Element("link", rel="alternate", href="https://www.winterrodeln.org/wiki/{0}".format(page_title_url), type="text/html", hreflang="de"))
+        entry.append(Element("link", rel="alternate",
+                             href="https://www.winterrodeln.org/wiki/{0}".format(page_title_url),
+                             type="text/html", hreflang="de"))
         entry_id = SubElement(entry, "id")
         entry_id.text = "https://www.winterrodeln.org/wiki/{0}#{1}".format(page_title_url, row.id)
         entry_updated = SubElement(entry, "updated")
         entry_updated.text = row.date_entry.isoformat() + "+01:00"
-        if last_updated is None: last_updated = row.date_entry
+        if last_updated is None:
+            last_updated = row.date_entry
         # entry_summary = SubElement(entry, "summary")
         # entry_summary.text = str(condition)
         entry_content = SubElement(entry, "content")
@@ -103,12 +109,13 @@ def create_feed(db, limit, page_title=None, page_ids=None, region_name=None):
         entry_content_div = SubElement(entry_content, "div")
         entry_content_div.attrib["xmlns"] = "http://www.w3.org/1999/xhtml"
         entry_content_ul = SubElement(entry_content_div, "ul")
-        if not row.date_report is None:
+        if row.date_report is not None:
             entry_content_date = SubElement(entry_content_ul, "li")
             entry_content_date.text = "Bericht für " + row.date_report.isoformat()
-        if not row.condition is None:
+        if row.condition is not None:
             entry_content_condition = SubElement(entry_content_ul, "li")
-            entry_content_condition.text = "Schneelage: " + {1: 'Sehr gut', 2: 'Gut', 3: 'Mittelmäßig', 4: 'Schlecht', 5: 'Geht nicht'}[row.condition]
+            entry_content_condition.text = "Schneelage: " + \
+                {1: 'Sehr gut', 2: 'Gut', 3: 'Mittelmäßig', 4: 'Schlecht', 5: 'Geht nicht'}[row.condition]
         entry_content_description = SubElement(entry_content_ul, "li")
         entry_content_description.text = row.description
         entry_author = SubElement(entry, "author")
@@ -117,7 +124,7 @@ def create_feed(db, limit, page_title=None, page_ids=None, region_name=None):
             entry_author_name.text = "Anonymous user"
         else:
             entry_author_name.text = row.author_name
-        if not row.lon is None and not row.lat is None:
+        if row.lon is not None and row.lat is not None:
             entry_geo = SubElement(entry, "georss:point")
             entry_geo.text = "{lat} {lon}".format(lat=row.lat, lon=row.lon)
         entry_wrreport = SubElement(entry, "wr:report")
index d160c33e5401b10bb122723c7c83fe85dadabcb8..e55b30738b30326287d69bdb389531c3b909c8ad 100644 (file)
@@ -45,7 +45,7 @@ def bahnen(bahnen):
     try:
         page_ids = [int(page_id) for page_id in page_ids]
     except ValueError:
-        abort(400) # bad request
+        abort(400)  # bad request
     return app.response_class(create_feed(db, app.config['FEEDENTRYLIMIT'], page_ids=page_ids),
                               mimetype='application/atom+xml')