gspush 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +43 -0
- data/Rakefile +2 -0
- data/bin/gspush +5 -0
- data/gspush.gemspec +20 -0
- data/lib/gspush/version.rb +3 -0
- data/lib/gspush.rb +108 -0
- data/spec/gspush_spec.rb +48 -0
- metadata +89 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 HORII Keima
|
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,43 @@
|
|
1
|
+
# Gspush
|
2
|
+
|
3
|
+
gspush: pushing data to google spreadsheet command line interface
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'gspush'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install gspush
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
typical usage to batch process
|
22
|
+
|
23
|
+
```sh
|
24
|
+
url=(YOUR SPREADSHEET URL)
|
25
|
+
user=(YOUR SPREADSHEET EMAIL ADDRESS)
|
26
|
+
pass=(YOUR PASSWORD) # FIXME
|
27
|
+
datetime=`date +%Y%m%d %H:00:00`
|
28
|
+
num1=123
|
29
|
+
num2=456
|
30
|
+
num3=789
|
31
|
+
|
32
|
+
echo $datetime $num1 $num2 $num3 | gspush $url -u $user -p $pass
|
33
|
+
```
|
34
|
+
|
35
|
+
then append your numbers to the spreadsheet
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
1. Fork it
|
40
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
41
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
42
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
43
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/gspush
ADDED
data/gspush.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/gspush/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["HORII Keima"]
|
6
|
+
gem.email = ["holysugar@gmail.com"]
|
7
|
+
gem.description = %q{Push command to Google Spreadsheet}
|
8
|
+
gem.summary = %q{Phsh command to Google Spreadsheet}
|
9
|
+
gem.homepage = "https://github.com/holysugar/gspush"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "gspush"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Gspush::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency "google_drive"
|
19
|
+
gem.add_development_dependency "rspec"
|
20
|
+
end
|
data/lib/gspush.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'google_drive'
|
3
|
+
|
4
|
+
require_relative './gspush/version'
|
5
|
+
|
6
|
+
class Gspush
|
7
|
+
class WorksheetNotFound < StandardError; end
|
8
|
+
|
9
|
+
attr_reader :url, :delimiter, :lines
|
10
|
+
|
11
|
+
def initialize(url, options = {})
|
12
|
+
@url = url
|
13
|
+
|
14
|
+
@delimiter = options[:delimiter]
|
15
|
+
@nullpush = options[:nullpush]
|
16
|
+
@username = options[:username]
|
17
|
+
@password = options[:password]
|
18
|
+
|
19
|
+
@prepend_timestamp = options[:prepend_timestamp]
|
20
|
+
@sheet_title = options[:sheet_title]
|
21
|
+
|
22
|
+
@lines = []
|
23
|
+
end
|
24
|
+
|
25
|
+
def push(line)
|
26
|
+
@lines.push line
|
27
|
+
end
|
28
|
+
|
29
|
+
def parse_lines
|
30
|
+
now = Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
31
|
+
@lines.each_with_object([]) {|line, obj|
|
32
|
+
values = separate(line)
|
33
|
+
if @prepend_timestamp
|
34
|
+
values.unshift(now)
|
35
|
+
end
|
36
|
+
unless values.empty?
|
37
|
+
obj << values
|
38
|
+
end
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def save
|
43
|
+
spreadsheet = open(@url, @username, @password)
|
44
|
+
|
45
|
+
sheet = select_worksheet(spreadsheet)
|
46
|
+
raise WorksheetNotFound if sheet.nil?
|
47
|
+
update(sheet, parse_lines)
|
48
|
+
end
|
49
|
+
|
50
|
+
def separate(line)
|
51
|
+
line.split(@delimiter)
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def open(url, username, password)
|
57
|
+
session = GoogleDrive.login(username, password)
|
58
|
+
spreadsheet = session.spreadsheet_by_url(url)
|
59
|
+
end
|
60
|
+
|
61
|
+
def select_worksheet(spreadsheet)
|
62
|
+
if @sheet_title
|
63
|
+
spreadsheet.worksheet_by_title(@sheet_title)
|
64
|
+
else
|
65
|
+
spreadsheet.worksheets.first
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def update(sheet, lines)
|
70
|
+
sheet.update_cells(sheet.num_rows+1, 1, lines)
|
71
|
+
sheet.save
|
72
|
+
end
|
73
|
+
|
74
|
+
class CLI
|
75
|
+
def self.execute(argv)
|
76
|
+
argv, options = parse_option(argv)
|
77
|
+
|
78
|
+
gspush = Gspush.new(argv[0], options)
|
79
|
+
while line = $stdin.gets # FIXME
|
80
|
+
gspush.push(line)
|
81
|
+
end
|
82
|
+
gspush.save
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.parse_option(argv_original)
|
86
|
+
options = {}
|
87
|
+
|
88
|
+
opt = OptionParser.new
|
89
|
+
opt.on('-d delim', 'input delimiter') {|v| options[:delimiter] = v }
|
90
|
+
opt.on('-u username', 'Google Drive username(email)') {|v| options[:username] = v }
|
91
|
+
opt.on('-p password', 'user password') {|v| options[:password] = v } # XXX how should i get this?
|
92
|
+
opt.on('-s sheet_title', 'worksheet title (default: first worksheet)') {|v| options[:sheet_title] = v }
|
93
|
+
opt.on('-t', 'prepend timestamp cell') {|v| options[:prepend_timestamp] = v }
|
94
|
+
|
95
|
+
opt.banner = "Usage: gspush URL [options]"
|
96
|
+
opt.version = Gspush::VERSION
|
97
|
+
|
98
|
+
argv = opt.parse(argv_original)
|
99
|
+
|
100
|
+
if argv.empty?
|
101
|
+
puts opt.banner
|
102
|
+
exit 1
|
103
|
+
end
|
104
|
+
|
105
|
+
[argv, options]
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
data/spec/gspush_spec.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'gspush'
|
2
|
+
|
3
|
+
describe Gspush do
|
4
|
+
let(:url) { 'http://example.com/ '} # FIXME
|
5
|
+
let(:gspush) { Gspush.new(url) }
|
6
|
+
|
7
|
+
describe "#push" do
|
8
|
+
it "append gspush.lines" do
|
9
|
+
expect { gspush.push "values 999" }.to change{ gspush.lines.size }.by(1)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#parse_lines" do
|
14
|
+
before do
|
15
|
+
gspush.push "foo 123"
|
16
|
+
gspush.push "bar 456"
|
17
|
+
gspush.push "baz 789"
|
18
|
+
end
|
19
|
+
|
20
|
+
subject { gspush.parse_lines }
|
21
|
+
it { should == [['foo', '123'], ['bar', '456'], ['baz', '789']] }
|
22
|
+
|
23
|
+
context 'with prepend_timestamp option' do
|
24
|
+
let(:gspush) { Gspush.new(url, :prepend_timestamp => true) }
|
25
|
+
specify "time prepended" do
|
26
|
+
subject[0][0].should match(/\d{4}-\d\d-\d\d \d\d:\d\d:\d\d/)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#save" do
|
32
|
+
it "update spreadsheet"
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "separate" do
|
36
|
+
context "without delimiter option" do
|
37
|
+
it "separates in blank" do
|
38
|
+
gspush.separate("0 bar,1 baz").should == ["0", "bar,1", "baz"]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
context "with delimiter option" do
|
42
|
+
let(:gspush) { Gspush.new(url, :delimiter => ",") }
|
43
|
+
it "separates in given delimter" do
|
44
|
+
gspush.separate("0 bar,1 baz").should == ["0 bar", "1 baz"]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gspush
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- HORII Keima
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: google_drive
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Push command to Google Spreadsheet
|
47
|
+
email:
|
48
|
+
- holysugar@gmail.com
|
49
|
+
executables:
|
50
|
+
- gspush
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- bin/gspush
|
60
|
+
- gspush.gemspec
|
61
|
+
- lib/gspush.rb
|
62
|
+
- lib/gspush/version.rb
|
63
|
+
- spec/gspush_spec.rb
|
64
|
+
homepage: https://github.com/holysugar/gspush
|
65
|
+
licenses: []
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 1.8.24
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: Phsh command to Google Spreadsheet
|
88
|
+
test_files:
|
89
|
+
- spec/gspush_spec.rb
|