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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env ruby
require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "ferrum"
gem "pry"
gem "typeprof"
end
require "csv"
require "date"
csv = CSV.new(File.new("goodreads_library_export.csv"), headers: true)
read_books = csv
.select { _1["Date Read"] }
.to_h {|row|
[row.fetch("Title"), Date.strptime(row.fetch("Date Read"), "%Y/%m/%d")]
}
storygraph_username = ENV.fetch("STORYGRAPH_USERNAME")
storygraph_password = ENV.fetch("STORYGRAPH_PASSWORD")
browser = Ferrum::Browser.new(headless: false)
browser.go_to("https://app.thestorygraph.com/users/sign_in")
input = browser.at_xpath("//input[@id='user_email']")
input.focus.type(storygraph_username)
input = browser.at_xpath("//input[@id='user_password']")
input.focus.type(storygraph_password, :Enter)
browser.network.wait_for_idle
browser.go_to("https://app.thestorygraph.com/books-read/b60a9490-d353-4aa1-8323-7464df846a25?year=no-date")
book_ids = browser.xpath("//span/div[@data-book-id]").map { _1.attribute("data-book-id") }
book_ids.each do |book_id|
browser.go_to("https://app.thestorygraph.com/books/#{book_id}")
title = browser.at_css("div.book-title-author-and-series h3").text.strip
gr_book = read_books[title]
# isbns = browser.css("div.edition-info").map { _1.text[/ISBN\/UID:\s*(\d+)/, 1] }
binding.pry
exit
next unless date_read
browser.go_to("https://app.thestorygraph.com/read_instances/new?book_id=#{book_id}")
end
# authors = csv
# .select {|row| row.fetch("My Rating").to_i >= 4 }
# .group_by {|row| row.fetch("Author") }
# .keys
# authors = ARGF.read.split("\n")
# require "capybara"
# Capybara.default_driver = :selenium
# require "selenium/webdriver"
# Selenium::WebDriver::Firefox::Binary.path = "/Applications/Firefox\ Developer\ Edition.app/Contents/MacOS/firefox"
# require "capybara/dsl"
# suppress_warnings do
# include Capybara::DSL
# end
# suppress_warnings do
# visit "http://bookfeed.io/"
# end
# click_button "Make my Feed"
# authors.each do |author|
# fill_in "addAuthorField", with: author
# click_button "Add Author"
# end
# puts find_by_id("feedUrl")["value"]