但し、Google App Engineの制約で、配信先のアドレスはGMailに限られます
http://markethacks.appspot.com/
Ubuntu/外為に関しての備忘録、メモ等・・・
bash gnuplot.sh bollinger.dat out
#!/bin/bash
INPUT=$1
OUTPUT=$2
gnuplot <<EOF
reset
set title "Bollinger Bands"
#set size 2.0, 2.0
set terminal png
set output "${OUTPUT}.png"
set xdata time
set timefmt "%m/%d%H:%M"
set format x "%m/%d %H:%M"
set title "Bollinger Bands"
set yrange [102.0:105.0]
set ytics (102.0, 102.5, 103.0, 103.5, 104.0, 104.5, 105.0)
#set xrange [50:253]
set lmargin 9
set rmargin 2
set grid
set logscale y
plot '$INPUT' using 1:2:4:3:5 notitle with candlesticks lt -1, \
'$INPUT' using 1:6 notitle with lines lt 1, \
'$INPUT' using 1:7 notitle with lines lt 1, \
'$INPUT' using 1:8 notitle with lines lt 1
EOF
05/2213:29 102.98 103.05 102.98 103.03 102.861904761905 103.000846339173 102.722963184637
05/2213:39 103.01 103.05 103.01 103.05 102.871904761905 103.032730014529 102.711079509281
05/2213:49 103.06 103.07 103.0 103.0 102.88 103.048878654657 102.711121345343
05/2213:59 103.04 103.1 103.02 103.08 102.892380952381 103.079880793624 102.704881111138
05/2214:09 103.07 103.13 103.07 103.11 102.907619047619 103.111472402901 102.703765692337
05/2214:19 103.1 103.13 103.1 103.11 102.923333333333 103.136531206948 102.710135459719

require 'rubygems'
require 'tlsmail'
require 'time'
module Gmail
def Gmail.get_content(from_address, to_address, subject=nil, body=nil)
content = ""
content << "From: #{from_address}\n"
content << "To: #{to_address}\n"
content << "Subject: #{subject}\n"
content << "Date: #{Time.now.rfc2822}\n\n"
content << "#{body}\n"
return content
end
def Gmail.send(user, pass, from_address, to_address, subject=nil, body=nil)
Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
Net::SMTP.start('smtp.gmail.com', 587, 'gmail.com', user, pass, :login) { |smtp|
smtp.send_message(get_content(from_address, to_address, subject, body), \
from_address, to_address)
}
end
end
if __FILE__ == $0
Gmail.send("Gmailのアカウント", "パスワード", "送信元アドレス", "送信先アドレス", "sub", "test")
end
application: hello
version: 1
runtime: python
api_version: 1
handlers:
- url: /.*
script: hello.py
import time
print ''
print 'Hello!!'
print ''
tm = time.localtime(time.time())
print time.strftime("%Y/%m/%d %H:%M:%S", tm)
$ ~/sdk/google_appengine/dev_appserver.py ./
WARNING 2008-04-08 23:28:08,144 __init__.py] Could not read datastore data from /tmp/dev_appserver.datastore
INFO 2008-04-08 23:28:08,147 __init__.py] Running application hello on port 8080: http://localhost:8080
Hello!!
2008/04/08 14:47:37
puts "usage ruby #{$0} 元本 金利 年数"; exit 100 if ARGV.size != 3
puts "元本 #{ARGV[0]} 金利 #{ARGV[1]}% #{ARGV[2]}年"
base = ARGV[0].to_i
kinri = ARGV[1].to_f / 100.0
num = ARGV[2].to_i
k_sum = 1.0
1.upto(num) { |i|
k_sum *= (kinri + 1)
alt = base * k_sum
printf "%2d %8d\n", i, alt.to_i
}
script$ ruby fuku.rb 1000000 0.8 10
usage ruby fuku.rb 元本 金利 年数
元本 1000000 金利 0.8% 10年
1 1008000
2 1016064
3 1024192
4 1032386
5 1040645
6 1048970
7 1057362
8 1065820
9 1074347
10 1082942
script$ ruby fuku.rb 1000000 10 10
usage ruby fuku.rb 元本 金利 年数
元本 1000000 金利 10% 10年
1 1100000
2 1210000
3 1331000
4 1464100
5 1610510
6 1771561
7 1948717
8 2143588
9 2357947
10 2593742

