From bc8b86690cd5335e23c907c0389cc6e128faf5dd Mon Sep 17 00:00:00 2001 From: spacepatcher Date: Wed, 27 Dec 2017 12:31:05 +0000 Subject: [PATCH] Fix #6 --- app/modules/db_feeds.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/modules/db_feeds.py b/app/modules/db_feeds.py index 35b06c1..4681834 100644 --- a/app/modules/db_feeds.py +++ b/app/modules/db_feeds.py @@ -72,14 +72,15 @@ def db_update_removed(self, feed_data): current_time_db = datetime.now() current_time_json = current_time_db.isoformat() for ip in ip_group: - select_query = select([feed_table.c.timeline]).where(feed_table.c.ip == ip) - timeline_list = db_session.execute(select_query).fetchone()[0] - period_json = timeline_list.pop() - period_json["removed"] = current_time_json - timeline_list.append(period_json) - update_query = update(feed_table).where(feed_table.c.ip == ip).values(last_removed=current_time_db, - timeline=timeline_list) - db_session.execute(update_query) + if db_session.query((exists().where(feed_table.c.ip == ip))).scalar(): + select_query = select([feed_table.c.timeline]).where(feed_table.c.ip == ip) + timeline_list = db_session.execute(select_query).fetchone()[0] + period_json = timeline_list.pop() + period_json["removed"] = current_time_json + timeline_list.append(period_json) + update_query = update(feed_table).where(feed_table.c.ip == ip).values(last_removed=current_time_db, + timeline=timeline_list) + db_session.execute(update_query) db_session.commit() except Exception as e: self.logger.error("Error: {}".format(e))