Skip to content

Commit

Permalink
Begin downloading pinboard data and storing it locally
Browse files Browse the repository at this point in the history
  • Loading branch information
danott committed Jan 15, 2024
1 parent 560ba65 commit 0a9ec65
Show file tree
Hide file tree
Showing 5 changed files with 2,201 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ task :serve do
server.start
end

desc "Download bookmarks from pinboard"
task :download_pinboard_bookmarks do
PinboardBookmark.download
end

desc "Start an Irb console"
task :irb do
binding.irb
end

desc "Temporary task to convert old posts"
task :convert_old_posts do
old_posts =
Expand Down
1 change: 1 addition & 0 deletions autoload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

require "active_support"
require "active_support/core_ext"
require "net/http"

loader = Zeitwerk::Loader.new
loader.push_dir("lib")
Expand Down
5 changes: 4 additions & 1 deletion lib/data_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ def initialize(path)
end

def data
YAML.safe_load(File.read(path), permitted_classes: [Date])
YAML.safe_load(
File.read(path),
permitted_classes: [Date, PinboardBookmark, Symbol]
)
end

def name
Expand Down
28 changes: 28 additions & 0 deletions lib/pinboard_bookmark.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
PinboardBookmark =
Struct.new(:href, :title, :commentary, :date, :tags, keyword_init: true) do
PATH = "site/_pinboard_bookmarks.yml".freeze

def self.pull
auth_token = ENV["DANOTT_DOT_WEBSITE_PINBOARD_AUTH_TOKEN"]
uri =
URI(
"https://api.pinboard.in/v1/posts/all?tag=danott.website&format=json&auth_token=#{auth_token}"
)
JSON
.load(Net::HTTP.get(uri))
.map do |record|
tags = record.fetch("tags").split(" ") - ["danott.website"]
new(
href: record.fetch("href").strip,
title: record.fetch("description").strip,
commentary: record.fetch("extended").strip,
date: Date.parse(record.fetch("time")),
tags: tags.compact.uniq
)
end
end

def self.download
File.write(PATH, YAML.dump(pull))
end
end

0 comments on commit 0a9ec65

Please sign in to comment.