Skip to content

Instantly share code, notes, and snippets.

@tumugin
Created August 4, 2016 14:44
Show Gist options
  • Save tumugin/1c5ccaa8d03820139ea21ed3090dea50 to your computer and use it in GitHub Desktop.
Save tumugin/1c5ccaa8d03820139ea21ed3090dea50 to your computer and use it in GitHub Desktop.
pixivの罵倒少女のAPIをRubyで叩くやつ
# -*- 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