nb_util 0.3.4

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.
@@ -0,0 +1,3 @@
1
+ module NbUtil
2
+ VERSION = "0.3.4"
3
+ end
@@ -0,0 +1,181 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'pp'
3
+ require 'yaml'
4
+ require 'json'
5
+ require "nb_util/version"
6
+ require 'cli'
7
+
8
+ module NbUtil
9
+ module_function
10
+ def yaml2ipynb(argv0)
11
+ input_filename = ARGV[1]
12
+ output_filename = ARGV[2] || input_filename.gsub(/(yml|yaml)$/, 'ipynb')
13
+ cont = YAML.load(File.read(ARGV[1]))
14
+ contsinglehash = flatten_hash_from cont
15
+ #pp contsinglehash
16
+
17
+ contsinglehashneed = contsinglehash.select{|k, v| k.match(/title/) || k.match(/cont/) }
18
+ pp contsinglehashneed
19
+
20
+ contdiffstring = contsinglehashneed.to_s
21
+
22
+ contdiffstring.gsub!(/=>/,'')
23
+ str = contsinglehashneed.keys
24
+ contnum=str.count
25
+ for i in 0..contnum do
26
+ ignore = str[i].to_s
27
+ p ignore
28
+ contdiffstring.sub!(/#{ignore}/,'')
29
+ end
30
+ contdiffstring.gsub!(/:\"\"\"/,'# ')
31
+ contdiffstring.gsub!(/\[/,'')
32
+ contdiffstring.gsub!(/\]/,'')
33
+ contdiffstring.gsub!(/{/,'')
34
+ contdiffstring.gsub!(/}/,'')
35
+ contdiffstring.gsub!(/\", :\"\"\"/,'\n')
36
+ contdiffstring.gsub!(/\"/,'')
37
+ contdiffstring.gsub!(/,/,'\n')
38
+ pp contdiffstring
39
+
40
+ #cellのデータ
41
+ cellsData = <<EOS
42
+ {
43
+ "cell_type": "markdown",
44
+ "metadata": {},
45
+ "source": [
46
+ "#{contdiffstring}"
47
+ ]
48
+ }
49
+ EOS
50
+
51
+ meta = <<-EOS
52
+ {
53
+ "cells": [
54
+ {
55
+ "cell_type": "markdown",
56
+ "metadata": {},
57
+ "source": [
58
+ "test code"
59
+ ]
60
+ },
61
+ #{cellsData}
62
+ ],
63
+ "metadata": {
64
+ "kernelspec": {
65
+ "display_name": "Python 3",
66
+ "language": "python",
67
+ "name": "python3"
68
+ },
69
+ "language_info": {
70
+ "codemirror_mode": {
71
+ "name": "ipython",
72
+ "version": 3
73
+ },
74
+ "file_extension": ".py",
75
+ "mimetype": "text/x-python",
76
+ "name": "python",
77
+ "nbconvert_exporter": "python",
78
+ "pygments_lexer": "ipython3",
79
+ "version": "3.6.2"
80
+ },
81
+ "latex_envs": {
82
+ "LaTeX_envs_menu_present": true,
83
+ "autocomplete": true,
84
+ "bibliofile": "biblio.bib",
85
+ "cite_by": "apalike",
86
+ "current_citInitial": 1,
87
+ "eqLabelWithNumbers": true,
88
+ "eqNumInitial": 1,
89
+ "hotkeys": {
90
+ "equation": "Ctrl-E",
91
+ "itemize": "Ctrl-I"
92
+ },
93
+ "labels_anchors": false,
94
+ "latex_user_defs": false,
95
+ "report_style_numbering": false,
96
+ "user_envs_cfg": false
97
+ },
98
+ "nbTranslate": {
99
+ "displayLangs": [
100
+ "*"
101
+ ],
102
+ "hotkey": "alt-t",
103
+ "langInMainMenu": true,
104
+ "sourceLang": "en",
105
+ "targetLang": "fr",
106
+ "useGoogleTranslate": true
107
+ },
108
+ "toc": {
109
+ "colors": {
110
+ "hover_highlight": "#DAA520",
111
+ "navigate_num": "#000000",
112
+ "navigate_text": "#333333",
113
+ "running_highlight": "#FF0000",
114
+ "selected_highlight": "#FFD700",
115
+ "sidebar_border": "#EEEEEE",
116
+ "wrapper_background": "#FFFFFF"
117
+ },
118
+ "moveMenuLeft": true,
119
+ "nav_menu": {
120
+ "height": "12px",
121
+ "width": "252px"
122
+ },
123
+ "navigate_menu": true,
124
+ "number_sections": true,
125
+ "sideBar": true,
126
+ "threshold": 4,
127
+ "toc_cell": false,
128
+ "toc_section_display": "block",
129
+ "toc_window_display": true,
130
+ "widenNotebook": false
131
+ },
132
+ "varInspector": {
133
+ "cols": {
134
+ "lenName": 16,
135
+ "lenType": 16,
136
+ "lenVar": 40
137
+ },
138
+ "kernels_config": {
139
+ "python": {
140
+ "delete_cmd_postfix": "",
141
+ "delete_cmd_prefix": "del ",
142
+ "library": "var_list.py",
143
+ "varRefreshCmd": "print(var_dic_list())"
144
+ },
145
+ "r": {
146
+ "delete_cmd_postfix": ") ",
147
+ "delete_cmd_prefix": "rm(",
148
+ "library": "var_list.r",
149
+ "varRefreshCmd": "cat(var_dic_list()) "
150
+ }
151
+ },
152
+ "types_to_exclude": [
153
+ "module",
154
+ "function",
155
+ "builtin_function_or_method",
156
+ "instance",
157
+ "_Feature"
158
+ ],
159
+ "window_display": false
160
+ }
161
+ },
162
+ "nbformat": 4,
163
+ "nbformat_minor": 2
164
+ }
165
+ EOS
166
+
167
+ File.open(output_filename, 'w+') do |f|
168
+ f.print(meta)
169
+ end
170
+ end
171
+
172
+ # nest hash to single hash
173
+ def flatten_hash_from hash
174
+ hash.each_with_object({}) do |(key, value), memo|
175
+ next flatten_hash_from(value).each do |k, v|
176
+ memo["#{key}.#{k}".intern] = v
177
+ end if value.is_a? Hash
178
+ memo[key] = value
179
+ end
180
+ end
181
+ end
@@ -0,0 +1,37 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "nb_util/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nb_util"
8
+ spec.version = NbUtil::VERSION
9
+ spec.authors = ["Masatoshi Kowaki"]
10
+ spec.email = ["ferrari.race.beautiful@gmail.com"]
11
+
12
+ spec.summary = %q{about jupyter utils}
13
+ spec.description = %q{about jupyter utils}
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against " \
23
+ # "public gem pushes."
24
+ # end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.16"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+ spec.add_development_dependency "thor"
37
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nb_util
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.4
5
+ platform: ruby
6
+ authors:
7
+ - Masatoshi Kowaki
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-12-18 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.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: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: about jupyter utils
70
+ email:
71
+ - ferrari.race.beautiful@gmail.com
72
+ executables:
73
+ - nb_util
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".DS_Store"
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".rspec_status"
81
+ - CODE_OF_CONDUCT.md
82
+ - Gemfile
83
+ - Gemfile.lock
84
+ - LICENSE.txt
85
+ - README.md
86
+ - Rakefile
87
+ - bin/console
88
+ - bin/setup
89
+ - docs/.ipynb_checkpoints/abst-checkpoint.ipynb
90
+ - docs/CopyAppend_ipynb.ipynb
91
+ - docs/how_to_set_up_mac.ipynb
92
+ - exe/nb_util
93
+ - lib/.DS_Store
94
+ - lib/cli.rb
95
+ - lib/data/pieces/form00_style.tex
96
+ - lib/data/pieces/tightlist_setting.tex
97
+ - lib/data/pieces/usepackage.tex
98
+ - lib/data/thesis/thesis.tex
99
+ - lib/nb_util.rb
100
+ - lib/nb_util/.#ipynb2tex.rb
101
+ - lib/nb_util/.DS_Store
102
+ - lib/nb_util/combine.rb
103
+ - lib/nb_util/getcode.rb
104
+ - lib/nb_util/iputs.rb
105
+ - lib/nb_util/ipynb2tex.rb
106
+ - lib/nb_util/version.rb
107
+ - lib/nb_util/yaml2ipynb.rb
108
+ - nb_util.gemspec
109
+ homepage: ''
110
+ licenses:
111
+ - MIT
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.7.2
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: about jupyter utils
133
+ test_files: []