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 +4 -4
- data/README.md +13 -7
- data/lib/qiita/takeout/cli.rb +22 -6
- data/lib/qiita/takeout/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21620b952c4d8d88591eeb47dbe9d3da0044fcbc
|
4
|
+
data.tar.gz: 395ec4151e5d662e615c6a59a67839611674d9ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
```
|
15
|
-
$ qiita-takeout
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
data/lib/qiita/takeout/cli.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
25
|
-
|
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
|
-
|
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}"
|