Check your MillNic stats over IM

Status
Not open for further replies.

andyt

New member
Dec 20, 2006
677
9
0
Lately I've been obsessed with checking my MillNic stats, so I thought I'd combine that with another obsession of mine..checking away messages. I wrote a jabber bot that grabs your MillNic stats for the day and sets it as the away message. It uses ruby, mechanize, and xmpp4r-simple. Here it is.




Code:
#millnic.rb
require 'rubygems'
require 'mechanize'
require 'xmpp4r-simple'

millnic_user="yourjabbername@gmail.com"
millnic_pass="password"
jabber_user="yourmillnicaccount@gmail.com"
jabber_pass="password"

class Millnic
  def self.stats(email, password)
    if email.nil? || password.nil?
      print "invalid-parameters"
    end

    agent = WWW::Mechanize.new
    page = agent.get('http://www.millnicmedia.com')
    form = page.forms.first
    form.fields.name('DL_AUTH_USERNAME').value = email
    form.fields.name('DL_AUTH_PASSWORD').value = password
    result = agent.submit(form, form.buttons.first)  
    return result.body[/[\$0-9\.].*Earned Today/]       
  end
end

begin
    im = Jabber::Simple.new(jabber_user, jabber_pass)
    while true
        stats = Millnic.stats(millnic_user, millnic_pass)   
        puts "set status to: '#{stats}'"
        im.status(:away, stats)
        sleep 60 * 60 # every 60 minutes
    end
end
To use:
-save that code as millnic.rb
-install ruby
-install rubygems
-Run: sudo gem install mechanize xmpp4r-simple -y
-Get a jabber account (gtalk), and an im client that supports jabber (I use Adium)
-If you don't already have one, get a MillNic account. They're a great company that pays quickly and has some great promotions.
-Edit that file with your MillNic and Jabber credentials
-Finally, run the script:
ruby millnic.rb
(I have it setup as a cron job that restarts it each day in case something goes wrong.)
-Check the screenname from adium or some other client
-Patiently wait for your check... :)
 
  • Like
Reactions: lucab


lmao - you have too much time on your hands dude.
hey do you run Vista? (I am betting your are running soem crazy flavour of linux...) We were talking about creating a Vista gadget for that fancy new bar it has.

Would people be interested in that?
Or just us stats obsessed uber geeks?
 
Since this is a Millnic thread anyway, can someone tell me what the weekly minimum is to get paid?
 
He's running Mac OS X. I'm impressed. I didn't think there were other Ruby devs here :D
 
He's running Mac OS X. I'm impressed. I didn't think there were other Ruby devs here :D

i am teaching myself ruby. do either of you 2 know much about configuring win32 for rails development? i am having trouble getting my server configured properly and am seriously considering buying a mac for this purpose.

thx in advance

op - pretty fucking cool bro, i have been fucking around with mechanize, hpricot, and scrubyt! lately... pretty cool shit, easy to use. have you used this to scrape, and if so, have you figured out a way to output to a db?

edit: sorry for the hijack , check pm's op
 
I think the resource I used when I first started doing Rails dev was ONLamp.com -- Rolling with Ruby on Rails

It's dated, but it should still be relevant. Macs are incredible for software development, so you definitely won't go wrong there. Since you're just getting started, I would stick with webrick for now as your development server.
 
Hey lucab, about saving to a db... no I haven't done that with mechanize via ruby, but I have with perl/php mechanize and mysql. I do rails for my day job, which has ActiveRecord and makes saving stuff to the db very easy. But there are ways to talk to mysql or sqlite or ... directly too. I really liked Why's Poignant Guide to Ruby for getting started with ruby, and the Agile Web Development book is great for rails.

ps: I think you'd like OS X and the Macbook. It's a great development environment.
 
yeah i bought agile web development, and i was going through that onlamp tutorial until i ran into a problem with viewing my localhost files. i have heard from a number of sources that windows just straight up blows for rails dev, i def have to get a mac. windows is just too much of a headache for rails dev i think. im going to check out that poingant guide tonight. thanks for the link.
 
