enop 0.1.3

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8e989593e40d999366ab21adfd8f54f05f9ab50b
4
+ data.tar.gz: b33826e9c971b7c93bc05d4c0401f89413e4842f
5
+ SHA512:
6
+ metadata.gz: 8e15eda394a9a51d48dfead71776f3ed6a03d220bdd70295cdb187fc56f55a61c8933b5c9dd08dae5895c1017110039be35d548bfb3c02a2cede454a9456b738
7
+ data.tar.gz: b6b17fe1ef6a4c92434db4cdaeb38d59b48838978d999cd081d00e39883f810186635ba8d0c2e3ad3aa265a281a09970a86bce637bd8cb35c739f9cf3ec94165
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ before_install: gem install bundler -v 1.10.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in enop.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Enop
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/enop`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'enop'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install enop
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec enop` to use the gem in this directory, ignoring other installed copies of this gem.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/enop.
36
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "enop"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/enop.gemspec ADDED
@@ -0,0 +1,44 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'enop/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "enop"
8
+ spec.version = Enop::VERSION
9
+ spec.authors = ["yasuo kominami"]
10
+ spec.email = ["ykominami@gmail.com"]
11
+
12
+ spec.summary = %q{evernote operation.}
13
+ spec.description = %q{evernote operation.}
14
+ spec.homepage = ""
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ if spec.respond_to?(:metadata)
19
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_runtime_dependency "evernote_oauth"
30
+ spec.add_runtime_dependency "activerecord"
31
+ spec.add_runtime_dependency "sqlite3"
32
+ # spec.add_runtime_dependency "sinatra"
33
+ # spec.add_runtime_dependency "sinatra-contrib"
34
+ # spec.add_runtime_dependency "backport" , ">= 2.0"
35
+ # spec.add_runtime_dependency "multi_json" , ">= 1.11.1"
36
+ # spec.add_runtime_dependency "rack"
37
+ # spec.add_runtime_dependency "rack-test"
38
+
39
+ spec.add_runtime_dependency "arxutils"
40
+
41
+ spec.add_development_dependency "bundler", "~> 1.10"
42
+ spec.add_development_dependency "rake", "~> 10.0"
43
+ spec.add_development_dependency "rspec"
44
+ end
data/exe/enop ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "enop"
4
+
5
+ authToken = "S=s18:U=1f38cb:E=15110796cd9:C=149b8c83d38:P=1cd:A=en-devtoken:V=2:H=970049a2b990ad5e0f58252a626539b0"
6
+
7
+ enop = Enop::Enop.new(Arxutils::DB_DIR, Arxutils::MIGRATE_DIR , Arxutils::CONFIG_DIR , Arxutils::DBCONFIG , Arxutils::DATABASELOG , authToken)
8
+ enop.connect
9
+ enop.list_notebooks
data/exe/makemigrate ADDED
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require 'dbinit'
5
+ require 'migrate'
6
+ require 'enop'
7
+
8
+ data_ary = [
9
+ {
10
+ :flist => %W!noitem!,
11
+ :classname => "Countdatetime",
12
+ :classname_downcase => "countdatetime",
13
+ :items => [
14
+ ["countdatetime" , "datetime", "false"],
15
+ ],
16
+ :plural => "countdatetimes"
17
+ },
18
+
19
+ {
20
+ :flist => %W!noitem!,
21
+ :classname => "Evnb",
22
+ :classname_downcase => "evnb",
23
+ :items => [
24
+ ["time_id" , "integer", "false"],
25
+ ["ennb_id" , "integer", "false"],
26
+ ],
27
+ :plural => "evnbs"
28
+ },
29
+
30
+ {
31
+ :flist => %W!base invalid current!,
32
+ :classname => "Ennblist",
33
+ :classname_downcase => "ennblist",
34
+
35
+ :items => [
36
+ ["stack" , "string", "false"],
37
+ ["notebook" , "string", "false"],
38
+ ["count" , "integer", "false"],
39
+ ["tag_count" , "integer", "false"],
40
+ ],
41
+ :plural => "ennblists"
42
+ },
43
+ ]
44
+
45
+ forced = true
46
+ mig = Arxutils::Migrate.new(Arxutils::DB_DIR, Arxutils::MIGRATE_DIR , Arxutils::CONFIG_DIR , Arxutils::DBCONFIG, Arxutils::DATABASELOG , forced )
47
+ data_ary.reduce(0) do |next_num , x|
48
+ mig.make( next_num , x )
49
+ end
50
+ mig.migrate
@@ -0,0 +1,95 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'forwardable'
3
+ require 'pp'
4
+
5
+ module Enop
6
+ module Dbutil
7
+ class Ennblist < ActiveRecord::Base
8
+ end
9
+
10
+ class Invalidennblist < ActiveRecord::Base
11
+ end
12
+
13
+ class Currentennblist < ActiveRecord::Base
14
+ belongs_to :ennblist , foreign_key: 'org_id'
15
+ end
16
+
17
+ class Evnb < ActiveRecord::Base
18
+ end
19
+
20
+ class Countdatetime < ActiveRecord::Base
21
+ end
22
+
23
+ class DbMgr
24
+ extend Forwardable
25
+
26
+ def_delegator( :@ennblistmgr , :add, :add)
27
+
28
+ def initialize( register_time )
29
+ @ennblistmgr = EnopMgr.new( register_time )
30
+ end
31
+
32
+ end
33
+
34
+ class EnopMgr
35
+
36
+ extend Forwardable
37
+
38
+ def initialize(register_time)
39
+ @register_time = register_time
40
+ @ct = Countdatetime.create( countdatetime: @register_time )
41
+ @hs_by_notebook = {}
42
+ @hs_by_id = {}
43
+ end
44
+
45
+ def add( stack , notebook, count, tag_count )
46
+ ennblist = @hs_by_notebook[notebook]
47
+ unless ennblist
48
+ cur_ennblist = Currentennblist.where( notebook: notebook ).limit(1)
49
+ if cur_ennblist.size == 0
50
+ begin
51
+ ennblist = Ennblist.create( stack: stack, notebook: notebook , count: count, tag_count: tag_count , start_datetime: @register_time )
52
+ evnb = Evnb.create( time_id: @ct.id , ennb_id: ennblist.id )
53
+ rescue => ex
54
+ p ex.class
55
+ p ex.message
56
+ pp ex.backtrace
57
+
58
+ ennblist = nil
59
+ evnb = nil
60
+ end
61
+ else
62
+ current_ennblist = cur_ennblist.first.ennblist
63
+ hs = {:stack => stack, :count => count , :tag_count => tag_count }
64
+ value_hs = hs.reduce({}){ |hsx,item|
65
+ if current_ennblist[ item[0] ] != item[1]
66
+ hsx[ item[0] ] = item[1]
67
+ end
68
+ hsx
69
+ }
70
+ current_ennblist.update(value_hs) if value_hs.size > 0
71
+ end
72
+ else
73
+ # ignore this case.
74
+ end
75
+
76
+ if ennblist
77
+ @hs_by_notebook[notebook] = ennblist
78
+ @hs_by_id[ennblist.id] = ennblist
79
+ end
80
+ ennblist
81
+ end
82
+
83
+ def post_process( dir_id )
84
+ h_ids = Currentennblist.pluck(:org_id)
85
+ t_ids = @hs_by_id.keys
86
+ ids = h_ids - t_ids
87
+ if ids.size > 0
88
+ ids.each do |idx|
89
+ Invalidennblist.create( org_id: idx , end_datetime: @register_time )
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
data/lib/en_oauth.rb ADDED
@@ -0,0 +1,314 @@
1
+ ##
2
+ # Copyright 2012 Evernote Corporation. All rights reserved.
3
+ ##
4
+
5
+ require 'sinatra'
6
+ require 'sinatra/reloader'
7
+ enable :sessions
8
+
9
+ # Load our dependencies and configuration settings
10
+ $LOAD_PATH.push(File.expand_path(File.dirname(__FILE__)))
11
+
12
+ #set :port, 4569
13
+ set :port, 4570
14
+
15
+ require "evernote_config.rb"
16
+
17
+ ##
18
+ # Verify that you have obtained an Evernote API key
19
+ ##
20
+ before do
21
+ if OAUTH_CONSUMER_KEY.empty? || OAUTH_CONSUMER_SECRET.empty?
22
+ halt '<span style="color:red">Before using this sample code you must edit evernote_config.rb and replace OAUTH_CONSUMER_KEY and OAUTH_CONSUMER_SECRET with the values that you received from Evernote. If you do not have an API key, you can request one from <a href="http://dev.evernote.com/documentation/cloud/">dev.evernote.com/documentation/cloud/</a>.</span>'
23
+ end
24
+ end
25
+
26
+ helpers do
27
+ def auth_token
28
+ session[:access_token].token if session[:access_token]
29
+ end
30
+
31
+ def client
32
+ @client ||= EvernoteOAuth::Client.new(token: auth_token, consumer_key:OAUTH_CONSUMER_KEY, consumer_secret:OAUTH_CONSUMER_SECRET, sandbox: SANDBOX)
33
+ end
34
+
35
+ def user_store
36
+ @user_store ||= client.user_store
37
+ end
38
+
39
+ def note_store
40
+ @note_store ||= client.note_store
41
+ end
42
+
43
+ def en_user
44
+ user_store.getUser(auth_token)
45
+ end
46
+
47
+ def notebooks
48
+ @notebooks ||= note_store.listNotebooks(auth_token)
49
+ end
50
+
51
+ def total_note_count
52
+ filter = Evernote::EDAM::NoteStore::NoteFilter.new
53
+ counts = note_store.findNoteCounts(auth_token, filter, false)
54
+ notebooks.inject(0) do |total_count, notebook|
55
+ total_count + (counts.notebookCounts[notebook.guid] || 0)
56
+ end
57
+ end
58
+
59
+ def notebooks_hash
60
+ @notebooks_hash ||= {}
61
+ if @notebooks_hash.size != notebooks.size
62
+ notebooks.each do |x|
63
+ @notebooks_hash[x.name] = x
64
+ end
65
+ end
66
+ @notebooks_hash
67
+ end
68
+
69
+ def notes(guid)
70
+ filter = Evernote::EDAM::NoteStore::NoteFilter.new
71
+ # filter.notebookGuid = @notebook.guid
72
+ filter.notebookGuid = guid
73
+ @found_n = note_store.findNotes(auth_token, filter, 0 , 100 )
74
+ # @found_notes = @found_n.notes
75
+ @found_n.notes
76
+ end
77
+ end
78
+
79
+ ##
80
+ # Index page
81
+ ##
82
+ get '/' do
83
+ erb :index
84
+ end
85
+
86
+ ##
87
+ # Reset the session
88
+ ##
89
+ get '/reset' do
90
+ session.clear
91
+ redirect '/'
92
+ end
93
+
94
+ ##
95
+ # Obtain temporary credentials
96
+ ##
97
+ get '/requesttoken' do
98
+ callback_url = request.url.chomp("requesttoken").concat("callback")
99
+ begin
100
+ session[:request_token] = client.request_token(:oauth_callback => callback_url)
101
+ redirect '/authorize'
102
+ rescue => e
103
+ @last_error = "3 Error obtaining temporary credentials: #{e.message}"
104
+ erb :error
105
+ end
106
+ end
107
+
108
+ ##
109
+ # Redirect the user to Evernote for authoriation
110
+ ##
111
+ get '/authorize' do
112
+ if session[:request_token]
113
+ redirect session[:request_token].authorize_url
114
+ else
115
+ # You shouldn't be invoking this if you don't have a request token
116
+ @last_error = "Request token not set."
117
+ erb :error
118
+ end
119
+ end
120
+
121
+ ##
122
+ # Receive callback from the Evernote authorization page
123
+ ##
124
+ get '/callback' do
125
+ unless params['oauth_verifier'] || session['request_token']
126
+ @last_error = "Content owner did not authorize the temporary credentials"
127
+ halt erb :error
128
+ end
129
+ session[:oauth_verifier] = params['oauth_verifier']
130
+ begin
131
+ session[:access_token] = session[:request_token].get_access_token(:oauth_verifier => session[:oauth_verifier])
132
+ redirect '/list'
133
+ rescue => e
134
+ @last_error = '2 Error extracting access token'
135
+ erb :error
136
+ end
137
+ end
138
+
139
+
140
+ ##
141
+ # Access the user's Evernote account and display account data
142
+ ##
143
+ get '/list' do
144
+ begin
145
+ # Get notebooks
146
+ session[:notebooks] = notebooks.collect{ |notebook|
147
+ [ notebook.name , notebook.guid ]
148
+ }
149
+ # session[:notebooks] = notebooks.map(&:name)
150
+ # Get username
151
+ session[:username] = en_user.username
152
+ # Get total note count
153
+ session[:total_notes] = total_note_count
154
+ erb :index
155
+ rescue => e
156
+ # @last_error = "Error listing notebooks: #{e.message}"
157
+ @last_error = "1 Error listing notebooks: #{e}"
158
+ erb :error
159
+ end
160
+ end
161
+
162
+ ##
163
+ #
164
+ ##
165
+ get '/notebook/:name/:guid' do
166
+ begin
167
+ session[:notebook_name] = params[:name]
168
+ session[:notebook_guid] = params[:guid]
169
+
170
+ # @notebook = notebooks_hash[ params[:name] ]
171
+ @found_notes = notes( params[:guid] )
172
+
173
+ erb :notes
174
+ rescue => e
175
+ @last_error = "0 Error listing notebook: #{e.message}"
176
+ erb :error
177
+ end
178
+ end
179
+
180
+ get '/create_note/:name/:guid' do
181
+ begin
182
+ ENML_HEADER = <<HEADER
183
+ <?xml version="1.0" encoding="UTF-8"?>
184
+ <!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">
185
+ HEADER
186
+
187
+ note_content = <<CONTENT
188
+ #{ENML_HEADER}
189
+ <en-note>Hello, my Evernote (from Ruby)!</en-note>
190
+ CONTENT
191
+
192
+ note = Evernote::EDAM::Type::Note.new
193
+ note.title = "Note Title"
194
+ note.notebookGuid = params[:guid]
195
+ note.content = note_content
196
+ note_store.createNote( auth_token , note)
197
+ @found_notes = notes(session[:notebook_guid])
198
+
199
+ erb :notes
200
+ rescue => e
201
+ @last_error = "0 Error listing notebook: #{e.message}"
202
+ erb :error
203
+ end
204
+ end
205
+
206
+
207
+ __END__
208
+
209
+ @@ index
210
+ <html>
211
+ <head>
212
+ <title>Evernote Ruby Example App</title>
213
+ </head>
214
+ <body>
215
+ <a href="/requesttoken">Click here</a> to authenticate this application using OAuth.
216
+ <% if session[:notebooks] %>
217
+ <hr />
218
+ <h3>The current user is <%= session[:username] %> and there are <%= session[:total_notes] %> notes in their account</h3>
219
+ <br />
220
+ <h3>Here are the notebooks in this account:</h3>
221
+ <ul>
222
+ <% session[:notebooks].each do |notebook| %>
223
+ <% p session[:notebooks] %>
224
+ <li><a href="/notebook/<%= notebook[0] %>/<%= notebook[1] %>"><%= notebook[0] %></a></li>
225
+ <% end %>
226
+ </ul>
227
+ <% end %>
228
+ </body>
229
+ </html>
230
+
231
+ @@ error
232
+ <html>
233
+ <head>
234
+ <title>Evernote Ruby Example App &mdash; Error</title>
235
+ </head>
236
+ <body>
237
+ <p>An error occurred: <%= @last_error %></p>
238
+ <p>Please <a href="/reset">start over</a>.</p>
239
+ </body>
240
+ </html>
241
+
242
+ @@ notebook
243
+ <html>
244
+ <head>
245
+ </head>
246
+ <body>
247
+ <table>
248
+ <% @found_notes.collect do |x| %>
249
+ <tr>
250
+ <td>
251
+ <%= x.guid %>
252
+ </td>
253
+ <td>
254
+ <%= x.title %>
255
+ </td>
256
+ </tr>
257
+ <% end %>
258
+ </table>
259
+ <form action="/create_note" method="get">
260
+ <input type="text" name="val" value="1">
261
+ <input type="submit" value="Create Note">
262
+ </form>
263
+ </body>
264
+ </html>
265
+
266
+ @@ notes
267
+ <html>
268
+ <head>
269
+ </head>
270
+ <body>
271
+ <table>
272
+ <% @found_notes.collect do |x| %>
273
+ <tr>
274
+ <td>
275
+ <%= x.guid %>
276
+ </td>
277
+ <td>
278
+ <%= x.title %>
279
+ </td>
280
+ </tr>
281
+ <% end %>
282
+ </table>
283
+ <form action="/create_note/<%= session[:notebook_name] %>/<%= session[:notebook_guid] %>" method="get">
284
+ <input type="text" name="val" value="1">
285
+ <input type="submit" value="Create Note">
286
+ </form>
287
+ </body>
288
+ </html>
289
+
290
+ @@ notebook1
291
+ <html>
292
+ <head>
293
+ </head>
294
+ <body>
295
+ Notebook<p>
296
+ <%= p @notebook.class %><p>
297
+ <%= p @found_n.class %><p>
298
+ <%= p @found_notes.class %><p>
299
+ <ul>
300
+ <% p @found_notes; @found_notes.each do |note| %>
301
+ <li><a href="/note/<%= note.name %>/<%= note.guid %>"><%= note.name %></li>
302
+ <% end %>
303
+ </ul>
304
+ </body>
305
+ </html>
306
+
307
+ @@ note
308
+ <html>
309
+ <head>
310
+ </head>
311
+ <body>
312
+
313
+ </body>
314
+ </html>
data/lib/ennb.rb ADDED
@@ -0,0 +1,149 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'evernote-thrift'
4
+ require 'csv'
5
+ require 'pp'
6
+
7
+ require 'forwardable'
8
+ require 'dbutil_base'
9
+ require 'dbutil_ennblist'
10
+
11
+ class Ennb
12
+ extend Forwardable
13
+
14
+ def_delegator( :@dbmgr , :add , :db_add)
15
+
16
+ def initialize
17
+ @sqlite3yaml = 'config/sqlite3.yaml'
18
+ @databaselog = 'db/database.log'
19
+
20
+ @stack_hs = {}
21
+ @nbinfos = {}
22
+ @notebookinfo = Struct.new("NotebookInfo", :name, :stack, :defaultNotebook, :count , :tags )
23
+
24
+ @authToken = "S=s18:U=1f38cb:E=15110796cd9:C=149b8c83d38:P=1cd:A=en-devtoken:V=2:H=970049a2b990ad5e0f58252a626539b0"
25
+
26
+ evernoteHost = "www.evernote.com"
27
+ userStoreUrl = "https://#{evernoteHost}/edam/user"
28
+ userStoreTransport = Thrift::HTTPClientTransport.new(userStoreUrl)
29
+ userStoreProtocol = Thrift::BinaryProtocol.new(userStoreTransport)
30
+ @userStore = Evernote::EDAM::UserStore::UserStore::Client.new(userStoreProtocol)
31
+
32
+ versionOK = @userStore.checkVersion("Evernote EDAMTest (Ruby)",
33
+ Evernote::EDAM::UserStore::EDAM_VERSION_MAJOR,
34
+ Evernote::EDAM::UserStore::EDAM_VERSION_MINOR)
35
+ puts "Is my Evernote API version up to date? #{versionOK}"
36
+ puts
37
+ exit(1) unless versionOK
38
+
39
+ set_output_dest( get_output_filename_base )
40
+
41
+ dbx
42
+ end
43
+
44
+ def dbx
45
+ @dbmgr = Dbutil::DbMgr.init( @sqlite3yaml , @databaselog )
46
+ end
47
+
48
+ def set_output_dest( fname )
49
+ if fname
50
+ fname_txt = fname + ".txt"
51
+ fname_csv = fname + ".csv"
52
+ @output = File.open( fname_txt , "w" , { :encoding => 'UTF-8' } )
53
+ @output_csv = CSV.open( fname_csv , "w" , { :encoding => 'UTF-8' } )
54
+ else
55
+ @output = STDOUT
56
+ end
57
+ end
58
+
59
+ def get_output_filename_base
60
+ Time.now.strftime("ennblist-%Y-%m-%d-%H-%M-%S")
61
+ end
62
+
63
+ def putsx( str )
64
+ @output.puts( str )
65
+ end
66
+
67
+ def connect
68
+ # Get the URL used to interact with the contents of the user's account
69
+ # When your application authenticates using OAuth, the NoteStore URL will
70
+ # be returned along with the auth token in the final OAuth request.
71
+ # In that case, you don't need to make this call.
72
+ #noteStoreUrl = userStore.getNoteStoreUrl(authToken)
73
+ noteStoreUrl = "https://www.evernote.com/shard/s18/notestore"
74
+
75
+ noteStoreTransport = Thrift::HTTPClientTransport.new(noteStoreUrl)
76
+ noteStoreProtocol = Thrift::BinaryProtocol.new(noteStoreTransport)
77
+ @noteStore = Evernote::EDAM::NoteStore::NoteStore::Client.new(noteStoreProtocol)
78
+ end
79
+
80
+ def list_notebooks
81
+ # List all of the notebooks in the user's account
82
+ filter = Evernote::EDAM::NoteStore::NoteFilter.new
83
+
84
+ begin
85
+ notebooks = @noteStore.listNotebooks(@authToken)
86
+ rescue => ex
87
+ puts "Can't call listNotebooks"
88
+ exit
89
+ end
90
+
91
+ puts "Found #{notebooks.size} notebooks:"
92
+ memo = notebooks.inject({:defaultNotebook => nil , :nbinfo => []}) do |memo , notebook|
93
+ notebook_name = ( notebook.name == nil ? "" : notebook.name )
94
+ stack_name = ( notebook.stack == nil ? "" : notebook.stack )
95
+
96
+ filter.notebookGuid = notebook.guid
97
+
98
+ ret = nil
99
+ begin
100
+ ret = @noteStore.findNoteCounts(@authToken , filter , false )
101
+ rescue => ex
102
+ puts "Can't call findNoteCounts with #{notebook_name}"
103
+ end
104
+
105
+ if ret
106
+ if ret.notebookCounts
107
+ notebookCounts = ret.notebookCounts[notebook.guid]
108
+ else
109
+ notebookCounts = 0
110
+ end
111
+ tagcount = 0
112
+ if ret.tagCounts
113
+ tagcount = ret.tagCounts.size
114
+ end
115
+ nbinfo = @notebookinfo.new( notebook_name , stack_name , notebook.defaultNotebook , notebookCounts , tagcount )
116
+ # CSVファイルへ追加(自動的に出力)
117
+ register_notebook( nbinfo.stack , nbinfo )
118
+ # dbへの登録
119
+ db_add( nbinfo.stack , nbinfo.name , nbinfo.count , nbinfo.tags.size )
120
+
121
+ # p notebook
122
+ memo[:defaultNotebook] = nbinfo if nbinfo.defaultNotebook
123
+ memo[:nbinfo] << nbinfo
124
+ end
125
+
126
+ memo
127
+ end
128
+
129
+ @stack_hs.keys.sort.each do |k|
130
+ # TXTファイルに出力
131
+ putsx "#{k},#{@stack_hs[k]}"
132
+ end
133
+
134
+ pp memo[:defaultNotebook]
135
+ end
136
+
137
+ def register_notebook( stack , nbinfo )
138
+ @stack_hs[stack] ||= []
139
+ @stack_hs[stack] << nbinfo
140
+ @nbinfos[nbinfo.name] = nbinfo
141
+
142
+ @output_csv << [ stack , nbinfo.name , nbinfo.count ]
143
+ end
144
+ end
145
+
146
+ ennb = Ennb.new
147
+ ennb.connect
148
+ ennb.list_notebooks
149
+
data/lib/enop.rb ADDED
@@ -0,0 +1,144 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require "enop/version"
4
+
5
+ require 'evernote-thrift'
6
+ require 'csv'
7
+ require 'pp'
8
+
9
+ require 'forwardable'
10
+ require 'dbutil_base'
11
+ require 'dbutil_enop'
12
+
13
+ module Enop
14
+ class Enop
15
+ extend Forwardable
16
+
17
+ def_delegator( :@dbmgr , :add , :db_add)
18
+
19
+ def initialize( db_dir , migrate_dir , config_dir, dbconfig , log_fname , authToken)
20
+
21
+ @stack_hs = {}
22
+ @nbinfos = {}
23
+ @notebookinfo = Struct.new("NotebookInfo", :name, :stack, :defaultNotebook, :count , :tags )
24
+
25
+ @authToken = authToken
26
+
27
+ register_time = Arxutils::Dbutil::DbMgr.init( db_dir , migrate_dir , config_dir, dbconfig , log_fname )
28
+
29
+ @dbmgr = Dbutil::DbMgr.new( register_time )
30
+
31
+ evernoteHost = "www.evernote.com"
32
+ userStoreUrl = "https://#{evernoteHost}/edam/user"
33
+ userStoreTransport = Thrift::HTTPClientTransport.new(userStoreUrl)
34
+ userStoreProtocol = Thrift::BinaryProtocol.new(userStoreTransport)
35
+ @userStore = Evernote::EDAM::UserStore::UserStore::Client.new(userStoreProtocol)
36
+
37
+ versionOK = @userStore.checkVersion("Evernote EDAMTest (Ruby)",
38
+ Evernote::EDAM::UserStore::EDAM_VERSION_MAJOR,
39
+ Evernote::EDAM::UserStore::EDAM_VERSION_MINOR)
40
+ puts "Is my Evernote API version up to date? #{versionOK}"
41
+ puts
42
+ exit(1) unless versionOK
43
+
44
+ set_output_dest( get_output_filename_base )
45
+ end
46
+
47
+ def set_output_dest( fname )
48
+ if fname
49
+ fname_txt = fname + ".txt"
50
+ fname_csv = fname + ".csv"
51
+ @output = File.open( fname_txt , "w" , { :encoding => 'UTF-8' } )
52
+ @output_csv = CSV.open( fname_csv , "w" , { :encoding => 'UTF-8' } )
53
+ else
54
+ @output = STDOUT
55
+ end
56
+ end
57
+
58
+ def get_output_filename_base
59
+ Time.now.strftime("ennblist-%Y-%m-%d-%H-%M-%S")
60
+ end
61
+
62
+ def putsx( str )
63
+ @output.puts( str )
64
+ end
65
+
66
+ def connect
67
+ # Get the URL used to interact with the contents of the user's account
68
+ # When your application authenticates using OAuth, the NoteStore URL will
69
+ # be returned along with the auth token in the final OAuth request.
70
+ # In that case, you don't need to make this call.
71
+ #noteStoreUrl = userStore.getNoteStoreUrl(authToken)
72
+ noteStoreUrl = "https://www.evernote.com/shard/s18/notestore"
73
+
74
+ noteStoreTransport = Thrift::HTTPClientTransport.new(noteStoreUrl)
75
+ noteStoreProtocol = Thrift::BinaryProtocol.new(noteStoreTransport)
76
+ @noteStore = Evernote::EDAM::NoteStore::NoteStore::Client.new(noteStoreProtocol)
77
+ end
78
+
79
+ def list_notebooks
80
+ # List all of the notebooks in the user's account
81
+ filter = Evernote::EDAM::NoteStore::NoteFilter.new
82
+
83
+ begin
84
+ notebooks = @noteStore.listNotebooks(@authToken)
85
+ rescue => ex
86
+ puts "Can't call listNotebooks"
87
+ exit
88
+ end
89
+
90
+ puts "Found #{notebooks.size} notebooks:"
91
+ memo = notebooks.inject({:defaultNotebook => nil , :nbinfo => []}) do |memo , notebook|
92
+ notebook_name = ( notebook.name == nil ? "" : notebook.name )
93
+ stack_name = ( notebook.stack == nil ? "" : notebook.stack )
94
+
95
+ filter.notebookGuid = notebook.guid
96
+
97
+ ret = nil
98
+ begin
99
+ ret = @noteStore.findNoteCounts(@authToken , filter , false )
100
+ rescue => ex
101
+ puts "Can't call findNoteCounts with #{notebook_name}"
102
+ end
103
+
104
+ if ret
105
+ if ret.notebookCounts
106
+ notebookCounts = ret.notebookCounts[notebook.guid]
107
+ else
108
+ notebookCounts = 0
109
+ end
110
+ tagcount = 0
111
+ if ret.tagCounts
112
+ tagcount = ret.tagCounts.size
113
+ end
114
+ nbinfo = @notebookinfo.new( notebook_name , stack_name , notebook.defaultNotebook , notebookCounts , tagcount )
115
+ # CSVファイルへ追加(自動的に出力)
116
+ register_notebook( nbinfo.stack , nbinfo )
117
+ # dbへの登録
118
+ db_add( nbinfo.stack , nbinfo.name , nbinfo.count , nbinfo.tags.size )
119
+
120
+ # p notebook
121
+ memo[:defaultNotebook] = nbinfo if nbinfo.defaultNotebook
122
+ memo[:nbinfo] << nbinfo
123
+ end
124
+
125
+ memo
126
+ end
127
+
128
+ @stack_hs.keys.sort.each do |k|
129
+ # TXTファイルに出力
130
+ putsx "#{k},#{@stack_hs[k]}"
131
+ end
132
+
133
+ pp memo[:defaultNotebook]
134
+ end
135
+
136
+ def register_notebook( stack , nbinfo )
137
+ @stack_hs[stack] ||= []
138
+ @stack_hs[stack] << nbinfo
139
+ @nbinfos[nbinfo.name] = nbinfo
140
+
141
+ @output_csv << [ stack , nbinfo.name , nbinfo.count ]
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,3 @@
1
+ module Enop
2
+ VERSION = "0.1.3"
3
+ end
@@ -0,0 +1,16 @@
1
+ # Load libraries required by the Evernote OAuth sample applications
2
+ require 'oauth'
3
+ require 'oauth/consumer'
4
+
5
+ # Load Thrift & Evernote Ruby libraries
6
+ require "evernote_oauth"
7
+
8
+ # Client credentials
9
+ # Fill these in with the consumer key and consumer secret that you obtained
10
+ # from Evernote. If you do not have an Evernote API key, you may request one
11
+ # from http://dev.evernote.com/documentation/cloud/
12
+ OAUTH_CONSUMER_KEY = "ykominami-1-0694"
13
+ OAUTH_CONSUMER_SECRET = "a53c21b9fe88db96"
14
+
15
+ #SANDBOX = true
16
+ SANDBOX = false
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: enop
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - yasuo kominami
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: evernote_oauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activerecord
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sqlite3
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: arxutils
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: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '1.10'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '1.10'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: evernote operation.
112
+ email:
113
+ - ykominami@gmail.com
114
+ executables:
115
+ - enop
116
+ - makemigrate
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - .gitignore
121
+ - .rspec
122
+ - .travis.yml
123
+ - Gemfile
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/setup
128
+ - enop.gemspec
129
+ - exe/enop
130
+ - exe/makemigrate
131
+ - lib/dbutil_enop.rb
132
+ - lib/en_oauth.rb
133
+ - lib/ennb.rb
134
+ - lib/enop.rb
135
+ - lib/enop/version.rb
136
+ - lib/evernote_config.rb
137
+ homepage: ''
138
+ licenses: []
139
+ metadata: {}
140
+ post_install_message:
141
+ rdoc_options: []
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - '>='
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - '>='
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 2.4.8
157
+ signing_key:
158
+ specification_version: 4
159
+ summary: evernote operation.
160
+ test_files: []