I have a simple cron job sending me questions and i'd like to be able to reply to them and do something with the answers... things like "what have you eaten recently?" or "what's your mood?". they all would feed into a mail account, so it should be easy-enough to work out i suppose. 开发者_如何转开发
My question is related to parsing the mail and the DB insert; I've done a fair amount of work to understand rails, but i've no idea on how i should go about tossing results into the db in just a ruby script. would i just use activerecord, or is that 'overkill'? i haven't done much pure ruby stuff so i thought i'd ask this question in addition to googling.
this would run as a cron job and simply download new messages from the POP account and parse them into the DB. I guess i'd end up logging the date/time, subject (for grouping) and first message line (dropping any message quoting)? i'd want to do things like graph mood over the course of a day/week/etc... or what have you.
So, i'm looking for the "easy" way to do this and not the "cobbled" way, which is totally what i would do if i wrote this in perl. I have little to no experience with ruby in this simple setup...
so, any gems that would help? and what would be ideal for DB access in a little script?
To download and parse mails, I'd recommend the Mail Gem. The documentation is pretty straightforward, so that part of it shouldn't be a problem.
You can schedule a cron job that runs a Ruby script which uses the mail gem and another choice of gem for data persistence. I'd recommend Stone
Alternatively if you're more comfortable with rails, you can just use rails runner -e environmentname script.rb
in your cron job, which will first load your Rails app with ActiveRecord and all the other defaults, and then execute the code in your script.
精彩评论