0
|
1 #!/usr/bin/tclsh
|
|
2
|
|
3 # Polku ja tiedosto mihin tiedot talletetaan
|
|
4 set datafile "/home/niinuska/bot/saa.data"
|
|
5
|
|
6 # HTTP proxy
|
|
7 # 1 = kyllä
|
|
8 # 0 = ei
|
|
9 set use_proxy 0
|
|
10
|
|
11 # HTTP proxy osoite ja portti (jos ed. optio 1)
|
|
12 set http_proxy_host "cache.inet.fi"
|
|
13 set http_proxy_port 800
|
|
14
|
|
15
|
|
16 ##############################################################################
|
|
17 package require http
|
|
18 ::http::config -urlencoding iso8859-1 -useragent "Mozilla/4.0 (compatible; MSIE 6.0; MSIE 5.5; Windows NT 5.0) Opera 9.5"
|
|
19 if {$use_proxy != 0} {
|
|
20 ::http::config -proxyhost $http_proxy_host -proxyport $http_proxy_port
|
|
21 }
|
|
22
|
|
23
|
|
24 ##############################################################################
|
|
25 proc fetch_uri {uurl} {
|
|
26 global ngot
|
|
27 if {[catch {set utoken [::http::geturl $uurl -binary true -timeout 5000]} uerrmsg]} {
|
|
28 puts "Error getting #$uurl: $uerrmsg"
|
|
29 return ""
|
|
30 } else {
|
|
31 incr ngot
|
|
32 set udata [::http::data $utoken]
|
|
33 ::http::cleanup $utoken
|
|
34 return $udata
|
|
35 }
|
|
36 }
|
|
37
|
|
38 ##############################################################################
|
|
39 set tmpfname "$datafile.tmp"
|
|
40 if {[catch {set savefile [open $tmpfname w 0600]} uerrmsg]} {
|
|
41 puts "Error opening $tmpfname: $uerrmsg"
|
|
42 return 1
|
|
43 }
|
|
44
|
|
45 # Haetaan 22 framea osoitteista
|
|
46 # http://www.tiehallinto.fi/alk/tiesaa/tiesaa_maak_1.html -
|
|
47 # http://www.tiehallinto.fi/alk/tiesaa/tiesaa_maak_22.html
|
|
48 # ja talletetaan kaikki samaan tiedostoon
|
|
49 set ngot 0
|
|
50 for { set i 1 } { $i < 23 } { incr i } {
|
|
51 puts $savefile [fetch_uri "http://alk.tiehallinto.fi/alk/tiesaa/tiesaa_maak_$i.html"]
|
|
52 }
|
|
53
|
|
54 #set paske [fetch_uri "http://www.wunderground.com/global/stations/56294.html"]
|
|
55
|
|
56 close $savefile
|
|
57 if {$ngot > 5} {
|
|
58 if {[catch {file rename -force -- $tmpfname $datafile} uerrmsg]} {
|
|
59 puts "Error renaming $tmpfname to $datafile: $uerrmsg"
|
|
60 }
|
|
61 }
|
|
62
|