-
Notifications
You must be signed in to change notification settings - Fork 2
/
mongosave.py
75 lines (63 loc) · 1.94 KB
/
mongosave.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
'''
Use this code while running the webapp on localhost
with a mongodb sever running
'''
import pymongo
from bson.objectid import ObjectId
from datetime import datetime
class mongosave:
currdate = None
currtime = None
connection = None
db = None
collection = None
def __init__(self):
self.connection = pymongo.Connection()
self.db = self.connection['codebuddy_db']
#self.collection = self.db['paste_collection']
def userlogin(self, email, password):
#self.collection = self.db['user_login']
self.collection = self.db['codebuddy_collect']
try:
result = list(self.collection.find({'user_email': email}))
if not len(result):
print('########new######')
result = str(self.collection.insert({'user_email': email, 'user_password': password}))
else:
if result[0].get('user_password') == password:
result = str(result[0].get('_id'))
print("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
print('####already#####', result)
else:
print('####already#####')
return -2
return result
except Exception, e:
print(e)
return -1
def login_check(self, _id):
self.collection = self.db['codebuddy_collect']
result = list(self.collection.find({'_id': ObjectId(_id)}))
print str(result[0].get('_id'))
if str(result[0].get('_id')) == _id:
return 1
else:
return -1
def save(self, _id, data):
self.collection = self.db['paste_collection']
currdate = datetime.now().strftime('%Y-%m-%d')
currtime = datetime.now().strftime('%H:%M')
self.collection.insert({'_id': _id, 'paste_doc': data, "date": currdate, 'time': currtime})
print(list(self.collection.find()))
def check(self, _id):
self.collection = self.db['paste_collection']
try:
result = list(self.collection.find({'_id': _id}, {'paste_doc':1, '_id':0}))
if not len(result):
print 'returning coz no data'
return None
restext = result[-1].get('paste_doc', None)
print restext
return restext
except Exception, e:
print e