Skip to content

Instantly share code, notes, and snippets.

@inertia186
Last active November 12, 2022 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inertia186/398a215668c1fd3e1ae7e7a86ba85e53 to your computer and use it in GitHub Desktop.
Save inertia186/398a215668c1fd3e1ae7e7a86ba85e53 to your computer and use it in GitHub Desktop.
Query Hive Blog
Query the entire blog of an author.

Have you ever wanted to read the entire blog of a particular author? It's actually not that easy with the current tools. You can scroll and scroll, but that's not a very fun experience.

This script allows you to output an index of an author's blog by querying HiveSQL, optionally limited to a year at a time. Then, you can save the output and view the file with a markdown reader or open it in hackmd.


Install Ruby

https://www.ruby-lang.org/en/documentation/installation/

Recommended version: ruby-2.7

Get this code

gem install bundler
git clone https://gist.github.com/398a215668c1fd3e1ae7e7a86ba85e53.git query_blog
cd query_blog
bundle install

Setup HiveSQL

Register here: https://hivesql.io/registration/

Edit authorize_hive_sql.sh and provide your credentials.

source authorize_hive_sql.sh

ruby query_blog.rb inertia

Or you can provide a year to focus on, which is useful for prolific bloggers:

ruby query_blog.rb arcange 2018

You can also redirect the output to a file:

ruby query_blog.rb dan > dan.md
open dan.md

Get in touch!

If you're using Query Blog, I'd love to hear from you. Drop me a line and tell me what you think! I'm @inertia on Hive.

License

I don't believe in intellectual "property". If you do, consider Query Blog as licensed under a Creative Commons CC0 License.

#!/bin/bash
export HIVESQL_HOST=vip.hivesql.io
export HIVESQL_USERNAME=
export HIVESQL_PASSWORD=
source 'https://rubygems.org'
gem 'hive_sql'
GEM
remote: https://rubygems.org/
specs:
activemodel (7.0.2.4)
activesupport (= 7.0.2.4)
activerecord (7.0.2.4)
activemodel (= 7.0.2.4)
activesupport (= 7.0.2.4)
activerecord-sqlserver-adapter (7.0.0.0)
activerecord (~> 7.0.0)
tiny_tds
activesupport (7.0.2.4)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
awesome_print (1.9.2)
concurrent-ruby (1.1.10)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
hive_sql (1.0.3)
activerecord (>= 4)
activerecord-sqlserver-adapter (>= 4)
activesupport (>= 4, < 7.0.3)
awesome_print (~> 1.7, >= 1.7.0)
nokogiri (~> 1.8)
rest-client (~> 2.0)
tiny_tds (~> 2.1)
http-accept (1.7.0)
http-cookie (1.0.5)
domain_name (~> 0.5)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
mime-types (3.4.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2022.0105)
minitest (5.16.3)
netrc (0.11.0)
nokogiri (1.13.9-arm64-darwin)
racc (~> 1.4)
racc (1.6.0)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
tiny_tds (2.1.5)
tzinfo (2.0.5)
concurrent-ruby (~> 1.0)
unf (0.1.4)
unf_ext
unf_ext (0.0.8.2)
PLATFORMS
arm64-darwin-22
DEPENDENCIES
hive_sql
BUNDLED WITH
2.3.16
require 'rubygems'
require 'bundler/setup'
Bundler.require
if ARGV.empty?
puts "Usage: ruby #{__FILE__} <author> [year]"
exit
end
author = ARGV[0]
year = ARGV[1].to_i
posts = HiveSQL::Comment.where(depth: 0, author: author)
posts = posts.select(:id, :created, :title, :parent_permlink, :author, :permlink)
posts = posts.order(id: :asc)
if year != 0
posts = posts.where("created BETWEEN '#{year}-01-01' AND '#{year + 1}-01-01'")
end
puts "### Posts by #{author}: #{posts.count(:id)}\n"
puts "| Date | Post |"
puts "|-----------|------|"
posts.each do |post|
title = post.title || ''
puts "| #{post.created.strftime("%Y/%m/%d") } | [#{title.gsub("\n", '')}](https://hive.blog/#{post.parent_permlink}/@#{post.author}/#{post.permlink}) |"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment