Skip to content

Instantly share code, notes, and snippets.

@whiteleaf7
Last active June 18, 2021 23:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whiteleaf7/bf279ca91a2aaf1e27f52bd35fe27ebb to your computer and use it in GitHub Desktop.
Save whiteleaf7/bf279ca91a2aaf1e27f52bd35fe27ebb to your computer and use it in GitHub Desktop.
database.yaml 復旧プログラム
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)
@whiteleaf7
Copy link
Author

whiteleaf7 commented Sep 21, 2016

使い方

小説管理フォルダに restore.rb をダウンロードし(右上のRawボタンから)、
コマンドプロンプトで

ruby restore.rb > database.yaml

と実行する。database.yaml が出来るので、中身を確認した上で、.narou フォルダにコピーする。

日付関係はだいぶ適当。IDもずれる。そしてタグは復旧出来ない。
IDがずれるとフリーズ情報もずれるので(フリーズはIDで関連付け)、フリーズし直す必要があります。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment