olivebot/utils/storer.py
xszyou 55fb0896b8 2023.01
Fay2.0:
1、控制器pc内网穿透,音频输入输出设备远程直连;
2、提供android 音频输入输出工程示例代码;
3、提供python音频输入输出工程示例代码(远程PC、树莓派等可用);
4、补传1.0语音指令音乐播放模块(暂不支持远程播放);
5、重构及补充若干工具模块:websocket、多线程、缓冲器、音频流录制器等;
6、修复1.x版本的多个bug。
2023-01-31 12:40:36 +08:00

32 lines
831 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import codecs
import os
from threading import Thread
import time
from core.interact import Interact
FILE_URL = "datas/data-" + time.strftime("%Y%m%d%H%M%S") + ".csv"
def __write_to_file(text):
if not os.path.exists("datas"):
os.mkdir("datas")
file = codecs.open(FILE_URL, 'a', 'utf-8')
file.write(text + "\n")
file.close()
def storage_live_interact(interact: Interact):
interact_type = interact.interact_type
user = interact.data["user"].replace(',', '')
msg = interact.data["msg"].replace(',', '')
msg_type = {
0: '主播',
1: '发言',
2: '进入',
3: '送礼',
4: '关注'
}
timestamp = int(time.time() * 1000)
Thread(target=__write_to_file, args=["%s,%s,%s,%s\n" % (timestamp, msg_type[interact_type], user, msg)]).start()