散財.com
30分プログラム、その199。散財.comにプログラムから投稿する。
最近、散財.comを始めたんだけど、携帯から投稿できないのが面倒。そこで、メールを送るだけで投稿できるプログラムを作ろうと思う。
で、それの下準備としてWWW::Mechanizeを使って投稿してみる。
ソースコード
#! /opt/local/bin/ruby # -*- mode:ruby; coding:utf-8 -*- # # 3zai.rb - # # Copyright(C) 2007 by mzp # Author: MIZUNO Hiroki / mzpppp at gmail dot com # http://howdyworld.org # # Timestamp: 2007/12/06 21:50:32 # # This program is free software; you can redistribute it and/or # modify it under the same terms as Ruby itself. # require 'rubygems' require 'mechanize' def login(agent) page = agent.get 'http://www.3zai.com' form = page.forms.with.name('loginForm').first form.user_id = '<user id>' form.password = '<password>' agent.submit form end def account(agent,option) page = agent.get 'http://www.3zai.com/manage/account/' form = page.forms.with.name('account_create_form').first count = form.start_item_count option.each{|key,value| form["#{key}#{count}"] = value } agent.submit form end agent = WWW::Mechanize.new login(agent) puts 'login' # - 商品hoge # - 100円 # - 食費 # - 全般 account(agent, :item_name=>'hoge', :unit_price=>'100', :account_genre_seq=>'4', :account_category_seq=>'10')
散財.comへメールで投稿
上で書いたやつを使って、メールから投稿できるようにしてみた。
でも、パスワードがべったり書いてあるし、ジャンルとかにも対応してないから、まだ公開できない。
そのうちね。