I've had to manually set up Rails dev environments on Mac OS X and I'm sure andyt has too. It takes longer than setting up a Windows Rails dev environment.

What problems are you experiencing? Maybe we can figure it out and get you rolling.
 
hey thanks man!

the problem i am having is that when i try to view a local file via a web browser, port 3000, i get a 'can't establish a connection.' when i go to the command prompt and view my netstats, nothing is even binding to tcp port 3000. i really am not very tech savvy and have no idea where to start troubleshooting.

i read a coulpe of reports that instantrails wasn't the best way to go, so i installed each component separately.

i think it may be a problem with my mysql db, which i am using heidisql to interact with. i was at the point in the onlamp tutorial where you just created the form - before that, everything was fine. then, all of a sudden, i can't view ANY files through 127.0.0.1, or localhost.

any ideas what may be causing this?

ps - i am def ditching win for my dev environment, but i am not sure if i will be able to purchase a new comp within the next couple of months, so this is def a shitty setback.
 
Are you remembering to turn on webrick by running "script/server"? When you go to localhost:3000, do you see the Ruby on Rails page or nothing at all?
 
yeah i just looked into webrick. for some reason, for the first little bit of that tutorial i hadn't needed to launch webrick to view files via port 3000. i just used the 'ruby script/server -p 3000' command in the command prompt, and it said no such file or directory....

not sure if i have to install or require something before i can configure webrick for port 3000.

also, when i open up a ruby command window, it just closes right away. i have written a few scripts, and they all just close immediately when they are done running. i talked to one of the guys from rubyonrailways, and he said this is a common problem when using win for ruby.

he said my best bet was to use the command prompt - but is there a workaround for this?

these two problems are seriously motivating me to switch over to mac os x for my dev environment. i need no more convincing lol.

any idea what i have to do to get webrick configured for port 3000 in the meantime?
 
You need to make sure you're in your Rails application root before you run "ruby script/server".

The command prompt windows close immediately because it's running code and exiting. If you open the command prompt separately and then run your Ruby code, it will be fine.
 
  • Like
Reactions: lucab
yeah i just looked into webrick. for some reason, for the first little bit of that tutorial i hadn't needed to launch webrick to view files via port 3000. i just used the 'ruby script/server -p 3000' command in the command prompt, and it said no such file or directory....

not sure if i have to install or require something before i can configure webrick for port 3000.

also, when i open up a ruby command window, it just closes right away. i have written a few scripts, and they all just close immediately when they are done running. i talked to one of the guys from rubyonrailways, and he said this is a common problem when using win for ruby.

he said my best bet was to use the command prompt - but is there a workaround for this?

these two problems are seriously motivating me to switch over to mac os x for my dev environment. i need no more convincing lol.

any idea what i have to do to get webrick configured for port 3000 in the meantime?

Hmm. I haven't worked in rails since august of last year, but I don't recall any difficulties getting webrick working on windows. I just followed the setup instructions from the oReilly onLamp article previously linked. I was using RadRails s my ruby IDE.

If you really think heidiSQL may be the issue, just gut it and try using "mysql query browser"

You can also look at getting it running using 'mongrel' as the webserver (http://mongrel.rubyforge.org/). That was how I was running in a production environment.

I switched to cakePHP due to the ease of php hosting versus rails hosting. I may switch back someday, since rails is much more elegant than cakePHP.
Here are some collected links I gathered when I was working with ruby. For one reason or another, these stood out to me in regards to learning ruby and rails (in no particular order):

19 Rails Tricks Most Rails Coders Don't Know
Ruby
Gluttonous : Gluttonous - category rails
Slash7 with Amy Hoy - Rails
Planet RubyOnRails
Ruby on Rails Cheat Sheet - Cheat Sheets - ILoveJackDaniels.com
poocs.net—The adventures of scaling, Stage 1
category ruby (specifically, the post "Scaling Rails with Apache 2.2, mod_proxy_balancer and Mongrel".......direct link doesn't work for some reason)
 
  • Like
Reactions: lucab
Status
Not open for further replies.