-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
67 lines (52 loc) · 1.65 KB
/
Copy pathdatabase.py
File metadata and controls
67 lines (52 loc) · 1.65 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
63
64
65
66
67
import pymongo
import os
def scrape(data):
myclient = pymongo.MongoClient(os.environ['mongo_uri'])
database = myclient['noSVG']
userid = data.chat.id
chattype = data.chat.type
collection = database["usercache"]
if (chattype == 'group') or (chattype == 'supergroup'):
collection = database["groupcache"]
manybase = myclient['manybase']
cluster = manybase["totalcache"]
if (chattype == 'group') or (chattype == 'supergroup'):
cluster = manybase["groupical"]
firstseen = data.date
result = collection.find_one({'userid': userid})
manyres = cluster.find_one({'userid': userid})
try:
result['userid']
userexist = True
except:
userexist = False
try:
manyres['userid']
exuser = True
except:
exuser = False
title = data.chat.title
username = data.chat.username
firstname = data.chat.first_name
lastname = data.chat.last_name
dc = data.from_user.dc_id
scraped = {}
scraped['userid'] = userid
scraped['chattype'] = chattype
if (chattype == 'group') or (chattype == 'supergroup'):
scraped['title'] = title
scraped['type'] = chattype
scraped['username'] = username
scraped['dc'] = dc
scraped['firstseen'] = firstseen
else:
scraped['username'] = username
scraped['firstname'] = firstname
scraped['lastname'] = lastname
scraped['is-banned'] = False
scraped['dc'] = dc
scraped['firstseen'] = firstseen
if (userexist == False):
collection.insert_one(scraped)
if (exuser == False):
cluster.insert_one(scraped)