Initial commit
This commit is contained in:
commit
23994791a0
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
venv/*
|
4
README.md
Normal file
4
README.md
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Owncast Chat Logger
|
||||||
|
This code was taken from a blog post: https://mcgillij.dev/getting-owncast-chat-in-obs.html
|
||||||
|
|
||||||
|
I have not found a way to wrap lines in OBS, so this repo is not being used.
|
18
client.py
Normal file
18
client.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import requests
|
||||||
|
import json
|
||||||
|
|
||||||
|
webhook_url = 'http://localhost:5000/webhook'
|
||||||
|
|
||||||
|
data = {'eventData': {'body': 'this is a test. testing 123. testing abc',
|
||||||
|
'id': 'MHLpo7Hng',
|
||||||
|
'rawBody': 'f',
|
||||||
|
'timestamp': '2021-09-20T23:02:54.980066719Z',
|
||||||
|
'user': {'createdAt': '2021-09-20T22:34:33.139297191Z',
|
||||||
|
'displayColor': 22,
|
||||||
|
'displayName': 'mcgillij',
|
||||||
|
'id': 'avyQt7N7R',
|
||||||
|
'previousNames': ['mcgillij']},
|
||||||
|
'visible': True},
|
||||||
|
'type': 'CHAT'}
|
||||||
|
|
||||||
|
r = requests.post(webhook_url, data=json.dumps(data), headers={'Content-Type': 'application/json'})
|
4
requirements.txt
Normal file
4
requirements.txt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
Flask
|
||||||
|
python-dateutil
|
||||||
|
python-dotenv
|
||||||
|
requests
|
34
server.py
Normal file
34
server.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
from datetime import datetime
|
||||||
|
from dateutil import parser
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
from flask import Flask, request, abort
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
CHATLOG_FILE = os.getenv('CHATLOG_FILE', '/tmp/chat.txt')
|
||||||
|
|
||||||
|
@app.route('/webhook', methods=['POST'])
|
||||||
|
def webhook():
|
||||||
|
if request.method == 'POST':
|
||||||
|
message = request.json.get('eventData').get('body')
|
||||||
|
user = request.json.get('eventData').get('user').get('displayName')
|
||||||
|
timestamp = request.json.get('eventData').get('timestamp')
|
||||||
|
formatted = datetime.strftime(parser.isoparse(timestamp), '%H:%M:%S')
|
||||||
|
|
||||||
|
if user and message and timestamp:
|
||||||
|
write_out_chatlog(formatted, user, message)
|
||||||
|
return 'success', 200
|
||||||
|
else:
|
||||||
|
abort(400)
|
||||||
|
|
||||||
|
def write_out_chatlog(timestamp, user, message):
|
||||||
|
with open(CHATLOG_FILE, mode='a') as chatlog:
|
||||||
|
chatlog.write(f"{timestamp} {user}: {message}\n")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app.run(host='0.0.0.0')
|
Loading…
Reference in New Issue
Block a user