1
This commit is contained in:
parent
ecba1fbc31
commit
481c2f8b6b
@ -9,3 +9,6 @@ mongo:
|
|||||||
uri : 'mongodb://localhost:27017/'
|
uri : 'mongodb://localhost:27017/'
|
||||||
dbname: 'tiktok'
|
dbname: 'tiktok'
|
||||||
enabled: 'on'
|
enabled: 'on'
|
||||||
|
|
||||||
|
api:
|
||||||
|
userinfo: 'https://live.douyin.com/webcast/user/?aid=6383&target_uid='
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,3 +1,4 @@
|
|||||||
|
import traceback
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from store.mongo import MongoStore
|
from store.mongo import MongoStore
|
||||||
|
|
||||||
@ -14,7 +15,10 @@ class Base:
|
|||||||
return dict()
|
return dict()
|
||||||
|
|
||||||
def user(self):
|
def user(self):
|
||||||
return self.instance.user
|
if(hasattr(self.instance, 'user')):
|
||||||
|
return self.instance.user
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
def persists(self):
|
def persists(self):
|
||||||
if config()['mongo']['enabled'] != 'on':
|
if config()['mongo']['enabled'] != 'on':
|
||||||
@ -22,41 +26,39 @@ class Base:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
store = MongoStore()
|
store = MongoStore()
|
||||||
store.set_collection('user')
|
|
||||||
|
|
||||||
user = self.user()
|
user = self.user()
|
||||||
|
if user is not None:
|
||||||
|
store.set_collection('user')
|
||||||
|
|
||||||
store.replace_one({
|
if not store.exists({'id': user.id}):
|
||||||
"id": user.id
|
store.insert_one({
|
||||||
}, {
|
'id': user.id,
|
||||||
"id": user.id,
|
'shortId': user.shortId,
|
||||||
"shortId": user.shortId,
|
'nickname': user.nickname,
|
||||||
"nickname": user.nickname,
|
'gender': user.gender
|
||||||
"gender": user.gender,
|
})
|
||||||
"avatar_thumb": user.avatarThumb.urlList[0],
|
|
||||||
"followInfo": {
|
|
||||||
"followingCount": user.followInfo.followingCount,
|
|
||||||
"followerCount": user.followInfo.followerCount
|
|
||||||
}
|
|
||||||
}, upsert=True)
|
|
||||||
|
|
||||||
store.set_collection(self.instance.common.method)
|
store.set_collection(self.instance.common.method)
|
||||||
|
|
||||||
msg = {
|
msg = {
|
||||||
"msgId": self.instance.common.msgId,
|
"msgId": self.instance.common.msgId,
|
||||||
"roomId": self.instance.common.roomId,
|
"roomId": self.instance.common.roomId,
|
||||||
"userId": user.id,
|
|
||||||
'content': self.format_content(),
|
'content': self.format_content(),
|
||||||
'created_at': datetime.today().replace(microsecond=0)
|
'created_at': datetime.today().replace(microsecond=0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if user is not None:
|
||||||
|
msg.update({
|
||||||
|
'userId': user.id
|
||||||
|
})
|
||||||
|
|
||||||
if len(self.extra_info()):
|
if len(self.extra_info()):
|
||||||
msg.update(self.extra_info())
|
msg.update(self.extra_info())
|
||||||
|
|
||||||
store.insert_one(msg)
|
store.insert_one(msg)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(self.instance.common.method + ' persists error')
|
print(self.instance.common.method + ' persists error')
|
||||||
|
print(traceback.format_exc())
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
pass
|
pass
|
||||||
|
@ -7,6 +7,11 @@ class RoomUserSeqMessage(Base):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.instance = message_pb2.RoomUserSeqMessage()
|
self.instance = message_pb2.RoomUserSeqMessage()
|
||||||
|
|
||||||
|
def extra_info(self):
|
||||||
|
return {
|
||||||
|
'total': self.instance.total,
|
||||||
|
}
|
||||||
|
|
||||||
def format_content(self):
|
def format_content(self):
|
||||||
return self.instance.totalUserStr
|
return self.instance.totalUserStr
|
||||||
|
|
||||||
|
@ -74,9 +74,9 @@ def decodeMsg(messages):
|
|||||||
elif message.method == 'WebcastRoomUserSeqMessage':
|
elif message.method == 'WebcastRoomUserSeqMessage':
|
||||||
room_user_seq_message = RoomUserSeqMessage()
|
room_user_seq_message = RoomUserSeqMessage()
|
||||||
room_user_seq_message.set_payload(message.payload)
|
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}")
|
print(f"\n{YELLOW}[+] {room_user_seq_message} {RESET}")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
BIN
scripts/__pycache__/utils.cpython-39.pyc
Normal file
BIN
scripts/__pycache__/utils.cpython-39.pyc
Normal file
Binary file not shown.
Binary file not shown.
10
scripts/utils.py
Normal file
10
scripts/utils.py
Normal 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
|
@ -39,6 +39,5 @@ class Handler(FileSystemEventHandler):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
elif event.event_type == 'created':
|
elif event.event_type == 'created':
|
||||||
print('here')
|
|
||||||
q.put(event.src_path)
|
q.put(event.src_path)
|
||||||
|
|
||||||
|
Binary file not shown.
@ -18,3 +18,6 @@ class MongoStore:
|
|||||||
|
|
||||||
def insert_many(self, data):
|
def insert_many(self, data):
|
||||||
return self.collection.insert_many(data)
|
return self.collection.insert_many(data)
|
||||||
|
|
||||||
|
def exists(self, condition):
|
||||||
|
return self.collection.count_documents(condition, limit = 1) != 0
|
||||||
|
Reference in New Issue
Block a user