Bookmeter Scraper
A library for scraping Bookmeter.
Japanese README is here.
Installation
Add this line to your application's Gemfile:
gem 'bookmeter_scraper'
And then execute:
$ bundle
Or install it yourself as:
$ gem install bookmeter_scraper
Usage
Add this line to your code before using this library:
require 'bookmeter_scraper'
Log in
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
1. Passing as arguments
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')
2. Writing out to config.yml
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
3. Configuring in a block
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
Get books information
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.
Read books
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
Reading books / Tsundoku / Wish list
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
Get followings users / followers information
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
Notice
Bookmeter#followings
and Bookmeter#followers
have not supported paginated followings / followers pages yet.
Get user profile
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
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/kymmt90/bookmeter_scraper.
License
The gem is available as open source under the terms of the MIT License.