-
Notifications
You must be signed in to change notification settings - Fork 5
/
mongodb.py
88 lines (69 loc) · 2.23 KB
/
mongodb.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
76
77
78
79
80
81
82
83
84
85
import pymongo
def get_fields_count():
# print("Welcome to pyMongo")
client = pymongo.MongoClient("mongodb://localhost:27017")
# print(client)
db = client['hackattack']
collection = db['spamlist']
return len(list(collection.find()))
def threat_level(id):
# print("Welcome to pyMongo")
client = pymongo.MongoClient("mongodb://localhost:27017")
# print(client)
db = client['hackattack']
collection = db['spamlist']
mongo_resp = list(collection.find({"Input": id}))
if len(mongo_resp)!=0:
return mongo_resp[0]
else:
return 0
def is_spam(id):
print("Welcome to pyMongo")
client = pymongo.MongoClient("mongodb://localhost:27017")
print(client)
db = client['hackattack']
collection = db['spamlist']
dictionary = {'Number_of_spams':0,'Input':id,'Threat_level':'Low'}
collection.insert_one(dictionary)
my_input = collection.find_one({'Input':id})
if (my_input):
print("Input: ",my_input)
spam_count = list(my_input.values())[1]
print("spam_count = ",spam_count)
spam_count=int(spam_count)+1
spam_count = int(spam_count)
if (spam_count<=5):
collection.replace_one({'Input':id},
{
'Number_of_spams':spam_count,
'Input':id,
'Threat_level':'Low'
})
elif (spam_count<=10):
collection.replace_one({'Input':id},
{
'Number_of_spams':spam_count,
'Input':id,
'Threat_level':'Medium'
})
elif (spam_count>10):
collection.replace_one({'Input':id},
{
'Number_of_spams':spam_count,
'Input':id,
'Threat_level':'High'
})
'''
collection.replace_one({'Input':id},
{
'Number_of_spams':spam_count,
'Input':id
})
'''
collection.delete_many({'Number_of_spams':0})
if __name__ == '__main__':
print(get_fields_count())
print(threat_level('xyz@gmail.com'))
print(threat_level('abc@gmail.com'))
print(threat_level('9988776588'))
print(threat_level('9988776589'))