Skip to content

Commit bb11a51

Browse files
committed
Update README, add Raketask
1 parent a81e661 commit bb11a51

File tree

6 files changed

+29
-8
lines changed

6 files changed

+29
-8
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ This script allows you to download, not only those books, but all of the books l
44

55
This was based on ruby 2.2.3 but you can change the `.ruby-version` file as there's nothing too exciting in here.
66

7-
You'll need to rename `config.yml.example` to `config.yml` and edit it so that it has your email, password to login to packtpub.com and the path where you want the books to download, which, will need to exist already.
8-
97
Once done install the required gems with bundler.
108

119
```
1210
bundle install
11+
rake bootstrap
12+
```
13+
14+
You'll need to edit `config.yml` so that it has your email, password to login to packtpub.com and the path where you want the books to download, which, will need to exist already.
15+
16+
```
1317
bundle exec ruby download-packt-books.rb
1418
```
1519

Rakefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
require "bundler/setup"
2+
3+
CONFIG_FILES = FileList["config/*.yml.example"].ext("")
4+
5+
desc "Initialize default config files"
6+
task bootstrap: "bootstrap:all"
7+
namespace :bootstrap do
8+
task all: :config
9+
task config: CONFIG_FILES
10+
end
11+
rule ".yml" => ".yml.example" do |task|
12+
cp task.source, task.name
13+
end
14+
15+
require "rake/clean"
16+
CLEAN.include(CONFIG_FILES)

config.yml.example

Lines changed: 0 additions & 3 deletions
This file was deleted.
File renamed without changes.

config/config.yml.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
email: name@domain.com
2+
password: password
3+
downloadpath: /path/to/app/download
4+
booklist: /path/to/app/config/books.yml

download-packt-books.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
require 'yaml'
44

55
# read the config
6-
config = YAML.load(File.read(File.expand_path("config.yml")))
6+
config = YAML.load(File.read(File.expand_path("config/config.yml")))
77

88
# read the tracking file
9-
downloaded_books = YAML::load_file("books.yml")
9+
downloaded_books = YAML::load_file(config["booklist"])
1010

1111
# setup the agent
1212
agent = Mechanize.new
@@ -67,7 +67,7 @@
6767
agent.download(full_link, download_base + file_name)
6868
downloaded_books["list"] << "#{file_name}" unless downloaded_books["list"].include?("#{file_name}")
6969
end
70-
File.open("books.yml", 'w') {|f| f.write downloaded_books.to_yaml }
70+
File.open(config["booklist"], 'w') {|f| f.write downloaded_books.to_yaml }
7171
rescue Mechanize::ResponseReadError => e
7272
e.force_parse
7373
puts " => " + file_name + " retrying"

0 commit comments

Comments
 (0)