-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstorage.py
More file actions
30 lines (24 loc) · 791 Bytes
/
storage.py
File metadata and controls
30 lines (24 loc) · 791 Bytes
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
__author__ = 'couldtt'
import pymongo
import time
class MongoStorage():
def __init__(self):
try:
client = pymongo.MongoClient('localhost', 27017)
self.db = client.limitfree
self.collection = self.db.books
except:
print("MongoDB数据库链接失败")
localtime = time.localtime(time.time())
self.now_time = time.strftime('%Y%m%d%H', localtime)
def save(self, type, platform):
today = {
'time': self.now_time,
'type': type,
'platform': platform
}
save_id = self.collection.save(today)
if save_id:
return True
def get_today(self, type):
return self.collection.find_one({'time': self.now_time, 'type': type})