harvest_wheelman 0.0.1 → 1.0.0
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 +1 -0
- data/README.md +0 -31
- data/bin/harvest_wheelman +45 -22
- data/harvest_wheelman.gemspec +1 -1
- data/lib/harvest_submit.rb +64 -18
- data/lib/harvest_wheelman/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4024eb4f75db002fb29a9ef766f7dcdd596ab4a
|
4
|
+
data.tar.gz: 3e9193ec68b32f41ecd4cac141676b1f9a3d0eb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93d61f4fcb80b44a049fe4560ddad053c32580f37d7eded0f187ca2ac3069540d38850bf84c9f6058dc67e85c4529c34f61fcb653914fee1daccc89ccb40788e
|
7
|
+
data.tar.gz: 7aa4e52c19d9f811e91e5514b97bd23237d292059728b7d6aea83922cb9d5901c69cfd7837d29d2b6822150f52d90d2aa5559f94be72fcc5eff472d77c7defef
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -4,43 +4,12 @@ I use this tool every 2 weeks to generate a PDF timesheet report from Harvest th
|
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
gem 'harvest_wheelman'
|
10
|
-
|
11
|
-
And then execute:
|
12
|
-
|
13
|
-
$ bundle
|
14
|
-
|
15
|
-
Or install it yourself as:
|
16
|
-
|
17
7
|
$ gem install harvest_wheelman
|
18
8
|
|
19
9
|
## Usage
|
20
10
|
|
21
11
|
`harvest_wheelman`
|
22
12
|
|
23
|
-
Optionally you can pass in a settings file like this:
|
24
|
-
|
25
|
-
`harvest_wheelman ~/MyStuff/harvest_Wheelman.json`
|
26
|
-
|
27
|
-
## Example Settings File
|
28
|
-
|
29
|
-
```json
|
30
|
-
{
|
31
|
-
"harvest":{
|
32
|
-
"site":"---",
|
33
|
-
"user":"---",
|
34
|
-
"pass":"---"
|
35
|
-
},
|
36
|
-
"pay_period":{
|
37
|
-
"weeks":2, # weeks in a pay period; used when only 1 date given (optional and defaults to 2)
|
38
|
-
"from":"09/03/2012", # start of pay period (optional if 'to' exists)
|
39
|
-
"to":"09/16/2012" # end of pay period (optional if 'from' exists)
|
40
|
-
}
|
41
|
-
}
|
42
|
-
```
|
43
|
-
|
44
13
|
## Contributing
|
45
14
|
|
46
15
|
1. Fork it
|
data/bin/harvest_wheelman
CHANGED
@@ -1,35 +1,58 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'harvest_wheelman'
|
3
|
+
require 'optparse'
|
3
4
|
|
4
|
-
|
5
|
+
EXAMPLE = %{{
|
6
|
+
"harvest":{
|
7
|
+
"site":"---",
|
8
|
+
"user":"---",
|
9
|
+
"pass":"---"
|
10
|
+
}
|
11
|
+
}}
|
12
|
+
|
13
|
+
SETTINGS_HELP = %{#{EXAMPLE}
|
14
|
+
|
15
|
+
Optionally include a "pay_period" block, otherwise we automatically use
|
16
|
+
a 2 week pay period where "to" is set to the closest Sunday to today.
|
17
|
+
|
18
|
+
{
|
19
|
+
"harvest": { ... },
|
20
|
+
"pay_period":{
|
21
|
+
"weeks":2,
|
22
|
+
"from":"09/03/2012",
|
23
|
+
"to":"09/16/2012"
|
24
|
+
}
|
25
|
+
}}
|
26
|
+
|
27
|
+
SETTINGS_FILE = File.join(File.expand_path('~'), '.harvest_wheelman')
|
28
|
+
if !File.exists? SETTINGS_FILE
|
29
|
+
File.open(SETTINGS_FILE, 'w') do |f|
|
30
|
+
f.write EXAMPLE
|
31
|
+
end
|
32
|
+
puts "Wrote to #{SETTINGS_FILE}"
|
33
|
+
puts SETTINGS_HELP
|
34
|
+
exit(0)
|
35
|
+
end
|
5
36
|
|
6
37
|
begin
|
7
38
|
hs = HarvestWheelman::HarvestSubmit.new(SETTINGS_FILE)
|
8
39
|
puts %{
|
9
40
|
Pay period is set from: #{hs.from}
|
10
41
|
to: #{hs.to}
|
11
|
-
Press enter to open
|
42
|
+
Press enter to open chrome and generate the PDF using these dates.
|
12
43
|
Ctrl-C to quit.
|
13
44
|
}
|
14
45
|
puts hs.drive_to_pdf if STDIN.gets
|
15
46
|
rescue => ex
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
"weeks":2, # weeks in a pay period (defaults to 2), used when only 1 date given
|
29
|
-
"from":"09/03/2012", # start of pay period
|
30
|
-
"to":"09/16/2012" # end of pay period
|
31
|
-
}
|
32
|
-
}
|
33
|
-
}
|
34
|
-
puts "There was a problem!\n#{ex.backtrace.join("\n")}\n\n#{ex.message}"
|
35
|
-
end
|
47
|
+
puts <<-EOF
|
48
|
+
Could not start, check your settings file.
|
49
|
+
Settings file path: #{SETTINGS_FILE}
|
50
|
+
|
51
|
+
Example:
|
52
|
+
#{SETTINGS_HELP}
|
53
|
+
|
54
|
+
Error: #{ex.message}
|
55
|
+
------------------
|
56
|
+
#{ex.backtrace.join("\n")}
|
57
|
+
EOF
|
58
|
+
end
|
data/harvest_wheelman.gemspec
CHANGED
data/lib/harvest_submit.rb
CHANGED
@@ -6,7 +6,24 @@ require 'timerizer'
|
|
6
6
|
# Puts +str+ into the pasteboard (Mac only)
|
7
7
|
def pbcopy(str)
|
8
8
|
return unless RUBY_PLATFORM =~ /darwin/
|
9
|
-
`echo "#{str}" | pbcopy`
|
9
|
+
`echo "#{str.strip}" | pbcopy`
|
10
|
+
end
|
11
|
+
|
12
|
+
class Date
|
13
|
+
def self.nearest_sunday
|
14
|
+
date = Date.today
|
15
|
+
wday = date.wday
|
16
|
+
if wday >= 4
|
17
|
+
wday.upto(6) do
|
18
|
+
date = 1.day.after(date)
|
19
|
+
end
|
20
|
+
elsif wday <= 3
|
21
|
+
wday.downto(1) do
|
22
|
+
date = 1.day.before(date)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
return date
|
26
|
+
end
|
10
27
|
end
|
11
28
|
|
12
29
|
module HarvestWheelman
|
@@ -20,13 +37,17 @@ module HarvestWheelman
|
|
20
37
|
File.open(settings_file) do |f|
|
21
38
|
@settings = JSON.parse(f.read)
|
22
39
|
end
|
40
|
+
if not @settings['pay_period']
|
41
|
+
@ppw = 2
|
42
|
+
@to = date_to_string Date.nearest_sunday
|
43
|
+
end
|
23
44
|
determine_time_interval!
|
24
45
|
end
|
25
46
|
|
26
47
|
##
|
27
48
|
# Pay period weeks
|
28
49
|
def ppw
|
29
|
-
@ppw ||= @settings['pay_period']['weeks']
|
50
|
+
@ppw ||= @settings['pay_period']['weeks'] rescue 2
|
30
51
|
end
|
31
52
|
|
32
53
|
def determine_time_interval!
|
@@ -37,7 +58,7 @@ module HarvestWheelman
|
|
37
58
|
@to = date_to_string(1.day.before(ppw.weeks.after(string_to_date(from))))
|
38
59
|
end
|
39
60
|
elsif date_valid? to
|
40
|
-
puts "Setting FROM via the TO based on a ppw week pay period"
|
61
|
+
puts "Setting FROM via the TO based on a #{ppw} week pay period"
|
41
62
|
@from = date_to_string(1.day.after(ppw.weeks.before(string_to_date(to))))
|
42
63
|
else
|
43
64
|
raise UnknownTimeIntervalError
|
@@ -62,11 +83,11 @@ module HarvestWheelman
|
|
62
83
|
end
|
63
84
|
|
64
85
|
def from
|
65
|
-
@from ||= @settings['pay_period']['from']
|
86
|
+
@from ||= @settings['pay_period']['from'] rescue nil
|
66
87
|
end
|
67
88
|
|
68
89
|
def to
|
69
|
-
@to ||= @settings['pay_period']['to']
|
90
|
+
@to ||= @settings['pay_period']['to'] rescue nil
|
70
91
|
end
|
71
92
|
|
72
93
|
def site
|
@@ -82,7 +103,7 @@ module HarvestWheelman
|
|
82
103
|
end
|
83
104
|
|
84
105
|
def whoami
|
85
|
-
`whoami`.strip
|
106
|
+
`whoami`.strip.capitalize
|
86
107
|
end
|
87
108
|
|
88
109
|
def pdf_name
|
@@ -94,50 +115,75 @@ module HarvestWheelman
|
|
94
115
|
end
|
95
116
|
|
96
117
|
def body
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
118
|
+
<<-EOF
|
119
|
+
Hello,
|
120
|
+
Attached is my timesheet for pay period #{from} - #{to}
|
121
|
+
|
122
|
+
Thank you,
|
123
|
+
#{whoami}
|
124
|
+
|
125
|
+
Generated using http://rubygems.org/gems/harvest_wheelman
|
126
|
+
Version #{HarvestWheelman::VERSION}
|
127
|
+
EOF
|
101
128
|
end
|
102
129
|
|
103
130
|
def drive_to_pdf
|
104
131
|
begin
|
105
|
-
|
132
|
+
puts "Starting chromedriver"
|
133
|
+
@driver = Selenium::WebDriver.for :chrome
|
106
134
|
@base_url = "https://#{site}.harvestapp.com/"
|
135
|
+
puts "Driving to #{@base_url}"
|
107
136
|
@driver.manage.timeouts.implicit_wait = 30
|
108
137
|
@verification_errors = []
|
109
138
|
@driver.get(@base_url + "/account/login")
|
139
|
+
puts "Signing in as #{user}"
|
110
140
|
@driver.find_element(:id, "email").clear
|
111
141
|
@driver.find_element(:id, "email").send_keys user
|
112
142
|
@driver.find_element(:id, "user_password").clear
|
113
143
|
@driver.find_element(:id, "user_password").send_keys pass
|
114
144
|
@driver.find_element(:id, "sign-in-button").click
|
145
|
+
puts "Heading to the Reports area"
|
115
146
|
@driver.find_element(:link, "Reports").click
|
116
147
|
@driver.find_element(:css, "span.btn-dropdown").click
|
117
148
|
@driver.find_element(:link, "Custom").click
|
118
149
|
|
150
|
+
puts "Entering custom dates"
|
119
151
|
@driver.find_element(:id, "start_date").clear
|
120
152
|
@driver.find_element(:id, "start_date").send_keys from
|
121
153
|
@driver.find_element(:id, "end_date").clear
|
122
154
|
@driver.find_element(:id, "end_date").send_keys to
|
123
155
|
|
156
|
+
puts "Requesting detailed report"
|
124
157
|
@driver.find_element(:link, "Update Report").click
|
125
158
|
@driver.find_element(:link, "Detailed Report").click
|
126
159
|
@driver.find_elements(:tag_name => 'option').find{|i| i.text == 'Task'}.click
|
127
160
|
|
128
161
|
puts "Print as PDF. Filename:\n#{pdf_name}"
|
129
|
-
pbcopy pdf_name
|
162
|
+
if pbcopy pdf_name
|
163
|
+
puts "Filename is currently in your pasteboard for file save dialog..."
|
164
|
+
end
|
130
165
|
@driver.execute_script('window.print()')
|
131
166
|
@driver.find_element(:xpath, "//nav[@id='nav']/div/ul/li[4]/a").click
|
132
167
|
@driver.find_element(:link, "Sign Out").click
|
133
|
-
@driver.quit
|
134
168
|
puts "Email your PDF."
|
135
|
-
|
136
|
-
puts
|
137
|
-
|
169
|
+
pbcopy subject
|
170
|
+
puts <<-EOF
|
171
|
+
-------------------------------
|
172
|
+
#{subject}
|
173
|
+
|
174
|
+
|
175
|
+
#{body}
|
176
|
+
-------------------------------
|
177
|
+
EOF
|
138
178
|
rescue Exception => ex
|
139
|
-
|
179
|
+
puts <<-EOF
|
180
|
+
Error: #{ex.message}
|
181
|
+
------------------
|
182
|
+
#{ex.backtrace.join("\n")}
|
183
|
+
EOF
|
184
|
+
ensure
|
185
|
+
@driver.quit
|
140
186
|
end
|
141
187
|
end
|
142
188
|
end
|
143
|
-
end
|
189
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: harvest_wheelman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keyvan Fatehi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
133
|
version: '0'
|
134
134
|
requirements: []
|
135
135
|
rubyforge_project:
|
136
|
-
rubygems_version: 2.0.
|
136
|
+
rubygems_version: 2.0.14
|
137
137
|
signing_key:
|
138
138
|
specification_version: 4
|
139
139
|
summary: Logs into Harvest and generates a PDF report
|