qiita-takeout 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +28 -0
- data/Rakefile +2 -0
- data/bin/qiita-takeout +11 -0
- data/lib/qiita/takeout/cli.rb +44 -0
- data/lib/qiita/takeout/connector.rb +77 -0
- data/lib/qiita/takeout/version.rb +5 -0
- data/lib/qiita/takeout.rb +10 -0
- data/qiita-takeout.gemspec +26 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a4d8db5ad33b321c4d0a9ef64111afd713bf75b6
|
4
|
+
data.tar.gz: f79203b2ecd31fa85f2384c02063a04f9827a0c5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aea071bd9b0cf447036bf23dc8320db95f370e0434e86d5b896589daf939ef82f45da664f5c2e577012e50c023915c90e4724ce6774f4d4596b27e7a8d07db05
|
7
|
+
data.tar.gz: ffb63d1a646dedf35c3c35bb827e5a34f80c88cbeff897b468afb9fafd6cab783f79592adc7d3f00350e65a9c1cd985273e38856e26253dd219303a97edd01e5
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Yasuaki Uechi
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Qiita::Takeout
|
2
|
+
|
3
|
+
This gem can take your articles from Qiita to local storage.
|
4
|
+
It's assumed to use for backup.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem install qiita-takeout
|
10
|
+
```
|
11
|
+
|
12
|
+
## Usage
|
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
|
20
|
+
```
|
21
|
+
|
22
|
+
## Contributing
|
23
|
+
|
24
|
+
1. Fork it ( https://github.com/uetchy/qiita-takeout/fork )
|
25
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
26
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
27
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
28
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/qiita-takeout
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'json'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'nokogiri'
|
5
|
+
require 'fileutils'
|
6
|
+
|
7
|
+
class Qiita::Takeout::CLI < Thor
|
8
|
+
desc "dump NAME PASSWORD", "Dump your articles on Qiita."
|
9
|
+
def dump(name, password)
|
10
|
+
auth = Qiita::Takeout::Connector.auth name, password
|
11
|
+
data = Qiita::Takeout::Connector.get(:items, :token => auth['token'])
|
12
|
+
|
13
|
+
dest_path = File.join(Qiita::Takeout::OUTPUT_PATH % {:timestamp => Time.now.strftime("%Y%m%d")})
|
14
|
+
images_dest_path = File.join(dest_path, "images")
|
15
|
+
|
16
|
+
FileUtils.mkdir_p(dest_path) unless File.exist?(dest_path)
|
17
|
+
|
18
|
+
open(File.join(dest_path, "articles.json"), "w") do |f|
|
19
|
+
f.write data.to_json
|
20
|
+
end
|
21
|
+
|
22
|
+
data.each do |article|
|
23
|
+
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']")
|
26
|
+
img_arr.each do |img|
|
27
|
+
url = img.attr('src')
|
28
|
+
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|
|
32
|
+
f.write open(url, 'rb').read
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
puts "Dumped => #{dest_path}"
|
38
|
+
end
|
39
|
+
|
40
|
+
desc "version", "Show version"
|
41
|
+
def version
|
42
|
+
puts "qiita-takeout version #{Qiita::Takeout::VERSION}"
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'net/https'
|
4
|
+
require 'uri'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
module Qiita::Takeout
|
8
|
+
class Connector
|
9
|
+
ENDPOINT = "https://qiita.com/api/v1/"
|
10
|
+
|
11
|
+
def self.fetch(uri, params={}, *args)
|
12
|
+
defaults = { method: :get, limit: 10 }
|
13
|
+
opt = args.last.kind_of?(Hash)? defaults.update(args.pop) : defaults
|
14
|
+
raise ArgumentError, 'too many HTTP redirects' if opt[:limit] == 0
|
15
|
+
|
16
|
+
if opt[:method] == :get
|
17
|
+
uri.query = URI.encode_www_form(params) if params
|
18
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
19
|
+
else
|
20
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
21
|
+
request.set_form_data(params)
|
22
|
+
end
|
23
|
+
|
24
|
+
response = Net::HTTP.start(
|
25
|
+
uri.host,
|
26
|
+
uri.port,
|
27
|
+
:use_ssl => (uri.scheme == 'https'),
|
28
|
+
:verify_mode => OpenSSL::SSL::VERIFY_NONE
|
29
|
+
) do |https|
|
30
|
+
https.request(request)
|
31
|
+
end
|
32
|
+
|
33
|
+
case response
|
34
|
+
when Net::HTTPSuccess
|
35
|
+
|
36
|
+
if(response.class.body_permitted?)
|
37
|
+
begin
|
38
|
+
JSON(response.body)
|
39
|
+
rescue JSON::ParserError
|
40
|
+
false
|
41
|
+
end
|
42
|
+
else
|
43
|
+
false
|
44
|
+
end
|
45
|
+
|
46
|
+
when Net::HTTPRedirection
|
47
|
+
location = response['location']
|
48
|
+
fetch(location, limit - 1)
|
49
|
+
when Net::HTTPUnauthorized
|
50
|
+
false
|
51
|
+
else
|
52
|
+
response.value
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.get(path, args={})
|
57
|
+
uri = URI.join(ENDPOINT, path.to_s)
|
58
|
+
fetch uri, args
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.post(path, args={})
|
62
|
+
uri = URI.join(ENDPOINT, path.to_s)
|
63
|
+
fetch uri, args, method: :post
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.auth(name, password)
|
67
|
+
uri = URI.join(ENDPOINT, 'auth')
|
68
|
+
params = {:url_name => name, :password => password}
|
69
|
+
fetch uri, params, method: :post
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.search(query, args={})
|
73
|
+
uri = URI.join(ENDPOINT, 'search')
|
74
|
+
fetch uri, {:q => query}.update(args)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'qiita/takeout/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "qiita-takeout"
|
8
|
+
spec.version = Qiita::Takeout::VERSION
|
9
|
+
spec.authors = ["Yasuaki Uechi"]
|
10
|
+
spec.email = ["uetchy@randompaper.co"]
|
11
|
+
spec.summary = %q{Dump your articles on Qiita.}
|
12
|
+
spec.description = %q{Dump your articles on Qiita.}
|
13
|
+
spec.homepage = "https://github.com/uetchy/qiita-takeout"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "pry-byebug"
|
24
|
+
spec.add_runtime_dependency "thor"
|
25
|
+
spec.add_dependency "nokogiri"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: qiita-takeout
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yasuaki Uechi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry-byebug
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: thor
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: nokogiri
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Dump your articles on Qiita.
|
84
|
+
email:
|
85
|
+
- uetchy@randompaper.co
|
86
|
+
executables:
|
87
|
+
- qiita-takeout
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/qiita-takeout
|
97
|
+
- lib/qiita/takeout.rb
|
98
|
+
- lib/qiita/takeout/cli.rb
|
99
|
+
- lib/qiita/takeout/connector.rb
|
100
|
+
- lib/qiita/takeout/version.rb
|
101
|
+
- qiita-takeout.gemspec
|
102
|
+
homepage: https://github.com/uetchy/qiita-takeout
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.4.5
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: Dump your articles on Qiita.
|
126
|
+
test_files: []
|