jupyter_to_scrapbox 0.2.3 → 0.3.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 +4 -0
- data/jupyter_to_scrapbox.gemspec +1 -1
- data/lib/gyazo_ext.rb +30 -0
- data/lib/jupyter_to_scrapbox/version.rb +1 -1
- data/lib/jupyter_to_scrapbox.rb +40 -4
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2a95a898833b4c7826367ed7fb20ef55e124bec
|
4
|
+
data.tar.gz: '018d7296e0b3fac13362e97bdab26721c955a5f6'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4e942c580ea7479cae4a22da72352721b141f5735e049c2c5423fc27146b5dcb34c70eace69efedb1bd3bdefdb6ee54989719f1a7f0dcf29f21dd1256bd1aee
|
7
|
+
data.tar.gz: e42b3245e981c6f812fd7a68ef469e730d2efd2be209f6239a9cb1aab451c1a031ccd3809cd1273e5ab2feb2c28fbbe2348bda13d7724ef035d8671a2b56146c
|
data/README.md
CHANGED
@@ -31,6 +31,10 @@ To import `scrapbox.json` to scrapbox, follow the instruction of "import pages"
|
|
31
31
|
|
32
32
|
Specify `scrapbox.json` created by this tool.
|
33
33
|
|
34
|
+
In order to register inline images to GYAZO service (--image or -i option),
|
35
|
+
preset GYAZO's access token to the environment variable GYAZO_TOKEN.
|
36
|
+
Refer https://gyazo.com/api for acquiring GYAZO's access token in detail.
|
37
|
+
|
34
38
|
## Development
|
35
39
|
|
36
40
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/jupyter_to_scrapbox.gemspec
CHANGED
data/lib/gyazo_ext.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'JSON'
|
4
|
+
require 'gyazo'
|
5
|
+
|
6
|
+
module Gyazo
|
7
|
+
|
8
|
+
class Client
|
9
|
+
|
10
|
+
def upload_image(imagedata,params={})
|
11
|
+
url = "https://upload.gyazo.com/api/upload"
|
12
|
+
time = params[:time] || params[:created_at] || Time.now
|
13
|
+
res = HTTMultiParty.post url, {
|
14
|
+
:query => {
|
15
|
+
:access_token => @access_token,
|
16
|
+
:imagedata => imagedata,
|
17
|
+
:created_at => time.to_i,
|
18
|
+
:referer_url => params[:referer_url] || params[:url] || '',
|
19
|
+
:title => params[:title] || '',
|
20
|
+
:desc => params[:desc] || ''
|
21
|
+
},
|
22
|
+
:header => {
|
23
|
+
'User-Agent' => @user_agent
|
24
|
+
}
|
25
|
+
}
|
26
|
+
raise Gyazo::Error, res.body unless res.code == 200
|
27
|
+
return JSON.parse res.body
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/jupyter_to_scrapbox.rb
CHANGED
@@ -1,5 +1,36 @@
|
|
1
1
|
require "jupyter_to_scrapbox/version"
|
2
|
+
require "rest-client"
|
2
3
|
require "JSON"
|
4
|
+
require 'base64'
|
5
|
+
|
6
|
+
def register_image(vv)
|
7
|
+
f=Tempfile.new(['image','.png'],Dir.tmpdir,:binary => true)
|
8
|
+
f.write Base64.decode64(vv)
|
9
|
+
image_path=File.expand_path(f.to_path)
|
10
|
+
f.close(false)
|
11
|
+
vp image_path
|
12
|
+
vputs File.new(image_path, 'rb')
|
13
|
+
gyazo_url="https://upload.gyazo.com/api/upload"
|
14
|
+
begin
|
15
|
+
r = RestClient.post gyazo_url, {
|
16
|
+
"access_token" => ENV["GYAZO_TOKEN"],
|
17
|
+
:imagedata => File.new(image_path, 'rb')
|
18
|
+
}
|
19
|
+
return JSON.parse(r)
|
20
|
+
rescue => e
|
21
|
+
p e
|
22
|
+
puts e.backtrace
|
23
|
+
puts <<EOS
|
24
|
+
Failed to register image data.
|
25
|
+
- Be online.
|
26
|
+
- Set your ACCESS_TOKEN to the environment variable "GYAZO_TOKEN"
|
27
|
+
EOS
|
28
|
+
ensure
|
29
|
+
FileUtils.rm(image_path)
|
30
|
+
end
|
31
|
+
exit(1)
|
32
|
+
end
|
33
|
+
|
3
34
|
|
4
35
|
module JupyterToScrapbox
|
5
36
|
# Your code goes here...
|
@@ -9,8 +40,11 @@ module JupyterToScrapbox
|
|
9
40
|
@@parse_markdown_notations=true
|
10
41
|
@@converters=[]
|
11
42
|
|
43
|
+
def Converter.prepareGyazoclient()
|
44
|
+
end
|
45
|
+
|
12
46
|
def Converter.set_verbose(v)
|
13
|
-
|
47
|
+
bose=v
|
14
48
|
end
|
15
49
|
|
16
50
|
def Converter.set_register_images(v)
|
@@ -108,11 +142,14 @@ module JupyterToScrapbox
|
|
108
142
|
end
|
109
143
|
|
110
144
|
def parse_image_png(v)
|
111
|
-
vputs
|
145
|
+
vputs(v)
|
146
|
+
|
112
147
|
push_text("code:output.txt")
|
113
148
|
push_code("image/png")
|
114
149
|
if @@register_images
|
115
|
-
|
150
|
+
r=register_image(v)
|
151
|
+
url=r["url"]
|
152
|
+
push_text( "["+url+"]" )
|
116
153
|
end
|
117
154
|
push_empty_text()
|
118
155
|
end
|
@@ -206,6 +243,5 @@ module JupyterToScrapbox
|
|
206
243
|
}
|
207
244
|
return page
|
208
245
|
end
|
209
|
-
|
210
246
|
end
|
211
247
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jupyter_to_scrapbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hiroharu Sugawara
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rest-client
|
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'
|
55
69
|
description: convert jupyter-notebook files to scrapbox-import-ready-json
|
56
70
|
email:
|
57
71
|
- hsugawa@tmu.ac.jp
|
@@ -69,6 +83,7 @@ files:
|
|
69
83
|
- exe/jupyter_to_scrapbox
|
70
84
|
- jupyter_to_scrapbox.gemspec
|
71
85
|
- lib/cli.rb
|
86
|
+
- lib/gyazo_ext.rb
|
72
87
|
- lib/jupyter_to_scrapbox.rb
|
73
88
|
- lib/jupyter_to_scrapbox/version.rb
|
74
89
|
homepage: https://github.com/hsugawa8651/jupyter_to_scrapbox_gem
|