require "tkclass"
require "tk"
OFFSET=10
$oval=0
$sque=0
$disp_hankei=100
$hankei=10000
module MonteCarlo
def MonteCarlo.plot(max_x=$hankei*2, max_y=$hankei*2)
x = rand(max_x+1)
y = rand(max_y+1)
[x, y]
end
end
label = TkLabel.new do
text("0")
pack()
end
$c = TkCanvas.new('width'=>($disp_hankei+OFFSET)*2, 'height'=>($disp_hankei+OFFSET)*2).pack
Oval.new($c,OFFSET+0,OFFSET+0,OFFSET+$disp_hankei*2,OFFSET+$disp_hankei*2)
Rectangle.new($c,OFFSET+0,OFFSET+0,OFFSET+$disp_hankei*2,OFFSET+$disp_hankei*2)
def plot
x2 = 2
bx, by = MonteCarlo.plot($hankei*2, $hankei*2)
x, y = bx, by
x = bx - $hankei
y = by - $hankei
bx = bx / 100
by = by / 100
if (x*x + y*y) < $hankei*$hankei
$oval += 1
dot = Oval.new($c,OFFSET+bx,OFFSET+by,OFFSET+bx, OFFSET+by, "outline" => "red", "fill" => "red")
else
dot = Oval.new($c,OFFSET+bx,OFFSET+by,OFFSET+bx, OFFSET+by)
end
$sque += 1
end
count=0
TkAfter.new(1, -1, proc do
count+=1
plot
pai = $oval.to_f/$sque.to_f * 4.0
label.text("#{count.to_s} #{pai.to_s}")
end).start
Tk.mainloop
$oval = 0; $sque = 1
def plot
x, y = rand, rand
$oval += 1 if (x*x + y*y) < 1.0
$sque += 1
end
1000000.times {
plot
}
pai = $oval.to_f/$sque.to_f * 4.0
puts "pai #{pai.to_s}"
pai 3.14324485675514
require 'net/http'
require 'gmailer'
require 'rexml/document'
host="www.drk7.jp"
path="/weather/xml/14.xml"
user="gmailのID"
pass="gmailのパスワード"
cellphone="携帯のアドレス"
#降水確率の基準値 メール送るか送らないか
RAINFALL_RATE=40
resp = ""
Net::HTTP.version_1_2
Net::HTTP.start(host, 80) {|http|
response = http.get(path)
if response.code != "200"
raise HttpError, "Http Conection Error."
end
resp = response.body
}
send_flag=false
body = "傘!!\n"
body << "神奈川県東部\n"
doc = REXML::Document.new(resp)
doc.elements.each("./weatherforecast/pref/area/info") do |item|
if item.attributes["date"] == Time.now.strftime("%Y/%m/%d")
#and doc.elements.each("./weatherforecast/pref/area").attributes["id"] == "東部"
body << item.text("weather") + "\n"
body << "降水確率\n"
4.times do |i|
period = item.get_elements("./rainfallchance/period")[i].text
hour = item.get_elements("./rainfallchance/period")[i].attributes["hour"]
body << "#{hour} #{period}\n"
begin
send_flag = true if period.to_i >= RAINFALL_RATE
rescue
end
end
body << item.text("weather_detail") + "\n"
# 西部をスキップする
break
end
end
puts body
if send_flag
GMailer.connect(user, pass) do |g|
g.send(
:to => cellphone,
:subject => "weather hack",
:body => body)
end
end
傘!!
神奈川県東部
くもり時々雨
降水確率
00-06 --
06-12 60
12-18 50
18-24 30
北の風のちやや強く海上では後北の風強くくもり朝から昼過ぎ雨
"自分のMIXIのID":
:url: http://mixi.jp/show_friend.pl
:flag: false
:depth: 0
require 'rubygems'
require 'mechanize'
require "yaml"
username = '<メールアドレス>'
password = '<パスワード>'
agent = WWW::Mechanize.new
page = agent.get('http://mixi.jp/')
form = page.forms[0]
form.fields.find {|f| f.name == 'email'}.value = username
form.fields.find {|f| f.name == 'password'}.value = password
form.fields.find {|f| f.name == 'next_url'}.value = '/home.pl'
page = agent.submit(form, form.buttons.first)
def url()
a = nil; id = ""
$list.each do |k,i|
if i[:flag] == false
if a == nil
a = i; id = k
end
if a[:depth] > i[:depth]
a = i
id = k
end
end
end
id
end
def set(id, url, depth)
if !$list.key?(id)
a={:url=>url,:depth=>depth,:flag=>false}
$list[id] = a
end
end
def output_data
result = {}
$list.each do |k,v|
depth = v[:depth]
if result.key?(depth)
result[depth] += 1
else
result[depth] = 1
end
size = v[:list].size if v[:list] != nil
puts "#{k} #{size} #{v[:flag]} #{depth}"
end
result.each do |k,v|
puts "隔たり次数 #{k} 人数 #{v}"
end
puts "全人数 #{$list.size}"
end
$list = YAML::load(File.open("list.yaml").read)
Signal.trap('INT') do
output_data()
YAML.dump($list, File.open("list.yaml", 'w'))
exit 0
end
while (id = url()) != nil
$list[id][:list] = []
depth = $list[id][:depth] + 1
diarylist = agent.get($list[id][:url])
diarylist.links.each do |link|
if link.href =~ /show_friend.pl\?id\=(\d+)/
friend_id = $1.to_s
url = "http://mixi.jp/" + link.href
$list[id][:list] << $1
set(friend_id, url, depth)
end
end
$list[id][:flag] = true
puts "#{id} size #{$list.size}"
#中間報告
output_data() if rand(50) == 20
sleep 2
end
output_data()