extracare2of 0.2 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.ruby-version +1 -1
- data/README.md +17 -5
- data/bin/extracare2of +8 -5
- data/extracare2of-0.2.gem +0 -0
- data/extracare2of.gemspec +1 -1
- data/lib/ExtraCare2OF/authentication.rb +27 -8
- data/lib/ExtraCare2OF/database.rb +20 -32
- data/lib/ExtraCare2OF/runner.rb +22 -26
- data/lib/ExtraCare2OF/settings.rb +2 -2
- data/lib/ExtraCare2OF/version.rb +2 -2
- data/lib/extracare2of.rb +3 -3
- metadata +3 -3
- data/config/config.yml +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2fab3c2c7a497c7b1b7778109a835070383e6d10
|
4
|
+
data.tar.gz: 0f6b388cf9ea330d863798b0a52904b6ff99da13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32bd39e2db40297bfe8837c1059aa46181e3cf8fef31ce0b3660c19f130db13ea82b83f7ae7a78c333c497089e52ea61a6c098deef5a72c08db22a3896382c6e
|
7
|
+
data.tar.gz: cda676df9026377c41d9ae158bdae7403c7a55bbc4b1def0aa0fd22626142566ce725a8bea796068c23e71258d4a6bad6db8dc95033d764bc68d583e97f27a3b
|
data/.gitignore
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.1.1
|
1
|
+
ruby-2.1.1
|
data/README.md
CHANGED
@@ -12,23 +12,35 @@ This script performs the following actions:
|
|
12
12
|
+ Checks coupons against the database for previously imported coupons
|
13
13
|
+ Sends every new coupon to the task manager of your choice
|
14
14
|
|
15
|
-
##
|
15
|
+
## Usage
|
16
16
|
|
17
|
-
$
|
17
|
+
$ extracare2of
|
18
18
|
$ Looking for coupons...
|
19
19
|
$ ----
|
20
20
|
$ Title: 10% off skincare products
|
21
21
|
$ - Due Date: 8/10/2013
|
22
22
|
$ - Start Date: 8/1/2013
|
23
23
|
$ - Note: Reedemable in-store only
|
24
|
-
|
24
|
+
|
25
25
|
|
26
26
|
|
27
27
|
## Installation
|
28
28
|
|
29
|
-
|
29
|
+
gem install extracare2of
|
30
|
+
|
31
|
+
## Configuration
|
32
|
+
|
33
|
+
Config file is location at `~/.extracare2of/config/config.yml`.
|
34
|
+
Here you can change which todo manager you use.
|
35
|
+
|
36
|
+
---
|
37
|
+
:services:
|
38
|
+
:use_omnifocus: true
|
39
|
+
:use_reminders: false
|
40
|
+
:use_things: false
|
41
|
+
:use_dueapp: false
|
30
42
|
|
31
|
-
|
43
|
+
The first time you run `extracare2of` you will be prompted for a username and password. The session will then be serialized and stored in `~/.extracare2of/config/session.yml`. Your password is not saved in plaintext. You will then be able to use this without having to log in again.
|
32
44
|
|
33
45
|
## Todo
|
34
46
|
|
data/bin/extracare2of
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
runner.
|
3
|
+
require 'extracare2of'
|
4
|
+
runner = Extracare2of::Runner.new
|
5
|
+
|
6
|
+
if ARGV[0] == "init"
|
7
|
+
runner.init
|
8
|
+
else
|
9
|
+
runner.run
|
10
|
+
end
|
Binary file
|
data/extracare2of.gemspec
CHANGED
@@ -5,7 +5,7 @@ require 'extracare2of/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "extracare2of"
|
8
|
-
spec.version =
|
8
|
+
spec.version = Extracare2of::VERSION
|
9
9
|
spec.authors = ["Nick Prokesch"]
|
10
10
|
spec.email = ["nick@prokes.ch"]
|
11
11
|
spec.summary = %q{send CVS ExtraCare coupon reminders to OmniFocus}
|
@@ -1,23 +1,42 @@
|
|
1
|
-
|
1
|
+
require 'highline/import'
|
2
|
+
|
3
|
+
module Extracare2of
|
2
4
|
class Authentication
|
3
5
|
attr_reader :hash
|
4
6
|
|
5
|
-
def initialize(
|
6
|
-
|
7
|
-
|
8
|
-
@agent = Mechanize.new
|
7
|
+
def initialize(*)
|
8
|
+
load_session if session_exists?
|
9
|
+
authenticate unless session_exists?
|
9
10
|
@hash = Hash.new
|
10
11
|
end
|
11
12
|
|
13
|
+
def session_exists?
|
14
|
+
File.exist?("#{ENV['HOME']}/.extracare2of/session.yml")
|
15
|
+
end
|
16
|
+
|
17
|
+
def load_session
|
18
|
+
session_file = open("#{ENV['HOME']}/.extracare2of/session.yml")
|
19
|
+
@agent = Mechanize.new do |a|
|
20
|
+
a.cookie_jar = YAML.load(session_file)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def authenticate
|
25
|
+
@agent = Mechanize.new
|
26
|
+
login
|
27
|
+
open("#{ENV['HOME']}/.extracare2of/session.yml", 'w') { |f|
|
28
|
+
f.puts @agent.cookie_jar.to_yaml
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
12
32
|
def login
|
13
33
|
page = @agent.get("https://m.cvs.com/mt/www.cvs.com/account/login.jsp")
|
14
34
|
form = page.forms.first
|
15
|
-
form['/atg/userprofiling/ProfileFormHandler.value.login'] =
|
16
|
-
form['/atg/userprofiling/ProfileFormHandler.value.password'] =
|
35
|
+
form['/atg/userprofiling/ProfileFormHandler.value.login'] = ask("username: ")
|
36
|
+
form['/atg/userprofiling/ProfileFormHandler.value.password'] = ask("password: ")
|
17
37
|
page = form.submit
|
18
38
|
@page = page
|
19
39
|
sleep 3
|
20
|
-
# puts page.parser.xpath("//body").to_html
|
21
40
|
end
|
22
41
|
|
23
42
|
def request(link, request_id)
|
@@ -1,42 +1,28 @@
|
|
1
1
|
require 'sqlite3'
|
2
2
|
|
3
|
-
module
|
3
|
+
module Extracare2of
|
4
4
|
class Database
|
5
5
|
attr_accessor :add_user
|
6
6
|
attr_reader :add_user
|
7
7
|
|
8
|
-
def initialize
|
9
|
-
@handle =
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
def initialize
|
9
|
+
@handle = `whoami`
|
10
|
+
db_path = "#{ENV['HOME']}/.extracare2of/db/coupons.db"
|
11
|
+
create_db unless File.exist?(db_path)
|
12
|
+
@db = SQLite3::Database.new( db_path )
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
def create_tables
|
23
|
-
begin
|
24
|
-
@db.execute("CREATE TABLE coupons(
|
15
|
+
def create_db
|
16
|
+
`mkdir -p ~/.extracare2of/db`
|
17
|
+
`mkdir -p ~/.extracare2of/config`
|
18
|
+
`touch ~/.extracare2of/db/coupons.db`
|
19
|
+
@db.execute("CREATE TABLE coupons(
|
25
20
|
id integer,
|
26
21
|
name text,
|
27
22
|
due_date integer,
|
28
23
|
start_date text,
|
29
24
|
handle text,
|
30
|
-
PRIMARY KEY(id)
|
31
|
-
)
|
32
|
-
")
|
33
|
-
rescue
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
|
38
|
-
def open
|
39
|
-
@db = SQLite3::Database.new( "./db/coupons.db" )
|
25
|
+
PRIMARY KEY(id))")
|
40
26
|
end
|
41
27
|
|
42
28
|
def close
|
@@ -44,18 +30,20 @@ module ExtraCare2OF
|
|
44
30
|
end
|
45
31
|
|
46
32
|
def add_coupon(args)
|
47
|
-
|
48
33
|
name = args[:name].to_s
|
49
34
|
due_date = args[:due_date].to_s
|
50
35
|
start_date = args[:start_date].to_s
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
36
|
+
return false if coupon_exists?(name)
|
37
|
+
@db.execute(
|
38
|
+
"insert into coupons(
|
39
|
+
name, due_date, start_date, handle
|
40
|
+
) values (?,?,?,?)",
|
41
|
+
name, due_date, start_date, @handle
|
42
|
+
)
|
55
43
|
end
|
56
44
|
|
57
45
|
def coupon_exists?(name)
|
58
|
-
|
46
|
+
@db.execute( "select 1 where exists(
|
59
47
|
select 1
|
60
48
|
from coupons
|
61
49
|
where name = ?
|
data/lib/ExtraCare2OF/runner.rb
CHANGED
@@ -1,18 +1,19 @@
|
|
1
1
|
|
2
|
-
module
|
2
|
+
module Extracare2of
|
3
3
|
class Runner
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
@
|
7
|
-
@
|
8
|
-
@db = ExtraCare2OF::Database.new(username: @username)
|
9
|
-
@browser = ExtraCare2OF::Authentication.new(username: @username, password: @password)
|
5
|
+
def initialize(*)
|
6
|
+
@db = Extracare2of::Database.new
|
7
|
+
@browser = Extracare2of::Authentication.new
|
10
8
|
@settings = Settings.new
|
11
|
-
@browser.login
|
12
9
|
@count = 0
|
13
10
|
# p @rewards_source
|
14
11
|
end
|
15
12
|
|
13
|
+
def init
|
14
|
+
@browser.authenticate
|
15
|
+
end
|
16
|
+
|
16
17
|
def async_response(url)
|
17
18
|
request_id = Time.now.to_i
|
18
19
|
@browser.request(url, request_id)
|
@@ -37,7 +38,7 @@ module ExtraCare2OF
|
|
37
38
|
due_date = deal[1]
|
38
39
|
note = deal[2]
|
39
40
|
# defer_date = deal[3]
|
40
|
-
@deals_array.push({:
|
41
|
+
@deals_array.push({name: name,due_date: parse_date(due_date), defer_date: Time.now, note: note})
|
41
42
|
end
|
42
43
|
@deals_array
|
43
44
|
end
|
@@ -63,7 +64,7 @@ module ExtraCare2OF
|
|
63
64
|
days = (60 * 60 * 24 * $1.to_i)
|
64
65
|
newdate = Time.now + days
|
65
66
|
else
|
66
|
-
newdate = Chronic.parse(datestring, {:
|
67
|
+
newdate = Chronic.parse(datestring, {context: :future, ambiguous_time_range: 8})
|
67
68
|
end
|
68
69
|
# parsed = newdate.strftime('%D %l:%M%p').gsub(/\s+/,' ');
|
69
70
|
# return parsed =~ /1969/ ? false : parsed
|
@@ -72,19 +73,18 @@ module ExtraCare2OF
|
|
72
73
|
|
73
74
|
def process_coupon(coupon)
|
74
75
|
# puts " - Sending #{get_coupons.size} tasks to OF"
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
end
|
76
|
+
return false if @db.coupon_exists?(coupon[:name])
|
77
|
+
@db.add_coupon(name: coupon[:name], due_date: coupon[:due_date], defer_date: coupon[:defer_date])
|
78
|
+
puts "----"
|
79
|
+
puts " Title: #{coupon[:name]}"
|
80
|
+
puts " - Due Date: #{coupon[:due_date]}"
|
81
|
+
puts " - Start Date: #{coupon[:defer_date]}"
|
82
|
+
puts " - Note: #{coupon[:note]}"
|
83
|
+
CreateTask::OmniFocus.new(coupon.to_hash) if @settings.use_omnifocus
|
84
|
+
CreateTask::Reminders.new(coupon.to_hash) if @settings.use_reminders
|
85
|
+
CreateTask::Things.new(coupon.to_hash) if @settings.use_things
|
86
|
+
CreateTask::DueApp.new(coupon.to_hash) if @settings.use_dueapp
|
87
|
+
# Services::Reminders.new(coupon.to_hash)
|
88
88
|
end
|
89
89
|
|
90
90
|
|
@@ -97,10 +97,6 @@ module ExtraCare2OF
|
|
97
97
|
else
|
98
98
|
puts "No new coupons found."
|
99
99
|
end
|
100
|
-
# puts "Sending extra bucks to card"
|
101
|
-
# send_bucks_to_card
|
102
|
-
# puts "Done"
|
103
|
-
# exit
|
104
100
|
end
|
105
101
|
|
106
102
|
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
module
|
1
|
+
module Extracare2of
|
2
2
|
class Settings
|
3
3
|
attr_reader :debug, :use_omnifocus, :use_reminders, :use_things, :use_dueapp
|
4
4
|
|
5
5
|
def initialize
|
6
|
-
@filename =
|
6
|
+
@filename = "#{ENV['HOME']}/.extracare2of/config/config.yml"
|
7
7
|
unless File.exists?(@filename)
|
8
8
|
config = {services: {
|
9
9
|
:use_omnifocus => true,
|
data/lib/ExtraCare2OF/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module
|
2
|
-
|
1
|
+
module Extracare2of
|
2
|
+
VERSION = "0.3"
|
3
3
|
end
|
data/lib/extracare2of.rb
CHANGED
@@ -6,8 +6,8 @@ require 'chronic'
|
|
6
6
|
require 'mechanize'
|
7
7
|
require 'open-uri'
|
8
8
|
|
9
|
-
module
|
10
|
-
|
9
|
+
module Extracare2of
|
10
|
+
Dir[File.dirname(__FILE__) + '/extracare2of/*.rb'].each do |file|
|
11
11
|
require file
|
12
12
|
end
|
13
|
-
end
|
13
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: extracare2of
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.3'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Prokesch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mechanize
|
@@ -108,8 +108,8 @@ files:
|
|
108
108
|
- Gemfile
|
109
109
|
- README.md
|
110
110
|
- bin/extracare2of
|
111
|
-
- config/config.yml
|
112
111
|
- db/coupons.db
|
112
|
+
- extracare2of-0.2.gem
|
113
113
|
- extracare2of.gemspec
|
114
114
|
- lib/ExtraCare2OF/authentication.rb
|
115
115
|
- lib/ExtraCare2OF/database.rb
|