def update(self): """ Perform update from source (Fio webpages). """ #open DB for storing payments #fetch will return dictionary rather then a tuple new_count=0 for payment in fio.scrape(url): self.cur.execute("SELECT * FROM Payments " "WHERE arrival=? " "AND identification=? " "AND message=?;", ( payment.arrival, payment.identification, payment.message)) if self.cur.fetchone(): # there is already this payment in DB, skip it pass else: # this is new payment, not yet in DB, insert it self.add_payment(payment) new_count += 1 self.cur.execute("INSERT INTO UpdateHistory VALUES(datetime())") self.con.commit() print("Update complete (%d new payments)"%new_count)
def update(self): """ Perform update from source (Fio webpages). """ new_count=0 for payment in fio.scrape(url): try: Payment.objects.get(date=payment.arrival, identification=payment.identification, message=payment.message, amount=payment.amount) except Payment.MultipleObjectsReturned: continue except Payment.DoesNotExist: new_count += 1 self.add_payment(payment) print("Update complete (%d new payments)" % new_count)