qiita_org 0.1.27 → 0.1.32
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 +4 -4
- data/.gitignore +2 -0
- data/Gemfile.lock +1 -1
- data/lib/qiita_org.rb +34 -37
- data/lib/qiita_org/all.rb +24 -5
- data/lib/qiita_org/base.rb +78 -0
- data/lib/qiita_org/config.rb +3 -2
- data/lib/qiita_org/get.rb +6 -43
- data/lib/qiita_org/get_multiple_files.rb +4 -3
- data/lib/qiita_org/get_template.rb +25 -21
- data/lib/qiita_org/list.rb +7 -34
- data/lib/qiita_org/{check_pc_os.rb → old_programs/check_pc_os.rb} +0 -0
- data/lib/qiita_org/{decide_option.rb → old_programs/decide_option.rb} +0 -0
- data/lib/qiita_org/{get_file_path.rb → old_programs/get_file_path.rb} +0 -0
- data/lib/qiita_org/{get_file_url.rb → old_programs/get_file_url.rb} +1 -1
- data/lib/qiita_org/{search_conf_path.rb → old_programs/search_conf_path.rb} +0 -0
- data/lib/qiita_org/{select_path.rb → old_programs/select_path.rb} +0 -0
- data/lib/qiita_org/{set_config.rb → old_programs/set_config.rb} +0 -0
- data/lib/qiita_org/{show_file_and_url.rb → old_programs/show_file_and_url.rb} +2 -1
- data/lib/qiita_org/post.rb +27 -28
- data/lib/qiita_org/upload.rb +107 -8
- data/lib/qiita_org/version.rb +1 -1
- data/tests/test2.org +1 -1
- metadata +11 -11
- data/tests/template.org +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3065c27fab3f91eef0df4ddb3f966fcddb54cebc741450e71977f0fd7f0d5961
|
4
|
+
data.tar.gz: 892613248797cf2f82497e6b355b7fa9e4fc05b48b9fc823d32516f05efbe03c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7005e750de0160ac668c0742c64d380e5898a26c7f0d1f56a4f09b901b52ea933902ea611478685ced7871724e47bbc3704342809f73bb129772bbb483eb1594
|
7
|
+
data.tar.gz: 59ad6b10fcc271bb2e11377963c4d5cde04ec3d7397642a1981eab81f17b5b40f95ebbe6099932f88172dbb953227420fbc7bfca368dad76245cc989c97bb44b
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/lib/qiita_org.rb
CHANGED
@@ -9,12 +9,13 @@ require "qiita_org/get"
|
|
9
9
|
require "qiita_org/list"
|
10
10
|
require "qiita_org/all"
|
11
11
|
require "qiita_org/get_template"
|
12
|
-
require "qiita_org/check_pc_os"
|
12
|
+
#require "qiita_org/check_pc_os"
|
13
13
|
require "qiita_org/upload"
|
14
|
-
require "qiita_org/get_file_path"
|
15
|
-
require "qiita_org/show_file_and_url"
|
16
|
-
require "qiita_org/decide_option"
|
14
|
+
#require "qiita_org/get_file_path"
|
15
|
+
#require "qiita_org/show_file_and_url"
|
16
|
+
#require "qiita_org/decide_option"
|
17
17
|
require "qiita_org/get_multiple_files"
|
18
|
+
require "qiita_org/base"
|
18
19
|
#require "qiita_org/qiita_org_thor"
|
19
20
|
|
20
21
|
module QiitaOrg
|
@@ -25,6 +26,7 @@ module QiitaOrg
|
|
25
26
|
#
|
26
27
|
def initialize(*argv)
|
27
28
|
super(*argv)
|
29
|
+
@base = QiitaBase.new()
|
28
30
|
end
|
29
31
|
|
30
32
|
desc "say_hello", "say_hello"
|
@@ -37,17 +39,21 @@ module QiitaOrg
|
|
37
39
|
desc "post [FILE] [private/public/teams]", "post to qiita from org"
|
38
40
|
|
39
41
|
def post(*argv)
|
40
|
-
checkos = CheckPcOs.new
|
41
|
-
os = checkos.return_os()
|
42
|
+
#checkos = CheckPcOs.new
|
43
|
+
#os = checkos.return_os()
|
44
|
+
os = @base.check_pc_os()
|
42
45
|
|
43
46
|
if argv.size > 2
|
44
47
|
GetMultipleFiles.new(argv, os, "post").run()
|
45
|
-
elsif argv
|
46
|
-
|
48
|
+
elsif argv.size > 1
|
49
|
+
if argv[-1].match(/(.+).org/)
|
50
|
+
GetMultipleFiles.new(argv, os, "post").run()
|
51
|
+
end
|
47
52
|
else
|
48
53
|
p ["in qiita_org.rb", argv]
|
49
54
|
p file = argv[0] || "README.org"
|
50
|
-
p mode = argv[1] || DecideOption.new(file).decide_option()
|
55
|
+
#p mode = argv[1] || DecideOption.new(file).decide_option()
|
56
|
+
p mode = argv[1] || @base.pick_up_option(file)
|
51
57
|
qiita = QiitaPost.new(file, mode, os)
|
52
58
|
begin
|
53
59
|
qiita.select_option(mode)
|
@@ -62,35 +68,23 @@ module QiitaOrg
|
|
62
68
|
desc "upload [FILE] [teams/public/private]", "upload about image to qiita"
|
63
69
|
|
64
70
|
def upload(*argv)
|
65
|
-
checkos = CheckPcOs.new
|
66
|
-
os = checkos.return_os()
|
71
|
+
#checkos = CheckPcOs.new
|
72
|
+
#os = checkos.return_os()
|
73
|
+
os = @base.check_pc_os()
|
67
74
|
|
68
75
|
if argv.size > 2
|
69
76
|
GetMultipleFiles.new(argv, os, "upload").run()
|
70
|
-
elsif argv
|
71
|
-
|
77
|
+
elsif argv.size > 1
|
78
|
+
if argv[-1].match(/(.+).org/)
|
79
|
+
GetMultipleFiles.new(argv, os, "upload").run()
|
80
|
+
end
|
72
81
|
else
|
73
82
|
p file = argv[0] || "README.org"
|
74
|
-
p mode = argv[1] || DecideOption.new(file).decide_option()
|
83
|
+
#p mode = argv[1] || DecideOption.new(file).decide_option()
|
84
|
+
p mode = argv[1] || @base.pick_up_option(file)
|
75
85
|
|
76
|
-
qiita =
|
77
|
-
end
|
78
|
-
=begin
|
79
|
-
getpath = GetFilePath.new(file)
|
80
|
-
paths = getpath.get_file_path()
|
81
|
-
unless paths.empty?
|
82
|
-
showfile = ShowFile.new(paths, file, mode, os)
|
83
|
-
showfile.open_file_dir()
|
84
|
-
showfile.open_qiita()
|
85
|
-
|
86
|
-
puts "Input file URL's on #{file}? (y/n)".green
|
87
|
-
ans = STDIN.getch
|
88
|
-
|
89
|
-
if ans == "y"
|
90
|
-
showfile.input_url_to_org()
|
91
|
-
end
|
86
|
+
qiita = QiitaFileUpLoad.new(file, mode, os).upload()
|
92
87
|
end
|
93
|
-
=end
|
94
88
|
end
|
95
89
|
|
96
90
|
desc "config [global/local] [option] [input]", "set config"
|
@@ -115,17 +109,20 @@ module QiitaOrg
|
|
115
109
|
desc "template", "make template.org"
|
116
110
|
|
117
111
|
def template(*argv)
|
118
|
-
checkos = CheckPcOs.new
|
119
|
-
os = checkos.return_os()
|
112
|
+
#checkos = CheckPcOs.new
|
113
|
+
#os = checkos.return_os()
|
114
|
+
os = @base.check_pc_os()
|
115
|
+
filename = argv[0] || "template.org"
|
116
|
+
filename = (filename.include?(".org"))? filename : "#{filename}.org"
|
120
117
|
|
121
|
-
template = QiitaGetTemplate.new(os).run()
|
118
|
+
template = QiitaGetTemplate.new(os, filename).run()
|
122
119
|
end
|
123
120
|
|
124
|
-
desc "all", "post all org files in the directory"
|
121
|
+
desc "all [teams/public/private] [options]", "post all org files in the directory"
|
125
122
|
|
126
123
|
def all(*argv)
|
127
|
-
mode = argv[0] || false
|
128
|
-
|
124
|
+
#mode = argv[0] || false
|
125
|
+
QiitaAll.new(argv).run()
|
129
126
|
end
|
130
127
|
|
131
128
|
desc "list [qiita/teams]", "view qiita report list"
|
data/lib/qiita_org/all.rb
CHANGED
@@ -1,16 +1,19 @@
|
|
1
1
|
require "colorize"
|
2
2
|
|
3
|
-
class
|
4
|
-
def initialize(
|
5
|
-
@mode = mode
|
3
|
+
class QiitaAll
|
4
|
+
def initialize(argv)
|
5
|
+
# @mode = mode
|
6
|
+
check_options(argv)
|
6
7
|
@files = Dir.glob("*.org")
|
7
8
|
p @files
|
8
9
|
end
|
9
10
|
|
10
11
|
def run()
|
11
12
|
@files.each do |file|
|
12
|
-
|
13
|
-
|
13
|
+
unless @exclude_files.empty?
|
14
|
+
if @exclude_files.include?(file)
|
15
|
+
next
|
16
|
+
end
|
14
17
|
end
|
15
18
|
|
16
19
|
unless @mode
|
@@ -28,4 +31,20 @@ class All
|
|
28
31
|
end
|
29
32
|
end
|
30
33
|
end
|
34
|
+
|
35
|
+
def check_options(string)
|
36
|
+
["teams", "private", "public"].each do |i|
|
37
|
+
if string.include?(i)
|
38
|
+
@mode = i
|
39
|
+
break
|
40
|
+
else
|
41
|
+
@mode = false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
@exclude_files = []
|
46
|
+
if string.include?("--exclude")
|
47
|
+
@exclude_files = string.grep(/.org/)
|
48
|
+
end
|
49
|
+
end
|
31
50
|
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require "colorize"
|
2
|
+
require "qiita_org/error_message.rb"
|
3
|
+
|
4
|
+
class QiitaBase
|
5
|
+
def initialize()
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
def check_pc_os()
|
10
|
+
if system "sw_vers"
|
11
|
+
return os = "mac"
|
12
|
+
elsif system "wmic.exe os get caption"
|
13
|
+
return os = "windows"
|
14
|
+
else
|
15
|
+
return nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def pick_up_option(src)
|
20
|
+
lines = File.readlines(src)
|
21
|
+
|
22
|
+
lines.each do |line|
|
23
|
+
m = []
|
24
|
+
if m = line.match(/\#\+qiita_(.+): (.+)/)
|
25
|
+
option = m[1]
|
26
|
+
unless option == "public" || option == "teams" || option == "private"
|
27
|
+
next
|
28
|
+
end
|
29
|
+
return option
|
30
|
+
end
|
31
|
+
end
|
32
|
+
return option = "private"
|
33
|
+
end
|
34
|
+
|
35
|
+
def search_conf_path(dir, home)
|
36
|
+
while dir != home
|
37
|
+
if File.exists?(File.join(dir, ".qiita.conf"))
|
38
|
+
return dir
|
39
|
+
else
|
40
|
+
dir = dir.match(/(.+)\//)[1]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
return dir
|
44
|
+
end
|
45
|
+
|
46
|
+
def select_access_path(mode, teams_url)
|
47
|
+
case mode
|
48
|
+
when "teams"
|
49
|
+
qiita = teams_url
|
50
|
+
path = "api/v2/items?page=1&per_page=100"
|
51
|
+
else
|
52
|
+
qiita = "https://qiita.com/"
|
53
|
+
path = "api/v2/authenticated_user/items?page=1&per_page=100"
|
54
|
+
end
|
55
|
+
return qiita, path
|
56
|
+
end
|
57
|
+
|
58
|
+
def set_config()
|
59
|
+
conf_dir = search_conf_path(Dir.pwd, Dir.home)
|
60
|
+
lib = File.expand_path("../../../lib", __FILE__)
|
61
|
+
if conf_dir != Dir.home
|
62
|
+
puts "config file path: #{conf_dir.gsub(Dir.home, "~")}".green
|
63
|
+
else
|
64
|
+
puts "config file path: #{conf_dir}".green
|
65
|
+
end
|
66
|
+
|
67
|
+
conf_path = File.join(conf_dir, ".qiita.conf")
|
68
|
+
conf = JSON.load(File.read(conf_path))
|
69
|
+
access_token = conf["access_token"]
|
70
|
+
teams_url = conf["teams_url"]
|
71
|
+
display = conf["display"]
|
72
|
+
ox_qmd_load_path = File.join(lib, "qiita_org", "ox-qmd", "ox-qmd")
|
73
|
+
|
74
|
+
ErrorMessage.new().access_token_error(access_token)
|
75
|
+
|
76
|
+
return access_token, teams_url, display, ox_qmd_load_path
|
77
|
+
end
|
78
|
+
end
|
data/lib/qiita_org/config.rb
CHANGED
@@ -7,8 +7,9 @@ class QiitaConfig
|
|
7
7
|
@option = option
|
8
8
|
@input = input
|
9
9
|
if status == "local"
|
10
|
-
search = SearchConfPath.new(Dir.pwd, Dir.home)
|
11
|
-
conf_dir = search.search_conf_path()
|
10
|
+
#search = SearchConfPath.new(Dir.pwd, Dir.home)
|
11
|
+
#conf_dir = search.search_conf_path()
|
12
|
+
conf_dir = QiitaBase.new().search_conf_path(Dir.pwd, Dir.home)
|
12
13
|
if @option == "set"
|
13
14
|
@setup = File.join(Dir.pwd, ".qiita.conf")
|
14
15
|
else
|
data/lib/qiita_org/get.rb
CHANGED
@@ -3,8 +3,8 @@ require "json"
|
|
3
3
|
require "open-uri"
|
4
4
|
require "io/console"
|
5
5
|
require "colorize"
|
6
|
-
require "qiita_org/select_path.rb"
|
7
|
-
require "qiita_org/set_config.rb"
|
6
|
+
#require "qiita_org/select_path.rb"
|
7
|
+
#require "qiita_org/set_config.rb"
|
8
8
|
require "qiita_org/error_message.rb"
|
9
9
|
require "qiita_org/access_qiita.rb"
|
10
10
|
|
@@ -12,47 +12,10 @@ class QiitaGet
|
|
12
12
|
def initialize(mode, id)
|
13
13
|
@mode = mode
|
14
14
|
@get_id = id
|
15
|
-
@
|
15
|
+
@base = QiitaBase.new()
|
16
|
+
# @selectpath = SelectPath.new()
|
16
17
|
end
|
17
18
|
|
18
|
-
# select path
|
19
|
-
=begin
|
20
|
-
def select_path(mode)
|
21
|
-
case mode
|
22
|
-
when "teams"
|
23
|
-
qiita = @teams_url
|
24
|
-
path = "api/v2/items?page=1&per_page=100"
|
25
|
-
else
|
26
|
-
qiita = "https://qiita.com/"
|
27
|
-
path = "api/v2/authenticated_user/items?page=1&per_page=100"
|
28
|
-
end
|
29
|
-
return qiita, path
|
30
|
-
end
|
31
|
-
=end
|
32
|
-
|
33
|
-
# access qiita
|
34
|
-
=begin
|
35
|
-
def access_qiita()
|
36
|
-
uri = URI.parse(@qiita + @path)
|
37
|
-
|
38
|
-
headers = { "Authorization" => "Bearer # {@access_token}",
|
39
|
-
"Content-Type" => "application/json" }
|
40
|
-
|
41
|
-
begin
|
42
|
-
response = URI.open(
|
43
|
-
"# {uri}",
|
44
|
-
"Authorization" => "# {headers["Authorization"]}",
|
45
|
-
)
|
46
|
-
#raise "NOT FOUND: # {@get_id} report".red
|
47
|
-
rescue => e
|
48
|
-
puts "# {$!}".red
|
49
|
-
exit
|
50
|
-
else
|
51
|
-
@items = JSON.parse(response.read)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
=end
|
55
|
-
|
56
19
|
# select report
|
57
20
|
def select_report()
|
58
21
|
@items.each do |item|
|
@@ -159,13 +122,13 @@ EOS
|
|
159
122
|
end
|
160
123
|
|
161
124
|
def run()
|
162
|
-
@access_token, @teams_url, @ox_qmd_load_path =
|
125
|
+
@access_token, @teams_url, @display, @ox_qmd_load_path = @base.set_config()
|
163
126
|
if @mode == "teams"
|
164
127
|
ErrorMessage.new().teams_url_error(@teams_url)
|
165
128
|
end
|
166
129
|
|
167
130
|
if @get_id == nil
|
168
|
-
@qiita, @path = @
|
131
|
+
@qiita, @path = @base.select_access_path(@mode, @teams_url)
|
169
132
|
@items = AccessQiita.new(@access_token, @qiita, @path).access_qiita()
|
170
133
|
select_report()
|
171
134
|
else
|
@@ -2,7 +2,7 @@ require "colorize"
|
|
2
2
|
#require "../qiita_org/qiita_org.rb"
|
3
3
|
require "qiita_org/post.rb"
|
4
4
|
require "qiita_org/upload.rb"
|
5
|
-
require "qiita_org/decide_option.rb"
|
5
|
+
#require "qiita_org/decide_option.rb"
|
6
6
|
|
7
7
|
class GetMultipleFiles
|
8
8
|
def initialize(files, os, type)
|
@@ -19,7 +19,8 @@ class GetMultipleFiles
|
|
19
19
|
def run()
|
20
20
|
puts "post files: #{@files}".green
|
21
21
|
@files.each do |file|
|
22
|
-
mode = @option || DecideOption.new(file).decide_option()
|
22
|
+
#mode = @option || DecideOption.new(file).decide_option()
|
23
|
+
mode = @option || QiitaBase.new().pick_up_option(file)
|
23
24
|
puts "qiita #{@type} #{file} #{mode}".green
|
24
25
|
if @type == "post"
|
25
26
|
qiita = QiitaPost.new(file, mode, @os)
|
@@ -31,7 +32,7 @@ class GetMultipleFiles
|
|
31
32
|
qiita.run
|
32
33
|
end
|
33
34
|
elsif @type == "upload"
|
34
|
-
|
35
|
+
QiitaFileUpLoad.new(file, mode, @os).upload()
|
35
36
|
end
|
36
37
|
end
|
37
38
|
end
|
@@ -1,14 +1,16 @@
|
|
1
1
|
require "fileutils"
|
2
2
|
require "colorize"
|
3
3
|
require "kconv"
|
4
|
-
require "qiita_org/search_conf_path"
|
4
|
+
#require "qiita_org/search_conf_path"
|
5
5
|
require "qiita_org/error_message.rb"
|
6
6
|
|
7
7
|
class QiitaGetTemplate
|
8
|
-
def initialize(os)
|
8
|
+
def initialize(os, filename)
|
9
9
|
@os = os
|
10
|
-
|
11
|
-
|
10
|
+
@filename = filename
|
11
|
+
#search = SearchConfPath.new(Dir.pwd, Dir.home)
|
12
|
+
# @conf_dir = search.search_conf_path()
|
13
|
+
@conf_dir = QiitaBase.new().search_conf_path(Dir.pwd, Dir.home)
|
12
14
|
# check_write_header()
|
13
15
|
end
|
14
16
|
|
@@ -18,9 +20,9 @@ class QiitaGetTemplate
|
|
18
20
|
m = []
|
19
21
|
m = version.match(/ProductName:\t(.+)\nProductVersion:\t(.+)\nBuildVersion:\t(.+)\n/)
|
20
22
|
system 'rm hoge.txt'
|
21
|
-
conts = File.read(
|
23
|
+
conts = File.read(@filename)
|
22
24
|
conts << "![#{m[1]}-#{m[2]}](https://img.shields.io/badge/#{m[1].gsub(" ", "")}-#{m[2]}-brightgreen) "
|
23
|
-
File.write(
|
25
|
+
File.write(@filename, conts) # + "# {m[1]}: # {m[2]}\n")
|
24
26
|
end
|
25
27
|
|
26
28
|
def get_windowsos_version()
|
@@ -33,9 +35,9 @@ class QiitaGetTemplate
|
|
33
35
|
m2 = version2.match(/OSArchitecture\n(.+)-bit/)
|
34
36
|
system 'rm hoge1.txt'
|
35
37
|
system 'rm hoge2.txt'
|
36
|
-
conts = File.read(
|
38
|
+
conts = File.read(@filename)
|
37
39
|
conts << "![#{m1[1]}-#{m1[2]}](https://img.shields.io/badge/#{m1[1].gsub(" ", "")}#{m1[2]}-#{m2[1]}bit-brightgreen) "
|
38
|
-
File.write(
|
40
|
+
File.write(@filename, conts) # + "# {m[1]}: # {m[2]}\n")
|
39
41
|
end
|
40
42
|
|
41
43
|
def get_ubuntu_version()
|
@@ -44,9 +46,9 @@ class QiitaGetTemplate
|
|
44
46
|
m = []
|
45
47
|
m = version.match(/(.+) (.+) LTS /)
|
46
48
|
system 'rm hoge.txt'
|
47
|
-
conts = File.read(
|
49
|
+
conts = File.read(@filename)
|
48
50
|
conts << "![#{m[1]}-#{m[2]}](https://img.shields.io/badge/#{m[1]}-#{m[2]}-brightgreen) "
|
49
|
-
File.write(
|
51
|
+
File.write(@filename, conts)
|
50
52
|
end
|
51
53
|
|
52
54
|
def get_ruby_version()
|
@@ -55,9 +57,9 @@ class QiitaGetTemplate
|
|
55
57
|
m = []
|
56
58
|
m = version.match(/ruby (.+) \((.+)/)
|
57
59
|
system 'rm hoge.txt'
|
58
|
-
conts = File.read(
|
60
|
+
conts = File.read(@filename)
|
59
61
|
conts << "![ruby-#{m[1]}](https://img.shields.io/badge/ruby-#{m[1].gsub(" ", "")}-brightgreen) "
|
60
|
-
File.write(
|
62
|
+
File.write(@filename, conts) # + "ruby: # {m[1]}\n")
|
61
63
|
end
|
62
64
|
|
63
65
|
# cp template.org
|
@@ -65,11 +67,11 @@ class QiitaGetTemplate
|
|
65
67
|
lib = File.expand_path("../../../lib", __FILE__)
|
66
68
|
cp_file = File.join(lib, "qiita_org", "template.org")
|
67
69
|
|
68
|
-
if File.exists?("
|
69
|
-
puts "
|
70
|
+
if File.exists?("./#{@filename}")
|
71
|
+
puts "#{@filename} exists.".red
|
70
72
|
exit
|
71
73
|
else
|
72
|
-
FileUtils.cp(cp_file,
|
74
|
+
FileUtils.cp(cp_file, @filename, verbose: true)
|
73
75
|
end
|
74
76
|
end
|
75
77
|
|
@@ -115,31 +117,33 @@ class QiitaGetTemplate
|
|
115
117
|
end
|
116
118
|
end
|
117
119
|
|
120
|
+
=begin
|
118
121
|
def get_name()
|
119
|
-
conts = File.readlines(
|
122
|
+
conts = File.readlines(@filename)
|
120
123
|
p "Type your name"
|
121
124
|
name = STDIN.gets
|
122
125
|
conts[3] = "#+AUTHOR: #{name}"
|
123
|
-
File.write(
|
126
|
+
File.write(@filename, conts.join)
|
124
127
|
end
|
125
128
|
|
126
129
|
def get_email()
|
127
|
-
conts = File.readlines(
|
130
|
+
conts = File.readlines(@filename)
|
128
131
|
p "Type your email"
|
129
132
|
email = STDIN.gets
|
130
133
|
conts[4] = "#+EMAIL: (concat \"#{email.chomp}\")\n"
|
131
|
-
File.write(
|
134
|
+
File.write(@filename, conts.join)
|
132
135
|
end
|
136
|
+
=end
|
133
137
|
|
134
138
|
def set_name_and_email()
|
135
139
|
conf_path = File.join(@conf_dir, ".qiita.conf")
|
136
140
|
conf = JSON.load(File.read(conf_path))
|
137
141
|
name = conf["name"]
|
138
142
|
email = conf["email"]
|
139
|
-
conts = File.readlines(
|
143
|
+
conts = File.readlines(@filename)
|
140
144
|
conts[3] = "#+AUTHOR: #{name}\n"
|
141
145
|
conts[4] = "#+EMAIL: (concat \"#{email}\")\n"
|
142
|
-
File.write(
|
146
|
+
File.write(@filename, conts.join)
|
143
147
|
end
|
144
148
|
|
145
149
|
def run()
|
data/lib/qiita_org/list.rb
CHANGED
@@ -2,54 +2,27 @@ require "net/https"
|
|
2
2
|
require "json"
|
3
3
|
require "open-uri"
|
4
4
|
require "colorize"
|
5
|
-
require "qiita_org/select_path.rb"
|
6
|
-
require "qiita_org/set_config.rb"
|
5
|
+
#require "qiita_org/select_path.rb"
|
6
|
+
#require "qiita_org/set_config.rb"
|
7
7
|
require "qiita_org/error_message.rb"
|
8
8
|
require "qiita_org/access_qiita.rb"
|
9
9
|
|
10
10
|
class QiitaList
|
11
11
|
def initialize(mode)
|
12
12
|
@mode = mode
|
13
|
-
@
|
13
|
+
@base = QiitaBase.new
|
14
|
+
# @access_token, @teams_url, @display, @ox_qmd_load_path = SetConfig.new().set_config()
|
15
|
+
@access_token, @teams_url, @display, @ox_qmd_load_path = @base.set_config()
|
14
16
|
if @mode == "teams"
|
15
17
|
ErrorMessage.new().teams_url_error(@teams_url)
|
16
18
|
end
|
17
19
|
|
18
|
-
@qiita, @path = SelectPath.new().select_path(@mode, @teams_url)
|
20
|
+
# @qiita, @path = SelectPath.new().select_path(@mode, @teams_url)
|
21
|
+
@qiita, @path = @base.select_access_path(@mode, @teams_url)
|
19
22
|
@items = AccessQiita.new(@access_token, @qiita, @path).access_qiita()
|
20
23
|
view_list()
|
21
24
|
end
|
22
25
|
|
23
|
-
# select path
|
24
|
-
=begin
|
25
|
-
def select_path()
|
26
|
-
case @mode
|
27
|
-
when "teams"
|
28
|
-
@qiita = @teams_url
|
29
|
-
@path = "api/v2/items?page=1&per_page=100"
|
30
|
-
else
|
31
|
-
@qiita = "https://qiita.com/"
|
32
|
-
@path = "api/v2/authenticated_user/items?page=1&per_page=100"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
=end
|
36
|
-
|
37
|
-
# access qiita
|
38
|
-
=begin
|
39
|
-
def access_qiita()
|
40
|
-
uri = URI.parse(@qiita + @path)
|
41
|
-
|
42
|
-
headers = { "Authorization" => "Bearer # {@access_token}",
|
43
|
-
"Content-Type" => "application/json" }
|
44
|
-
|
45
|
-
response = URI.open(
|
46
|
-
"# {uri}",
|
47
|
-
"Authorization" => "# {headers["Authorization"]}",
|
48
|
-
)
|
49
|
-
@items = JSON.parse(response.read)
|
50
|
-
end
|
51
|
-
=end
|
52
|
-
|
53
26
|
def view_list()
|
54
27
|
@items.each do |item|
|
55
28
|
puts "title: #{item["title"]}"
|
File without changes
|
File without changes
|
File without changes
|
@@ -12,7 +12,7 @@ class GetFileUrl
|
|
12
12
|
@id = id
|
13
13
|
@file = file
|
14
14
|
@mode = (mode == "qiita" || mode == "open")? "public" : mode
|
15
|
-
@access_token, @teams_url, @ox_qmd_load_path = SetConfig.new().set_config()
|
15
|
+
@access_token, @teams_url, @display, @ox_qmd_load_path = SetConfig.new().set_config()
|
16
16
|
if @mode == "teams"
|
17
17
|
ErrorMessage.new().teams_url_error(@teams_url)
|
18
18
|
end
|
File without changes
|
File without changes
|
File without changes
|
@@ -3,6 +3,7 @@ require "qiita_org/get_file_url.rb"
|
|
3
3
|
require "qiita_org/set_config.rb"
|
4
4
|
require "qiita_org/access_qiita.rb"
|
5
5
|
require "qiita_org/file_open.rb"
|
6
|
+
require "qiita_org/error_message.rb"
|
6
7
|
|
7
8
|
class ShowFile
|
8
9
|
def initialize(paths, src, mode, os)
|
@@ -52,7 +53,7 @@ class ShowFile
|
|
52
53
|
|
53
54
|
@access_token, @teams_url, @display, @ox_qmd_load_path = SetConfig.new().set_config()
|
54
55
|
if @mode == "teams"
|
55
|
-
|
56
|
+
ErrorMessage.new().teams_url_error(@teams_url)
|
56
57
|
end
|
57
58
|
|
58
59
|
qiita = (@mode == "teams") ? @teams_url : "https://qiita.com/"
|
data/lib/qiita_org/post.rb
CHANGED
@@ -5,15 +5,17 @@ require "json"
|
|
5
5
|
require "command_line/global"
|
6
6
|
require "colorize"
|
7
7
|
require "qiita_org/md_converter_for_image"
|
8
|
-
require "qiita_org/set_config.rb"
|
8
|
+
#require "qiita_org/set_config.rb"
|
9
9
|
require "qiita_org/error_message"
|
10
10
|
require "qiita_org/file_open.rb"
|
11
|
+
require "qiita_org/access_qiita.rb"
|
11
12
|
|
12
13
|
class QiitaPost
|
13
14
|
def initialize(file, option, os)
|
14
15
|
@src = file
|
15
16
|
@option = (option == "qiita" || option == "open")? "public" : option
|
16
17
|
@os = os
|
18
|
+
@base = QiitaBase.new
|
17
19
|
end
|
18
20
|
|
19
21
|
public
|
@@ -64,20 +66,29 @@ class QiitaPost
|
|
64
66
|
return qiita_id, patch
|
65
67
|
end
|
66
68
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
69
|
+
def check_change_public(conts, option, id)
|
70
|
+
qiita = "https://qiita.com/"
|
71
|
+
path = "api/v2/items/#{id}"
|
72
|
+
items = AccessQiita.new(@access_token, qiita, path).access_qiita()
|
73
|
+
|
74
|
+
if items["private"]
|
75
|
+
return conts, option
|
76
|
+
else
|
77
|
+
option = "public"
|
78
|
+
lines = File.readlines(@src)
|
79
|
+
file = File.open(@src, "w")
|
80
|
+
lines.each_with_index do |line, i|
|
81
|
+
lines[i] = "#+qiita_#{option}: #{id}\n" if line.match(/\#\+qiita_private: (.+)/)
|
82
|
+
file.print(lines[i])
|
77
83
|
end
|
84
|
+
conts = File.read(@src)
|
85
|
+
return conts, option
|
78
86
|
end
|
79
|
-
|
80
|
-
|
87
|
+
end
|
88
|
+
|
89
|
+
# check twitter post
|
90
|
+
def select_twitter(conts, option)
|
91
|
+
option == "public" && conts.match?(/^\#\+twitter:\s*on$/i)
|
81
92
|
end
|
82
93
|
|
83
94
|
def select_option(option)
|
@@ -157,24 +168,11 @@ class QiitaPost
|
|
157
168
|
end
|
158
169
|
end
|
159
170
|
|
160
|
-
# open qiita
|
161
|
-
=begin
|
162
|
-
def open_qiita()
|
163
|
-
if @os == "mac"
|
164
|
-
system "open # {@res_body["url"]}"
|
165
|
-
elsif @os == "windows"
|
166
|
-
system "explorer.exe # {@res_body["url"]}"
|
167
|
-
else
|
168
|
-
system "open # {@res_body["url"]}"
|
169
|
-
system "xdg-open # {@res_body["url"]}"
|
170
|
-
end
|
171
|
-
end
|
172
|
-
=end
|
173
|
-
|
174
171
|
def run()
|
175
172
|
@conts = File.read(@src)
|
176
173
|
@title, @tags = get_title_tags(@conts)
|
177
|
-
@access_token, @teams_url, @display, @ox_qmd_load_path = SetConfig.new().set_config()
|
174
|
+
# @access_token, @teams_url, @display, @ox_qmd_load_path = SetConfig.new().set_config()
|
175
|
+
@access_token, @teams_url, @display, @ox_qmd_load_path = @base.set_config()
|
178
176
|
|
179
177
|
if @option == "teams"
|
180
178
|
ErrorMessage.new().teams_url_error(@teams_url)
|
@@ -184,6 +182,7 @@ class QiitaPost
|
|
184
182
|
add_source_path_in_md()
|
185
183
|
@lines = MdConverter.new().convert_for_image(@lines)
|
186
184
|
@qiita_id, @patch = select_patch_or_post(@conts, @option)
|
185
|
+
@conts, @option = check_change_public(@conts, @option, @qiita_id) if (@patch and @option == "private")
|
187
186
|
@twitter = select_twitter(@conts, @option)
|
188
187
|
@qiita, @private = select_option(@option)
|
189
188
|
@res = qiita_post()
|
data/lib/qiita_org/upload.rb
CHANGED
@@ -1,28 +1,127 @@
|
|
1
1
|
require "colorize"
|
2
2
|
require "io/console"
|
3
|
-
require "qiita_org/get_file_path.rb"
|
4
|
-
require "qiita_org/show_file_and_url.rb"
|
3
|
+
#require "qiita_org/get_file_path.rb"
|
4
|
+
#require "qiita_org/show_file_and_url.rb"
|
5
|
+
require "qiita_org/file_open.rb"
|
6
|
+
#require "qiita_org/set_config.rb"
|
7
|
+
require "qiita_org/access_qiita.rb"
|
5
8
|
|
6
|
-
class
|
9
|
+
class QiitaFileUpLoad
|
7
10
|
def initialize(src, option, os)
|
8
11
|
@src = src
|
9
12
|
@option = (option == "qiita" || option == "open")? "public" : option
|
10
13
|
@os = os
|
14
|
+
@fileopen = FileOpen.new(@os)
|
15
|
+
# @access_token, @teams_url, @display, @ox_qmd_load_path = SetConfig.new().set_config()
|
16
|
+
@access_token, @teams_url, @display, @ox_qmd_load_path = QiitaBase.new().set_config()
|
17
|
+
if @option == "teams"
|
18
|
+
ErrorMessage.new().teams_url_error(@teams_url)
|
19
|
+
end
|
11
20
|
end
|
12
21
|
|
13
22
|
def upload()
|
14
|
-
paths = GetFilePath.new(@src).get_file_path()
|
23
|
+
#paths = GetFilePath.new(@src).get_file_path()
|
24
|
+
paths = get_file_path(@src)
|
15
25
|
unless paths.empty?
|
16
|
-
showfile = ShowFile.new(paths, @src, @option, @os)
|
17
|
-
showfile.open_file_dir()
|
18
|
-
|
26
|
+
#showfile = ShowFile.new(paths, @src, @option, @os)
|
27
|
+
#showfile.open_file_dir()
|
28
|
+
open_file_dir(paths)
|
29
|
+
#showfile.open_qiita()
|
30
|
+
open_qiita()
|
19
31
|
|
20
32
|
puts "Overwrite file URL's on #{@src}? (y/n)".green
|
21
33
|
ans = STDIN.getch
|
22
34
|
|
23
35
|
if ans == "y"
|
24
|
-
showfile.input_url_to_org()
|
36
|
+
#showfile.input_url_to_org()
|
37
|
+
input_url_to_org(paths)
|
38
|
+
end
|
39
|
+
else
|
40
|
+
puts "file path is empty.".red
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_file_path(src)
|
45
|
+
lines = File.readlines(src)
|
46
|
+
files = []
|
47
|
+
lines.each do |line|
|
48
|
+
if path = line.match(/\[\[(.+)\]\[file:(.+)\]\]/) || line.match(/\[\[file:(.+)\]\]/)
|
49
|
+
if path[2] == nil
|
50
|
+
files << path[1]
|
51
|
+
else
|
52
|
+
files << path[2]
|
53
|
+
end
|
25
54
|
end
|
26
55
|
end
|
56
|
+
|
57
|
+
return files
|
58
|
+
end
|
59
|
+
|
60
|
+
def open_file_dir(paths)
|
61
|
+
previous_paths = []
|
62
|
+
previous_paths << File.join(paths[0].split("/")[0..-2])
|
63
|
+
@fileopen.file_open(File.join(paths[0].split("/")[0..-2]))
|
64
|
+
|
65
|
+
paths.each do |path|
|
66
|
+
dir_path = File.join(path.split("/")[0..-2])
|
67
|
+
unless previous_paths.include?(dir_path)
|
68
|
+
previous_paths << dir_path
|
69
|
+
@fileopen.file_open(dir_path)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def open_qiita()
|
75
|
+
conts = File.read(@src)
|
76
|
+
id = conts.match(/\#\+qiita_#{@option}: (.+)/)[1]
|
77
|
+
|
78
|
+
=begin
|
79
|
+
@access_token, @teams_url, @display, @ox_qmd_load_path = SetConfig.new().set_config()
|
80
|
+
if @option == "teams"
|
81
|
+
ErrorMassage.new().teams_url_error(@teams_url)
|
82
|
+
end
|
83
|
+
=end
|
84
|
+
|
85
|
+
qiita = (@option == "teams") ? @teams_url : "https://qiita.com/"
|
86
|
+
path = "api/v2/items/#{id}"
|
87
|
+
|
88
|
+
@access = AccessQiita.new(@access_token, qiita, path)
|
89
|
+
items = @access.access_qiita()
|
90
|
+
|
91
|
+
@fileopen.file_open(items["url"])
|
92
|
+
end
|
93
|
+
|
94
|
+
def input_url_to_org(paths)
|
95
|
+
lines = File.readlines(@src)
|
96
|
+
conts = File.read(@src)
|
97
|
+
id = conts.match(/\#\+qiita_#{@option}: (.+)/)[1]
|
98
|
+
|
99
|
+
paths.each do |path|
|
100
|
+
file_name = File.basename(path).strip
|
101
|
+
url = (get_file_url(id, file_name))? @file_url : next
|
102
|
+
lines.each_with_index do |line, i|
|
103
|
+
if line.match(/\[\[file:#{path}\]\]/)
|
104
|
+
lines[i] = "[[#{url}][file:#{path}]]\n"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
File.write(@src, lines.join)
|
110
|
+
end
|
111
|
+
|
112
|
+
def get_file_url(id, file_name)
|
113
|
+
qiita = (@option == "teams")? @teams_url : "https://qiita.com/"
|
114
|
+
path = "api/v2/items/#{@id}"
|
115
|
+
|
116
|
+
items = @access.access_qiita()
|
117
|
+
|
118
|
+
if items["body"].match?(/\!\[#{file_name}\]\(((.+))\)/)
|
119
|
+
@file_url = items["body"].match(/\!\[#{file_name}\]\(((.+))\)/)[2]
|
120
|
+
puts "Wrote #{file_name}'s URL".green
|
121
|
+
return true
|
122
|
+
else
|
123
|
+
puts "Can not find #{file_name}'s URL".red
|
124
|
+
return false
|
125
|
+
end
|
27
126
|
end
|
28
127
|
end
|
data/lib/qiita_org/version.rb
CHANGED
data/tests/test2.org
CHANGED
@@ -18,6 +18,6 @@ fogefoge
|
|
18
18
|
#+ATTR_LATEX: :width 8cm
|
19
19
|
[[https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/612049/ebf505d2-6960-6bb9-20f0-e16dab142f4a.png][file:../figs/fig1.png]]
|
20
20
|
|
21
|
-
[[
|
21
|
+
[[file:../figs/fig2.png]]
|
22
22
|
|
23
23
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qiita_org
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.32
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenta Yamamoto
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -2558,32 +2558,32 @@ files:
|
|
2558
2558
|
- lib/qiita_org/.qiita.conf
|
2559
2559
|
- lib/qiita_org/access_qiita.rb
|
2560
2560
|
- lib/qiita_org/all.rb
|
2561
|
-
- lib/qiita_org/
|
2561
|
+
- lib/qiita_org/base.rb
|
2562
2562
|
- lib/qiita_org/config.json
|
2563
2563
|
- lib/qiita_org/config.rb
|
2564
|
-
- lib/qiita_org/decide_option.rb
|
2565
2564
|
- lib/qiita_org/error_message.rb
|
2566
2565
|
- lib/qiita_org/file_open.rb
|
2567
2566
|
- lib/qiita_org/get.rb
|
2568
|
-
- lib/qiita_org/get_file_path.rb
|
2569
|
-
- lib/qiita_org/get_file_url.rb
|
2570
2567
|
- lib/qiita_org/get_multiple_files.rb
|
2571
2568
|
- lib/qiita_org/get_template.rb
|
2572
2569
|
- lib/qiita_org/hoge.txt
|
2573
2570
|
- lib/qiita_org/list.rb
|
2574
2571
|
- lib/qiita_org/md_converter_for_image.rb
|
2572
|
+
- lib/qiita_org/old_programs/check_pc_os.rb
|
2573
|
+
- lib/qiita_org/old_programs/decide_option.rb
|
2574
|
+
- lib/qiita_org/old_programs/get_file_path.rb
|
2575
|
+
- lib/qiita_org/old_programs/get_file_url.rb
|
2576
|
+
- lib/qiita_org/old_programs/search_conf_path.rb
|
2577
|
+
- lib/qiita_org/old_programs/select_path.rb
|
2578
|
+
- lib/qiita_org/old_programs/set_config.rb
|
2579
|
+
- lib/qiita_org/old_programs/show_file_and_url.rb
|
2575
2580
|
- lib/qiita_org/ox-qmd/ox-qmd.el
|
2576
2581
|
- lib/qiita_org/post.rb
|
2577
|
-
- lib/qiita_org/search_conf_path.rb
|
2578
|
-
- lib/qiita_org/select_path.rb
|
2579
|
-
- lib/qiita_org/set_config.rb
|
2580
|
-
- lib/qiita_org/show_file_and_url.rb
|
2581
2582
|
- lib/qiita_org/template.org
|
2582
2583
|
- lib/qiita_org/upload.rb
|
2583
2584
|
- lib/qiita_org/version.rb
|
2584
2585
|
- qiita_org.gemspec
|
2585
2586
|
- tests/hoge.rb
|
2586
|
-
- tests/template.org
|
2587
2587
|
- tests/test.html
|
2588
2588
|
- tests/test.org
|
2589
2589
|
- tests/test2.org
|
data/tests/template.org
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
#+OPTIONS: ^:{}
|
2
|
-
#+STARTUP: indent nolineimages
|
3
|
-
#+TITLE: title
|
4
|
-
#+AUTHOR: Kenta Yamamoto
|
5
|
-
#+EMAIL: (concat "doi35077@kwansei.ac.jp")
|
6
|
-
#+LANGUAGE: jp
|
7
|
-
# +OPTIONS: H:4 toc:t num:2
|
8
|
-
#+OPTIONS: toc:nil
|
9
|
-
#+TAG: tag1, tag2
|
10
|
-
#+TWITTER: off
|
11
|
-
# +SETUPFILE: ~/.emacs.d/org-mode/theme-readtheorg.setup
|
12
|
-
|
13
|
-
 
|