Skip to content

Instantly share code, notes, and snippets.

@s2t2
Created January 10, 2016 19:30
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 s2t2/ec4d2c0bd1427197d4ca to your computer and use it in GitHub Desktop.
Save s2t2/ec4d2c0bd1427197d4ca to your computer and use it in GitHub Desktop.
repo converter

Repo to Syllabus

Convert repository of many linked markdown files to a single pdf file.

Bonus: Upload to blackboard every day via cron. Does Blackboard have an API?

Usage

Install ruby gem dependencies.

bundle install

Convert.

repo = Repo.new({:org => "gwu-business", :name => "badm-2301"})
repo.convert(:to => "badm-2301-syllabus-20150831.pdf")

Reference:

require 'github_api'
class Repo
attr_accessor(:org, :name)
def initialize(attributes)
@org = attributes[:org]
@name = attributes[:name]
end
# @param [Repo] repository
# @param [Hash] options
# @param [Hash] options [String] to
#def convert(repository, options = {})
def convert(options = {})
# get contents of README.md
# if there are any links from the readme to other markdown files,
# in place of each link:
# get the contents of the linked file;
# insert the contents (except for the file header, denoted by an `#`)
# convert transformed contents to html and save output as .pdf (or maybe .doc)
github = Github.new
dir = github.repos.contents.get(:user => repo.org, :repo => repo.name, :path => '/')
files = dir.map do |f|
github.repos.contents.get(:user => repo.org, :repo => repo.name, :path => f.path.to_s)
end
file_contents = files.map do |f|
Base64.decode64(f.content)
end
file_contents.each do |fc|
puts fc
puts ""
end
end
end
binding.pry
repo = Repo.new({:org => "gwu-business", :name => "badm-2301"})
#syllabus = File.new("#{repo.name}-syllabus-#{Date.today.to_s}.pdf")
#repo.convert(:to => syllabus)
repo.convert(:to => "#{repo.name}-syllabus-#{Date.today.to_s}.pdf")
source 'https://rubygems.org'
gem 'github_api'
gem 'pry' # insert `binding.pry` for debugging
GEM
remote: https://rubygems.org/
specs:
addressable (2.3.8)
coderay (1.1.0)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
faraday (0.9.1)
multipart-post (>= 1.2, < 3)
github_api (0.12.4)
addressable (~> 2.3)
descendants_tracker (~> 0.0.4)
faraday (~> 0.8, < 0.10)
hashie (>= 3.4)
multi_json (>= 1.7.5, < 2.0)
nokogiri (~> 1.6.6)
oauth2
hashie (3.4.2)
jwt (1.5.1)
method_source (0.8.2)
mini_portile (0.6.2)
multi_json (1.11.2)
multi_xml (0.5.5)
multipart-post (2.0.0)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
oauth2 (1.0.0)
faraday (>= 0.8, < 0.10)
jwt (~> 1.0)
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (~> 1.2)
pry (0.10.1)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
rack (1.6.4)
slop (3.6.0)
thread_safe (0.3.5)
PLATFORMS
ruby
DEPENDENCIES
github_api
pry
BUNDLED WITH
1.10.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment