forked from yuanxu-li/quora-crawler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstorer.py
More file actions
23 lines (19 loc) · 668 Bytes
/
Copy pathstorer.py
File metadata and controls
23 lines (19 loc) · 668 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import pymongo
class Storer(object):
def __init__(self, db, collection):
self.client = pymongo.MongoClient("localhost", 27017)
self.db = self.client[db]
self.collection = self.db[collection]
def save(self, item):
self.collection.replace_one({"_id": item["_id"]}, item, True)
"""
if "_id" in item and self.is_exist(item["_id"]):
self.collection.update_one({"_id": item["_id"]}, item)
else:
self.collection.insert_one(item)
"""
def is_exist(self, _id):
if self.collection.find_one({"_id": _id}):
return True
else:
return False