-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.py
More file actions
46 lines (40 loc) · 1.46 KB
/
data.py
File metadata and controls
46 lines (40 loc) · 1.46 KB
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
from pymongo import MongoClient
from string_dispose_new import process
import time
class profile:
def __init__(self):
myclient = MongoClient('mongodb://localhost:27017/')
mydatabase = myclient['db']
mydata = mydatabase['data_list']
mydata.delete_many({})
self.file = mydata
self.taglist = ['fake']
self.badtag = [' ','is','and','to','are','?',',','.','if','what','where','when']
def add(self,dict):
for tag in dict['tags']:
if(tag not in self.taglist and tag not in self.badtag):
self.taglist.append(tag)
if self.file.find({'content':dict['content']}):
self.file.insert_one(dict)
def add_auto(self,text):
dict = data()
dict.title = process(text)[0]
dict.content = text
dict.time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
dict.tags = process(text)
self.add(dict.todict())
def Find(self,tagname):
ret = []
for x in (self.file).find({'tags':tagname}):
ret.append(x)
return ret
class data:
def __init__(self,title='',content='',time='',tags=''):
self.title = title
self.content = content
self.time = time
self.tags = tags
def tolist(self):
return [self.title,self.content,self.time,self.tags]
def todict(self):
return {'title':self.title, 'content':self.content,'time':self.time,'tags':self.tags}