Pure pymongo data saving for cross-benchmarking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def save_data(self, rows): | |
# Mark all as 'old' | |
self.db.offers.update( | |
{'productlist': self.productlist.name}, | |
{'$set': {'old': True}}, multi=True, safe=True) | |
# Upsert | |
for row in rows: | |
# Add productlist key and mark as 'not old' | |
row['productlist'] = self.productlist.name | |
row['old'] = False | |
resp = self.db.offers.update( | |
{'articlenumber': row['articlenumber'], | |
'productlist': self.productlist.name}, | |
{'$set': row}, upsert=True, safe=True) | |
if resp['updatedExisting']: | |
updated += 1 | |
else: | |
inserted += 1 | |
# Delete de-listed offers | |
for offer in self.db.offers.find( | |
{'productlist': self.productlist.name, 'old': True}): | |
removed += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment