A library for scraping Bookmeter.
Japanese README is here.
Add this line to your application's Gemfile:
gem 'bookmeter_scraper'
And then execute:
$ bundle
Or install it yourself as:
$ gem install bookmeter_scraper
Add this line to your code before using this library:
require 'bookmeter_scraper'
You need to log in Bookmeter to get books and followings / followers information by Bookmeter.log_in
or Bookmeter#log_in
.
There are 3 ways to input authentication information:
- Passing as arguments
- Writing out to
config.yml
- Configuring in a block
You can log in Bookmeter by passing mail address and password to Bookmeter.log_in
:
bookmeter = BookmeterScraper::Bookmeter.log_in('example@example.com', 'your_password')
bookmeter.logged_in? # true
Bookmeter#log_in
is also available:
bookmeter = BookmeterScraper::Bookmeter.new
bookmeter.log_in('example@example.com', 'password')
Create config.yml
as followings and save it to the same directory as your Ruby script:
mail: example@example.com
password: your_password
Now you can log in Bookmeter by calling Bookmeter.log_in
or Bookmeter#log_in
with no arguments:
bookmeter = BookmeterScraper::Bookmeter.log_in
bookmeter.logged_in? # true
You can configure mail address and password in a block.
bookmeter = BookmeterScraper::Bookmeter.log_in do |configuration|
configuration.mail = 'example@example.com'
configuration.password = 'password'
end
bookmeter.logged_in? # true
Bookmeter#log_in
is also available:
bookmeter = BookmeterScraper::Bookmeter.new
bookmeter.log_in do |configuration|
configuration.mail = 'example@example.com'
configuration.password = 'password'
end
You can get books information:
- read books
- reading books
- tsundoku (stockpile)
- wish list
You need to log in Bookmeter in advance to get these information.
You can get read books information by Bookmeter#read_books
:
books = bookmeter.read_books # get read books of the logged in user
bookmeter.read_books('01010101') # get read books of a user specified by ID
Books infomation is an array of Book
which has these attributes:
name
read_dates
uri
image_uri
read_dates
is an array of finished reading dates (first finished date and reread dates):
books[0].name
books[0].read_dates
books[0].uri
books[0].image_uri
To specify year-month for read books, you can use Bookmeter#read_books_in
:
books = bookmeter.read_books_in(2016, 1) # get read books of the logged in user in 2016-01
books = bookmeter.read_books_in(2016, 1, '01010101') # get read books of a user in 2016-01
You can get other books information:
Bookmeter#reading_books
Bookmeter#tsundoku
Bookmeter#wish_list
books = bookmeter.reading_books
books[0].name
books[0].read_dates # this array is empty
bookmeter.tsundoku
bookmeter.wish_list
You can get following users (followings) and followers information by Bookmeter#followings
and Bookmeter#followers
:
following_users = bookmeter.followings
followers = bookmeter.followers
You need to log in Bookmeter in advance to get these information.
Users information is an array of Struct
which has following attributes:
name
id
uri
following_users[0].name
following_users[0].id
following_users[0].uri
followers[0].name
followers[0].id
followers[0].uri
Bookmeter#followings
and Bookmeter#followers
have not supported paginated followings / followers pages yet.
You can get a user profile by Bookmeter#profile
:
bookmeter = BookmeterScraper::Bookmeter.new
user_id = '000000'
profile = bookmeter.profile(user_id) # You can specify arbitrary user ID
You do not need to log in to get user profiles.
Profile information is Struct
which has these attributes:
profile.name
profile.gender
profile.age
profile.blood_type
profile.job
profile.address
profile.url
profile.description
profile.first_day
profile.elapsed_days
profile.read_books_count
profile.read_pages_count
profile.reviews_count
profile.bookshelfs_count
Bug reports and pull requests are welcome on GitHub at https://github.com/kymmt90/bookmeter_scraper.
The gem is available as open source under the terms of the MIT License.