dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

commit 5d77aa35e324d22b88bca28d9cb95f9cb070c991
parent 4301f876ad3c47d73fed72b8871e8d65bf7ed9d0
Author: Alex Balgavy <a.balgavy@gmail.com>
Date:   Wed,  7 Oct 2020 21:21:18 +0200

hpanot: moved to separate repo, added to Homebrew tap

Former-commit-id: 225411d371ae2d39e1cac9db0674b5168f381ab1
Diffstat:
M.gitmodules | 3+++
Dscripts/hypothesis-annotations | 85-------------------------------------------------------------------------------
Atools/hpanot | 1+
3 files changed, 4 insertions(+), 85 deletions(-)

diff --git a/.gitmodules b/.gitmodules @@ -31,3 +31,6 @@ [submodule "tools/sc-im"] path = tools/sc-im url = https://github.com/andmarti1424/sc-im.git +[submodule "tools/hpanot"] + path = tools/hpanot + url = git@git.alex.balgavy.eu:hpanot.git diff --git a/scripts/hypothesis-annotations b/scripts/hypothesis-annotations @@ -1,85 +0,0 @@ -#!/usr/bin/env ruby -require 'open-uri' -require 'json' -class Hypothesis - class Annotation - attr_reader :title, :uri - def initialize(text,comment,title,uri) - @text = text - @comment = comment - @title = title - @uri = uri - end - - def to_markdown - str = @text.split("\n").reduce("") { |acc, line| acc += "> #{line}\n" } - str += "\n" - str += "#{@comment}\n" if @comment - str - end - - def to_markdown_title_url - "[#{@title}](#{@uri})\n" - end - end - def initialize - ['HYPOTHESIS_API_KEY', 'HYPOTHESIS_USERNAME'].each do |var| - if ENV[var].nil? - warn "Please set the #{var} environment variable." - exit 1 - end - end - - @apikey = ENV['HYPOTHESIS_API_KEY'] - @username = ENV['HYPOTHESIS_USERNAME'] - @headers = {'Host' => 'hypothes.is', 'Accept' => 'application/json', 'Authorization' => "Bearer #{@apikey}"} - @baseurl = "https://hypothes.is/api" - - begin - URI.open("#{@baseurl}/", @headers) - rescue - warn "Could not access the API #{@baseurl}" - exit 1 - end - end - - def request(endpoint) - begin - URI.open(@baseurl+endpoint, @headers) do |response| - JSON.parse(response.read)['rows'] - end - rescue - warn "Error getting data from #{endpoint}" - [] - end - end - - def annotations(uri_search_str) - data = request "/search?user=acct:#{@username}@hypothes.is&#{uri_search_str}&limit=200&order=asc" - data.reduce([]) do |arr, annot| - arr << Annotation.new(annot['target'].first['selector'].select {|f| f['type'] == 'TextQuoteSelector'}.first['exact'], - annot['text'].empty? ? nil : annot['text'], - annot['document']['title'].first, - annot['uri']) - end - - end - - def search_host(host) - annotations "wildcard_uri=http://#{host}/*" - end - - def search_uri(uri) - annotations "uri=#{uri}" - end -end - -if ARGV.empty? - puts "Argument required: URL or host" - exit 1 -end - -h = Hypothesis.new -site = ARGV.first -annotations = (site.start_with? "http") ? h.search_uri(site) : h.search_host(site) -puts annotations.first.to_markdown_title_url+"\n"+annotations.reduce("") { |str, annot| str += annot.to_markdown } diff --git a/tools/hpanot b/tools/hpanot @@ -0,0 +1 @@ +Subproject commit c31c8afd06151806edb874d1a25bc61274dd2c48