-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_sherlock.rb
62 lines (58 loc) · 2.26 KB
/
add_sherlock.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
require './local_sequel'
require 'yaml'
username = "Arthur Conan Doyle"
dataset= DB[:users].where(:user => username)
dataset.delete
DB[:users].insert( :user => username,
:pass => "666",
:email => "emailofadeadman",
:emailver => "wq23iujt4erofd9wu3rj4k5rotf09ifer43erfd09iknr",
:veri => false) if dataset.empty?
userid = dataset.all[0][:id]
name = "The Adventures of Sherlock Holmes"
authors_note = ""
chaps = YAML::load(File.read('sherlock.yaml'))
chapsarr = makearray
nameid = DB[:names].insert(:auth => userid, :name => name, :fin => true)
bookid = DB[:books].insert(:auth => userid,
:chaps => chapsarr,
:endvotes => makearray,
:noendvotes => makearray,
:pparas => makearray,
:fin => true,
:pnames => makearray,
:name => nameid)
chapids = []
chaps.each do |key,val|
paraid = DB[:paras].insert(:auth => userid,:an =>"",:text => val.join("\n").gsub("\n\n","\r").gsub("\n"," ").gsub("\r","\n\n"),:upvotes => makearray, :downvotes => makearray)
paraarray = makearray
getarray(paraarray).insert(:val => paraid)
chapids << {:val => DB[:chaps].insert(:paras => paraarray, :name => key)}
end
getarray(DB[:books].where(:id => bookid).select(:chaps).all[0][:chaps]).multi_insert(chapids)
puts "all done!"
=begin
ts = Time.now
DB[:books].insert(:userid => userid, :timestamp => ts)
bookid = DB[:books].where(:userid => userid, :timestamp => ts).all[0][:id]
book = DB[:books].where(:id => bookid)
chaps.each do |name, paras|
firstpara = paras.shift
DB[:paras].insert(:bookid => bookid,
:userid => userid,
:an => authors_note,
:text => firstpara,
:chapname => name,
:newchap => true)
paras.each do |text|
DB[:paras].insert(:bookid => bookid,:userid => userid,:an => authors_note,:text => text, :chapname => name)
end
end
raw_paras = DB[:paras].where(:bookid => bookid).all
paraids = []
raw_paras.each do |row_hash|
paraids << row_hash[:id]
end
DB[:books].where(:id => bookid).update(:paras => paraids.join(','))
puts 'done!'
=end