qiita-takeout 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a4d8db5ad33b321c4d0a9ef64111afd713bf75b6
4
- data.tar.gz: f79203b2ecd31fa85f2384c02063a04f9827a0c5
3
+ metadata.gz: 21620b952c4d8d88591eeb47dbe9d3da0044fcbc
4
+ data.tar.gz: 395ec4151e5d662e615c6a59a67839611674d9ff
5
5
  SHA512:
6
- metadata.gz: aea071bd9b0cf447036bf23dc8320db95f370e0434e86d5b896589daf939ef82f45da664f5c2e577012e50c023915c90e4724ce6774f4d4596b27e7a8d07db05
7
- data.tar.gz: ffb63d1a646dedf35c3c35bb827e5a34f80c88cbeff897b468afb9fafd6cab783f79592adc7d3f00350e65a9c1cd985273e38856e26253dd219303a97edd01e5
6
+ metadata.gz: 74d0b051be30e847ec13c4e8b2159e3c8b7eaa1cd9e36f87bd1e96215987d55a0a4df5855cac9653d0c8b62819038b1f11a5e7b22697df14ba2936358ba8b6a9
7
+ data.tar.gz: aa434d53d59ec1d4f5a3ebd24b5e7e02cd1754a36d86a64f1bcfe3a09b0fa7203085d635f595defa4f37bdcebc9104f08a3c0c04b9004352710806e7fa68fa71
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Qiita::Takeout
2
2
 
3
- This gem can take your articles from Qiita to local storage.
3
+ This gem can takes your articles from Qiita to local storage.
4
4
  It's assumed to use for backup.
5
5
 
6
6
  ## Installation
@@ -11,12 +11,18 @@ gem install qiita-takeout
11
11
 
12
12
  ## Usage
13
13
 
14
- ```session
15
- $ qiita-takeout
16
- Commands:
17
- qiita-takeout dump NAME PASSWORD # Dump your articles on Qiita.
18
- qiita-takeout help [COMMAND] # Describe available commands or one specific command
19
- qiita-takeout version # Show version
14
+ ```console
15
+ $ qiita-takeout dump [name] [password]
16
+ Dumped => qiita-takeout-20150125
17
+ $ tree qiita-takeout-20150125
18
+ qiita-takeout-20150125
19
+ ├── articles
20
+ │   ├── 22393
21
+ │   │   ├── 2013-07-07-HomebrewでOSXに音声解析エンジンJuliusを入れる.md
22
+ │   │   └── s1.png
23
+ │   └── 31028
24
+ │      └── 2013-11-02-Qiitaの記事をインクリメンタルサーチするAlfred 2 Workflow.md
25
+ └── articles.json
20
26
  ```
21
27
 
22
28
  ## Contributing
@@ -8,12 +8,17 @@ class Qiita::Takeout::CLI < Thor
8
8
  desc "dump NAME PASSWORD", "Dump your articles on Qiita."
9
9
  def dump(name, password)
10
10
  auth = Qiita::Takeout::Connector.auth name, password
11
+ unless auth
12
+ puts "Error: invalid credentials. Please confirm your inputs are correct."
13
+ exit
14
+ end
11
15
  data = Qiita::Takeout::Connector.get(:items, :token => auth['token'])
12
16
 
13
17
  dest_path = File.join(Qiita::Takeout::OUTPUT_PATH % {:timestamp => Time.now.strftime("%Y%m%d")})
14
- images_dest_path = File.join(dest_path, "images")
18
+ articles_dest_path = File.join(dest_path, "articles")
15
19
 
16
20
  FileUtils.mkdir_p(dest_path) unless File.exist?(dest_path)
21
+ FileUtils.mkdir_p(articles_dest_path) unless File.exist?(articles_dest_path)
17
22
 
18
23
  open(File.join(dest_path, "articles.json"), "w") do |f|
19
24
  f.write data.to_json
@@ -21,17 +26,28 @@ class Qiita::Takeout::CLI < Thor
21
26
 
22
27
  data.each do |article|
23
28
  id = article['id'].to_s
24
- body = Nokogiri::HTML.parse(article['body'])
25
- img_arr = body.css("img[src^='https://qiita-image-store.s3.amazonaws.com']")
29
+ title = article['title']
30
+ created_at = Time.parse(article['created_at'])
31
+
32
+ output_path = File.join(articles_dest_path, id)
33
+ FileUtils.mkdir_p(output_path) unless File.exist?(output_path)
34
+
35
+ # Fetch images
36
+ img_arr = Nokogiri::HTML.parse(article['body']).css("img[src^='https://qiita-image-store.s3.amazonaws.com']")
26
37
  img_arr.each do |img|
27
38
  url = img.attr('src')
28
39
  output = img.attr('alt')
29
- output_path = File.join(images_dest_path, id, output)
30
- FileUtils.mkdir_p(File.dirname(output_path)) unless File.exist?(File.dirname(output_path))
31
- open(output_path, 'wb') do |f|
40
+ open(File.join(output_path, output), 'wb') do |f|
32
41
  f.write open(url, 'rb').read
33
42
  end
34
43
  end
44
+
45
+ # Markdown
46
+ markdown = article['raw_body']
47
+ markdown_filename = "%{timestamp}-%{title}.md" % {:timestamp => created_at.strftime("%Y-%m-%d"), :title => title.gsub(/[\\\/\:\*\?"<>\|]/, "")}
48
+ open(File.join(output_path, markdown_filename), 'w') do |f|
49
+ f.write markdown
50
+ end
35
51
  end
36
52
 
37
53
  puts "Dumped => #{dest_path}"
@@ -1,5 +1,5 @@
1
1
  module Qiita
2
2
  module Takeout
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qiita-takeout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yasuaki Uechi