From b3a3e36a08f919ff687a9e7e8a3579997b590f4f Mon Sep 17 00:00:00 2001 From: Lorin Werthen Date: Wed, 11 Oct 2017 18:07:13 +0200 Subject: [PATCH] fix #188, add fb import tool --- README.md | 6 +++++- commands/fetch.rb | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 commands/fetch.rb diff --git a/README.md b/README.md index edf4c9d..214bdd1 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,11 @@ For manual deployment, run bundle exec nanoc deploy --target public ``` -## Posts +## Events + +Events can be fetched from facebook using `nanoc fetch [facebook event id]`. A file named `.fb_token` containing an app token for facebook must be present. + +## Blogposts Posts should be written in [kramdown](http://kramdown.gettalong.org/index.html), a markdown superset which has a very complete [syntax guide](http://kramdown.gettalong.org/syntax.html). diff --git a/commands/fetch.rb b/commands/fetch.rb new file mode 100644 index 0000000..b63a3d2 --- /dev/null +++ b/commands/fetch.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require 'net/http' +require 'json' + +usage 'fetch [facebook event id]' +aliases :f +summary 'Fetch an event from facebook' +description 'Fetch an event from facebook' + +run do |_opts, args, _cmd| + fb_token = File.read('.fb_token') + uri = URI("https://graph.facebook.com/v2.10/#{args[0]}?fields=cover,name,description,start_time,place,end_time&access_token=#{fb_token}") + o = JSON.parse(Net::HTTP.get(uri)) + + puts <<~EOS + --- + title: "#{o['name']}" + time: #{o['start_time']} + location: #{o['place']['name']} + end: #{o['end_time']} + banner: #{o['cover']['source']} + --- + + #{o['description']} + EOS +end