def save(self, a): mapper = PostgresDBPrivileged.getInstance(self.user, self.session_token) cur = mapper.cursor() try: if a.isnew: cur.execute(PostgreSQLArticleLoader.insert % (a.id, a.feed.id, a.link, re.sub("\\\\'|[']", "''", a.title), re.sub("\\\\'|[']", "''", a.content), strftime("%Y-%m-%d %H:%M:%S",a.pub_date.timetuple()), strftime("%Y-%m-%d %H:%M:%S",a.fetch_date.timetuple()), strftime("%Y-%m-%d %H:%M:%S",a.create_date.timetuple())) ) else: cur.execute(PostgreSQLArticleLoader.update % ( re.sub("\\\\'|[']", "''", a.title), re.sub("\\\\'|[']", "''", a.content), strftime("%Y-%m-%d %H:%M:%S",a.pub_date.timetuple()), strftime("%Y-%m-%d %H:%M:%S",a.fetch_date.timetuple()), a.id ) ) except Exception, e: print "fallo ", str(e), " - link =", a.link," id=",a.id, " feed=",a.feed.id
def deleteArticlesFromFeed(self, feed): mapper = PostgresDBPrivileged.getInstance(self.user, self.session_token) cur = mapper.cursor() cur.execute("delete from articles where feed = %s", (feed.id,)) mapper.commit()