-
Notifications
You must be signed in to change notification settings - Fork 0
/
mongo.py
57 lines (43 loc) · 1.45 KB
/
mongo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import pymongo
from datetime import date, datetime, timedelta
conn = pymongo.MongoClient('mongodb+srv://bang:[email protected]/test?retryWrites=true')
db = conn.get_database('bluevisor')
date = datetime.now().strftime('%Y-%m-%d')
def check_point_save(name, title):
collection = db.get_collection('check_point')
post = {
"name": name,
"title": title,
"save_date": date
}
collection.update({"name": name},post,upsert=True)
def post_save(name, title, link, sdate, edate):
collection = db.get_collection('posts')
post = {
"name": name,
"title": title,
"link": link,
"start_date": sdate,
"end_date": edate,
"save_date": date
}
collection.insert_one(post)
def check_point_read(name):
collection = db.get_collection('check_point')
if collection.find_one({"name": name}) is None:
post = {
"name": name,
"title": '',
"save_date": date
}
collection.update({"name": name}, post, upsert=True)
return collection.find_one({"name": name})
# return collection.find({"date": date})
def is_saved(title):
collection = db.get_collection('posts')
return collection.find_one({"title": title})
def count():
collection = db.get_collection('posts')
return collection.find({"save_date": date}).count()
def close():
conn.close()