forked from kkaatttiechang/Database
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocument.py
More file actions
executable file
·62 lines (48 loc) · 1.53 KB
/
document.py
File metadata and controls
executable file
·62 lines (48 loc) · 1.53 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/python
from pymongo import MongoClient
from bson import ObjectId
import cv2
client = MongoClient('mongodb://10.34.33.28:33333')
db = client.database
crawl = db.crawl
global tublelist
class profile:
imagepath = ""
source = ""
web_url = ""
image_url = ""
datetime = 0
keyword = ""
tag = ""
change = ""
def create (self):
prev_id = db.crawl.count()
documentformatter={
"source":self.source,
"web url": self.web_url,
"image url":self.image_url,
"keyword":self.keyword,
"height":self.imagepath.shape[0],
"width":self.imagepath.shape[1],
"datetime": self.datetime,
"_id" : ObjectId(repr(prev_id+1))
}
db.crawl.insert([documentformatter])
def find_bykeyword (self, tags):
count = db.crawl.find({"keyword":{"$all":tags}}).count()
if count > 0:
for users in count:
profilelist[user] = db.crawl.find_one({"keyword":{"$all":tags}}).skip(user)
tuplelist = tuple(profilelist)
return db.crawl.find({"keyword":{"$all":tags}}).count()
else:
return -1
def update(self, tag, change):
numupdates = find_bykeyword(tag)
if numupdates > 0:
db.collection.update({"keyword":tag},{"keyword":change} )
#update keywords
def delete(self, tag):
numdeletes = find_bykeyword(tag)
if numdeletes > 0:
db.collection.remove({"keyword":tag})