Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fishroom to TUNA Danmaku
#!/usr/bin/env python2
# -*- coding:utf-8 -*-
from __future__ import print_function, division, unicode_literals
import requests
import hashlib
FISHROOM_TOKEN_ID = ""
FISHROOM_TOKEN_KEY = ""
FISHROOM_ADDR = "https://fishroom.tuna.moe/api/messages"
DANMAKU_ADDR = "http://dm.tuna.moe/api/v1/channels/tuna/danmaku"
DANMAKU_TOKEN = ""
DANMAKU_COLORS = (
'blue',
'white',
'red',
'yellow',
'cyan',
'green',
'purple',
'black',
)
while 1:
r = requests.get(
FISHROOM_ADDR,
params={'id': FISHROOM_TOKEN_ID, 'key': FISHROOM_TOKEN_KEY}
)
if r.status_code == 200:
try:
j = r.json()
except:
continue
msgs = j['messages']
for m in msgs:
if not m['room'].startswith("tuna"):
continue
print(m['sender'], m['content'])
cidx = (
int(hashlib.md5(m['sender']).hexdigest()[-8:], 16)
% len(DANMAKU_COLORS)
)
color = DANMAKU_COLORS[cidx]
requests.post(
DANMAKU_ADDR,
headers={
'X-GDANMAKU-TOKEN': DANMAKU_TOKEN
},
json={
'content': m['content'],
'color': color,
}
)
# vim: ts=4 sw=4 sts=4 expandtab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.