Commit fa2343a2 authored by 神楽坂玲奈's avatar 神楽坂玲奈

announcements

parent e0b8d20a
......@@ -2,7 +2,7 @@
require "fileutils"
require_relative 'card'
module Update
Version = '0.9.3'
Version = '0.9.4'
URL = "http://my-card.in/mycard/update.json?version=#{Version}"
class <<self
attr_reader :thumbnails, :images, :status
......@@ -129,39 +129,44 @@ module Update
require 'net/http/pipeline'
@thumbnails_left = @thumbnails.size
@images_left = @images.size
threads = 1.times.collect do
threads = 5.times.collect do
thread = Thread.new do
Net::HTTP.start uri.host, uri.port do |http|
http.pipelining = true
while !@thumbnails.empty?
ids = @thumbnails.pop(100)
reqs = ids.reverse.collect { |id| Net::HTTP::Get.new image_req.gsub(':id', id.to_s) }
http.pipeline reqs do |res|
@status.replace "正在下载缩略卡图 (剩余#{@thumbnails_left}张)"
@thumbnails_left -= 1
id = ids.pop
next if File.file? "ygocore/pics/thumbnail/#{id}.jpg"
content = res.body
open("ygocore/pics/thumbnail/#{id}.jpg", 'wb') do |local|
local.write content
begin
list = @thumbnails
ids = []
while !@thumbnails.empty?
ids.replace @thumbnails.pop(100)
reqs = ids.reverse.collect { |id| Net::HTTP::Get.new image_req.gsub(':id', id.to_s) }
http.pipeline reqs do |res|
@status.replace "正在下载缩略卡图 (剩余#{@thumbnails_left}张)"
@thumbnails_left -= 1
id = ids.pop
next if File.file? "ygocore/pics/thumbnail/#{id}.jpg"
content = res.body
open("ygocore/pics/thumbnail/#{id}.jpg", 'wb') {|local|local.write content}
end
end rescue $log.error('下载缩略卡图') { [$!.inspect, *$!.backtrace].collect { |str| str.force_encoding("UTF-8") }.join("\n") }
end
while !@images_reqs.empty?
ids = @images_reqs.pop(100)
reqs = ids.reverse.collect { |id| Net::HTTP::Get.new thumbnail_req.gsub(':id', id.to_s) }
http.pipeline reqs do |res|
@status.replace "正在下载完整卡图 (剩余#{@images_left}张)"
@images_left -= 1
id = ids.pop
next if File.file? "ygocore/pics/#{id}.jpg"
content = res.body
open("ygocore/pics/#{id}.jpg", 'wb') do |local|
local.write content
end
list = @images_reqs
ids = []
while !@images_reqs.empty?
ids.replace @images_reqs.pop(100)
reqs = ids.reverse.collect { |id| Net::HTTP::Get.new thumbnail_req.gsub(':id', id.to_s) }
http.pipeline reqs do |res|
@status.replace "正在下载完整卡图 (剩余#{@images_left}张)"
@images_left -= 1
id = ids.pop
next if File.file? "ygocore/pics/#{id}.jpg"
content = res.body
open("ygocore/pics/#{id}.jpg", 'wb') {|local|local.write content}
end
end rescue $log.error('下载完整卡图') { [$!.inspect, *$!.backtrace].collect { |str| str.force_encoding("UTF-8") }.join("\n") }
end
rescue
$log.error('卡图下载') { [$!.inspect, *$!.backtrace].collect { |str| str.force_encoding("UTF-8") }.join("\n") }
list.concat ids
end
end rescue $log.error('下载完整卡图出错') { [$!.inspect, *$!.backtrace].collect { |str| str.force_encoding("UTF-8") }.join("\n") }
end
end
thread.priority = -1
thread
......
......@@ -18,14 +18,14 @@ class Window_Announcements < Window
if @transforming and @last_item
@font.style = TTF::STYLE_NORMAL
@font.draw_blended_utf8(@contents, @last_item.title, 0, -@transforming, *@color)
@time_font.draw_blended_utf8(@contents, @last_item.time.strftime('%Y-%m-%d'), 300, -@transforming+4, *@time_color) if @last_item.time
@time_font.draw_blended_utf8(@contents, @last_item.time.strftime('%Y-%m-%d'), 500, -@transforming+4, *@time_color) if @last_item.time
@font.style = TTF::STYLE_UNDERLINE if @focus
@font.draw_blended_utf8(@contents, @item.title, 0, -@transforming+24, *@color)
@time_font.draw_blended_utf8(@contents, @item.time.strftime('%Y-%m-%d'), 300, -@transforming+24+4, *@time_color) if @item.time
@time_font.draw_blended_utf8(@contents, @item.time.strftime('%Y-%m-%d'), 500, -@transforming+24+4, *@time_color) if @item.time
else
@font.style = @focus ? TTF::STYLE_UNDERLINE : TTF::STYLE_NORMAL
@font.draw_blended_utf8(@contents, @item.title, 0, 0, *@color)
@time_font.draw_blended_utf8(@contents, @item.time.strftime('%Y-%m-%d'), 300, 4, *@time_color) if @item.time
@time_font.draw_blended_utf8(@contents, @item.time.strftime('%Y-%m-%d'), 500, 4, *@time_color) if @item.time
end
end
def update
......
......@@ -5,6 +5,8 @@ require 'em-http'
require 'websocket'
require 'open-uri'
require 'yaml'
require 'json'
require 'date'
class Ygocore < Game
attr_reader :username
attr_accessor :password
......@@ -357,21 +359,18 @@ class Ygocore < Game
#公告
$config['ygocore'] ||= {}
$config['ygocore']['announcements'] ||= [Announcement.new("开放注册", nil, nil)]
#Thread.new do
# begin
# open(@@config['api']) do |file|
# file.set_encoding "GBK"
# announcements = []
# file.read.encode("UTF-8").scan(/<div style="color:red" >公告:(.*?)<\/div>/).each do |title, others|
# announcements << Announcement.new(title, @@config['index'], nil)
# end
# $config['ygocore']['announcements'].replace announcements
# Config.save
# end
# rescue Exception => exception
# $log.error('公告读取失败') { [exception.inspect, *exception.backtrace].collect { |str| str.encode("UTF-8") }.join("\n") }
# end
#end
Thread.new do
begin
open('http://my-card.in/announcements.json') do |file|
$config['ygocore']['announcements'].replace JSON.parse(file.read).collect { |announcement|
Announcement.new(announcement['title'], announcement['url'], Date.parse(announcement['created_at']))
}
Config.save
end
rescue Exception => exception
$log.error('公告读取失败') { [exception.inspect, *exception.backtrace].collect { |str| str.encode("UTF-8") }.join("\n") }
end
end
end
#module Client
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment