Skip to content

Instantly share code, notes, and snippets.

@bigeagle
Created February 29, 2016 11:08
Show Gist options
  • Save bigeagle/3a79c5cda8b500d71f69 to your computer and use it in GitHub Desktop.
Save bigeagle/3a79c5cda8b500d71f69 to your computer and use it in GitHub Desktop.
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