-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrewards_central.rb
executable file
·164 lines (151 loc) · 4.65 KB
/
rewards_central.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/rubycash'
class RewardsCentral < Rubycash
def initialize(username, password)
@base_url = "http://www.rewardscentral.com.au"
super(username, password)
end
def doQuickQuiz()
page = fetchPage('/earn/QuickSurvey.aspx', 'Getting Quick Quiz page...')
form = page.forms_with(action: 'quicksurvey.aspx').first
if form.nil?
log('ERROR: Quiz form cannot be found.')
return
end
if page.body =~ /You have already/
log('Quiz already completed.')
return
end
type = form.radiobuttons
if type == []
type = form.checkboxes
end
if !type.last.nil?
type.last.check
end
# if there are no radios or checkboxes, there's probably no question for today
result = submitForm(form, 'Submitting Quick Quiz form...', 'ctl00$mainContent$QuickSurvey1$btnSubmit')
if result.body =~ /You have been credited/
log('Quiz completed successfully!')
else
log('Unable to verify if Quiz completed succesfully.')
end
end
def scrapeLinks(page)
links = []
page.links.each do |link|
if link.href =~ /TopFrame.aspx\?adid=\d+/
links.push(link)
end
end
return links
end
def visitTrackedLink(link)
result = link.click
# `result' is now an iframe
real_links = result.body.scan(/src="(.+?)"/).flatten;
real_click = real_links[0]
# This page is the top iframe that counts down from 10 and then reloads.
# Wait 10 seconds before we phone home (8 is really enough though).
wait = 8
page = fetchPage('/earn/' + real_click, "Waiting #{wait} seconds...")
sleep(wait)
return fetchPage('/earn/' + real_click, 'Reporting link has been clicked...')
end
def doGuessingGame()
page = fetchPage('/earn/GuessingGame.aspx', 'Getting Guessing Game page...')
form = page.forms.first
gg_button = 'ctl00$mainContent$btnSubmitGuessing'
# has the field already been filled in?
if page.body =~ /disabled/
log('Guessing Game already completed.')
return
end
# generate seven numbers between 1 to 10,000
numbers = []
7.times { numbers.push(1 + rand(9999)) }
# load numbers into form
num_loaded = 0;
for i in (0..6)
field_name = 'ctl00$mainContent$txtguess' + (i+1).to_s
# They might have 5, 6 or 7 fields to fill in, depending on Experience Points
if form.has_field?(field_name)
form[field_name] = numbers[i]
num_loaded += 1
end
end
# submit our values and check the result
result = submitForm(form, "Submitting #{num_loaded} numbers...", gg_button)
if result.body =~ /Your guessing game entry has been accepted/
log('Guessing Game completed successfully!')
else
log('Unable to verify if Guessing Game completed succesfully.')
end
end
def doRewardMail()
base = '/Earn/'
page = fetchPage(base + 'RewardMail.aspx', 'Getting Reward Mail page...')
rlinks = []
# look for the links to the Reward Mail emails
page.links.each do |link|
if link.href =~ /(ReadRewardMail.aspx\?uid=[\w-]+&aid=[\w-]+)/i
rlinks.push($1)
end
end
# look for the rows that are unread
rows = page.body.scan(/<tr>.+?<strong>[^<]+<\/strong>.+?<\/tr>/im)
rows.each do |row|
# find which links are for unread Reward Mail only
rlinks.each do |link|
readRewardMail(base + link) if row.index(link)
end
end
end
def readRewardMail(path)
# fetch the Reward Mail
page = fetchPage(path, 'Visiting Reward Mail at ' + @base_url + path)
# find the link that will earn us points
page.links.each do |link|
if link.href =~ /(\/Earn\/to.aspx\?uid=[\w-]+&aid=[\w-]+.*&rtype=1)/i
fetchPage($1, 'Clicking Reward Mail points link: ' + link.href)
break
end
end
end
def doAlerts()
base = '/Earn/'
page = fetchPage(base + 'myalerts.aspx', 'Getting My Alerts page...')
# find the alert links
new_alert_links = page.links.select do |link|
link.href =~ /(myalertsview\.aspx\?ctype=[\d]+&uid=[\w-]+&aid=[\w-]+)/i and
link.attributes.find { |attr| attr[0] == 'style' }[1] =~ /bold/i
end
if new_alert_links.length == 0
puts "No new alerts."
return
end
new_alert_links.each do |link|
alert_page = fetchPage(base + link.href, 'Clicking My Alerts link: ' + @base_url + base + link.href)
if alert_page.body =~ /earn\.css/ or alert_page.body =~ /Surprise Bonus/i
# check if it's an alert we gain something from
if alert_page.body =~ /You have already collected/
puts "Already collected reward."
else
submitForm(alert_page.forms.first, 'Collecting alert reward.', alert_page.forms.first.buttons.first.name)
end
else
puts "Skipping sponsored alert."
end
end
end
def doDailyRun()
login()
doQuickQuiz()
doGuessingGame()
doRewardMail()
doAlerts()
end
end
if $PROGRAM_NAME == __FILE__
RewardsCentral::run()
end