-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess_speedtest
executable file
·48 lines (39 loc) · 1.07 KB
/
process_speedtest
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env ruby
#
# reads CSV output from speedtest.py and
# a) saves it to local speedtest.csv file
# b) sends a human readable emaill
#
require 'csv'
require 'time'
require 'mail'
require 'yaml'
gcred = YAML.load_file("#{ENV['HOME']}/.gmail/cred.yml")
data = ARGF.read
(serverid, sponsor, name, timestamp, distance, ping, download, upload) = CSV.parse(data)[0]
smtp_option = {
address: 'smtp.gmail.com',
port: 587,
domain: 'vineta.ca',
user_name: gcred[:user],
password: gcred[:password],
authentication: 'plain',
enable_starttls_auto: true
}
subject = "Speedtest #{Time.parse(timestamp).localtime.strftime('%d-%h-%Y %H:%M')}"
text_body = <<"EOM"
ping: #{'%.2f' % ping} ms
download: #{'%.1f' % (download.to_f / 1024)} Mbit/s (#{'%.0f' % (download.to_f / (1024*8))} KB/s)
upload: #{'%.1f' % (upload.to_f / 1024)} Mbit/s (#{'%.0f' % (upload.to_f / (1024*8))} KB/s)
EOM
# puts subject
# puts text_body
Mail.defaults do
delivery_method :smtp, smtp_option
end
Mail.deliver do
to '[email protected]'
from 'Saturn <[email protected]>'
subject subject
body text_body
end