Created
August 4, 2016 14:44
-
-
Save tumugin/1c5ccaa8d03820139ea21ed3090dea50 to your computer and use it in GitHub Desktop.
pixivの罵倒少女のAPIをRubyで叩くやつ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
require 'websocket-client-simple' | |
require 'yaml' | |
require 'time' | |
require 'json' | |
# http://www.pixiv.net/special/batoshojo/ の通信内容をChromeとかのDev tool使って解析して、以下の3つのパラメータを探せばおk | |
config = YAML.load_file('./config.yml') | |
UID = config['user']['uid'] | |
TOKEN = config['user']['user_token'] | |
DOMAIN = config['user']['ws_domain'] | |
ws = WebSocket::Client::Simple.connect("ws://#{DOMAIN}/chat/?id=#{UID}&tt=#{TOKEN}") | |
ws.on :message do |msg| | |
print "\n" | |
puts msg.data | |
print ">" | |
end | |
loop do | |
mesg = STDIN.gets.strip | |
sendchar = { | |
:chatMsg => { | |
:displayTime => Date.today.to_time.to_i, | |
:message => mesg, | |
:pending => true, | |
:sender => 'user' | |
} | |
} | |
ws.send(JSON.generate(sendchar)) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment