13
\$\begingroup\$

Your challenge today is to cheat at badges!

You will build a bot that will connect to a Stack Exchange site, log in as you, visit the /questions page, visit a question, and then visit 9 other questions in the "related" sidebar (because that seems sufficient to count as "activity," and I need to standardize on something).

This bot must go through this process once every day, without any input or actions from the user. It should be able to be left running, and the user should be able to never touch the computer, and the consecutive days count will still be incremented. After "visiting" the site, it must print "visited".

You will assume that the user is using the Stack Exchange-provided OpenID.

The input of the program will be the site URL, SE OpenID email, and SE OpenID password. For example:

https://stackoverflow.com/ [email protected] password

You can input these however you would like.

Your program must work for a minimum of:

(Just to make sure it is universal.)

This is , so the shortest code in bytes will win!

\$\endgroup\$
3
  • 1
    \$\begingroup\$ The minimum I needed to do for activity was visit my user page. No need to read any questions. (But don't change the rules on account of this.) \$\endgroup\$ Commented Mar 5, 2014 at 14:16
  • 4
    \$\begingroup\$ Thank goodness the challenge wasn't to create a bot that randomly downvotes 40 questions/answers each day. \$\endgroup\$
    – user12183
    Commented Mar 5, 2014 at 19:21
  • 1
    \$\begingroup\$ Given the scope of stack exchange, it was only a matter of time until there was a question on exploiting it. \$\endgroup\$ Commented Mar 5, 2014 at 21:31

1 Answer 1

11
\$\begingroup\$

Ruby, 456 characters

require'mechanize'
s,*e=gets.split
a,o=Mechanize.new,'http://openid.stackexchange.com/'
a.agent.http.verify_mode=OpenSSL::SSL::VERIFY_NONE
l=a.get(o+'account/login').forms[0]
l.email,l.password=e
a.submit l,l.buttons[0]
g=a.get(s+'/users/login').forms.find{|f|f.action=='/users/authenticate'}
g.openid_identifier=o
a.submit g,g.buttons[-1]
loop{p=a.get s+'/questions'
10.times{p=p.links.find{|i|i.href=~/^\/questions\/\d/}.click}
puts'visited'
sleep 86400}

Ungolfed version:

require 'mechanize'

site, email, password = gets.split

agent = Mechanize.new
agent.agent.http.verify_mode = OpenSSL::SSL::VERIFY_NONE

login_form = agent.get('http://openid.stackexchange.com/account/login').forms.first
login_form.email = email
login_form.password = password
agent.submit login_form, login_form.buttons.first
puts 'logged in with SE openid'

site_login_form = agent.get(site + '/users/login').forms.find {|form| form.action == '/users/authenticate' }
site_login_form.openid_identifier = 'http://openid.stackexchange.com/'
agent.submit site_login_form, site_login_form.buttons.last
puts 'logged in to site'

loop {
    page = agent.get(site + '/questions')
    10.times do page = page.links.find{|link| link.href =~ /^\/questions\/\d/ }.click; end
    puts 'visited'
    sleep 60 * 60 * 24
}
\$\endgroup\$
2
  • 7
    \$\begingroup\$ Did you exceed the maximum storage on your Github account and start using the Q&A StackExchange format as overflow storage for your specs and source code? ;-) \$\endgroup\$ Commented Mar 5, 2014 at 22:59
  • 1
    \$\begingroup\$ @JonathanVanMatre, wait, there's a size limit on GitHub repositories? \$\endgroup\$ Commented Jul 29, 2016 at 23:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.