This commit is contained in:
耿伦伦 2021-12-01 17:21:27 +08:00
parent ecba1fbc31
commit 481c2f8b6b
13 changed files with 43 additions and 21 deletions

View File

@ -9,3 +9,6 @@ mongo:
uri : 'mongodb://localhost:27017/'
dbname: 'tiktok'
enabled: 'on'
api:
userinfo: 'https://live.douyin.com/webcast/user/?aid=6383&target_uid='

View File

@ -1,3 +1,4 @@
import traceback
from datetime import datetime
from store.mongo import MongoStore
@ -14,49 +15,50 @@ class Base:
return dict()
def user(self):
if(hasattr(self.instance, 'user')):
return self.instance.user
return None
def persists(self):
if config()['mongo']['enabled'] != 'on':
return
try:
store = MongoStore()
store.set_collection('user')
user = self.user()
if user is not None:
store.set_collection('user')
store.replace_one({
"id": user.id
}, {
"id": user.id,
"shortId": user.shortId,
"nickname": user.nickname,
"gender": user.gender,
"avatar_thumb": user.avatarThumb.urlList[0],
"followInfo": {
"followingCount": user.followInfo.followingCount,
"followerCount": user.followInfo.followerCount
}
}, upsert=True)
if not store.exists({'id': user.id}):
store.insert_one({
'id': user.id,
'shortId': user.shortId,
'nickname': user.nickname,
'gender': user.gender
})
store.set_collection(self.instance.common.method)
msg = {
"msgId": self.instance.common.msgId,
"roomId": self.instance.common.roomId,
"userId": user.id,
'content': self.format_content(),
'created_at': datetime.today().replace(microsecond=0)
}
if user is not None:
msg.update({
'userId': user.id
})
if len(self.extra_info()):
msg.update(self.extra_info())
store.insert_one(msg)
except Exception as e:
print(self.instance.common.method + ' persists error')
print(traceback.format_exc())
def __str__(self):
pass

View File

@ -7,6 +7,11 @@ class RoomUserSeqMessage(Base):
def __init__(self):
self.instance = message_pb2.RoomUserSeqMessage()
def extra_info(self):
return {
'total': self.instance.total,
}
def format_content(self):
return self.instance.totalUserStr

View File

@ -74,7 +74,7 @@ def decodeMsg(messages):
elif message.method == 'WebcastRoomUserSeqMessage':
room_user_seq_message = RoomUserSeqMessage()
room_user_seq_message.set_payload(message.payload)
# room_user_seq_message.persists()
room_user_seq_message.persists()
print(f"\n{YELLOW}[+] {room_user_seq_message} {RESET}")

Binary file not shown.

10
scripts/utils.py Normal file
View File

@ -0,0 +1,10 @@
import requests
from config.helper import config
def getUserinfo(uid):
try:
r = requests.get(config()['api']['userinfo'] + str(uid))
return r.json()
except:
pass

View File

@ -39,6 +39,5 @@ class Handler(FileSystemEventHandler):
return None
elif event.event_type == 'created':
print('here')
q.put(event.src_path)

View File

@ -18,3 +18,6 @@ class MongoStore:
def insert_many(self, data):
return self.collection.insert_many(data)
def exists(self, condition):
return self.collection.count_documents(condition, limit = 1) != 0