Created
August 20, 2021 17:31
-
-
Save johnholdun/69700b4908d2a7dcfef15a1b6c18a008 to your computer and use it in GitHub Desktop.
Get a list of your updates to literal.club. There's no guarantee this will continue to work over time!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'date' | |
require 'json' | |
require 'net/http' | |
require 'uri' | |
# This should be your username | |
USERNAME = 'johnholdun'.freeze | |
QUERY = <<-QUERY.freeze | |
query getBooks($username: String) { | |
profile(where: { handle: $username }) { | |
readingStates(first: 100, orderBy: { createdAt: desc }) { | |
createdAt | |
status | |
book { | |
title | |
authors { | |
name | |
} | |
} | |
} | |
} | |
} | |
QUERY | |
params = { query: QUERY, variables: { username: USERNAME }, operationName: 'getBooks' } | |
uri = URI.parse('https://literal.club/graphql') | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true | |
request = Net::HTTP::Post.new(uri.request_uri) | |
request.body = params.to_json | |
request['Content-Type'] = 'application/json' | |
response = http.request(request) | |
result = JSON.parse(response.body, symbolize_names: true) | |
events = result.dig(:data, :profile, :readingStates) | |
events.each do |event| | |
status = | |
case event[:status] | |
when 'DROPPED' then 'π ββοΈ' | |
when 'WANTS_TO_READ' then 'π' | |
when 'IS_READING' then 'π' | |
when 'FINISHED' then 'β ' | |
end | |
authors = event[:book][:authors].map { |a| a[:name] }.join(', ') + ',' | |
title = "*#{event[:book][:title]}*." | |
date = Date.parse(event[:createdAt]).iso8601 | |
line = [status, authors, title, date] | |
puts "- #{line.join(' ')}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment