Last active
June 18, 2021 23:52
-
-
Save whiteleaf7/bf279ca91a2aaf1e27f52bd35fe27ebb to your computer and use it in GitHub Desktop.
database.yaml 復旧プログラム
This file contains 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
require "yaml" | |
require "ostruct" | |
require "time" | |
require "pp" | |
database = {} | |
def date_string_to_time(date) | |
date.is_a?(Time) ? date : Time.parse(date.sub(/[\((].+?[\))]/, "").tr("年月日時分秒@;", "///::: :")) | |
end | |
def new_arrivals_date(data) | |
new_arrivals = Time.mktime(0) | |
data.subtitles.each do |subtitle| | |
subdate = date_string_to_time subtitle["subdate"] | |
new_arrivals = subdate if subdate > new_arrivals | |
end | |
new_arrivals | |
end | |
def use_subdirectory?(path) | |
path.split("/").length == 5 | |
end | |
Dir.glob("小説データ/*/*/toc.yaml\0小説データ/*/*/*/toc.yaml").each.with_index do |path, id| | |
begin | |
data = OpenStruct.new(YAML.load_file(path)) | |
rescue Psych::SyntaxError => e | |
$stderr.puts "#{path} が壊れています。スキップしました" | |
next | |
end | |
database[id] = { | |
"id" => id, | |
"author" => data.author, | |
"title" => data.title, | |
"file_title" => File.basename(File.dirname(path)), | |
"toc_url" => data.toc_url, | |
"sitename" => path.split("/")[1], | |
# "novel_type" => | |
"use_subdirectory" => use_subdirectory?(path), | |
"last_update" => Time.now, | |
"new_arrivals_date" => new_arrivals_date(data), | |
"general_firstup" => nil, | |
"novelupdated_at" => new_arrivals_date(data), | |
"general_lastup" => new_arrivals_date(data), | |
"last_mail_date" => Time.now, | |
} | |
end | |
puts YAML.dump(database) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
使い方
小説管理フォルダに restore.rb をダウンロードし(右上のRawボタンから)、
コマンドプロンプトで
と実行する。database.yaml が出来るので、中身を確認した上で、.narou フォルダにコピーする。
日付関係はだいぶ適当。IDもずれる。そしてタグは復旧出来ない。
IDがずれるとフリーズ情報もずれるので(フリーズはIDで関連付け)、フリーズし直す必要があります。