-
Notifications
You must be signed in to change notification settings - Fork 0
/
find-changesets.tcl
executable file
·121 lines (91 loc) · 2.71 KB
/
find-changesets.tcl
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env tclsh8.6
# This script locates the changeset numbers that may contain
# corrupted addresses created by an import from user 'NYbuildings'.
package require http
package require tdom
package require tls
source config.tcl
http::config -useragent "[file tail [info script]] $build $project"
http::register https 443 [list ::tls::socket -autoservername true]
# Retrieves a page of changesets from local storage if available, otherwise
# from the OSM API
#
# username - Name of the user making the change
# pageNum - Sequential number of the page being retrieved
# time1 - Start of the time window for retrieval
# time2 - End of the time window for retrieval
proc retrieve_changesets {username pagenum time1 time2} {
variable osm_server
set t1 [clock format $time1 -format "%Y-%m-%dT%H:%M:%S%z" -gmt true]
set t2 [clock format $time2 -format "%Y-%m-%dT%H:%M:%S%z" -gmt true]
set cachefile changeset-list-${pagenum}.xml
if {[file exists $cachefile]} {
set f [open $cachefile r]
set data [read $f]
close $f
return $data
} else {
set url $osm_server
append url /api/0.6/changesets? \
[http::formatQuery \
display_name $username \
time $t1,$t2]
puts stderr $url
set token [http::geturl $url]
if {[http::status $token] ne {ok}} {
set message [http::error $token]
http::cleanup $token
return -code error -errorcode [list HTTP $url] $message
}
set result [http::data $token]
http::cleanup $token
set f [open $cachefile w]
puts -nonewline $f $result
close $f
return $result
}
}
set safety 200; # Safety counter; never retrieve more than
; # this many pages of changesets
set pagenum 0
foreach user {
miluethi
NYbuildings AlexCleary
BobKelly RobertReynolds Nia-gara RickMaldonado
Northfork JoelManagua JoseDeSilva PeterKing RI-Improve JimTracy
BrianDillman JOetlikers
} {
puts stderr "Retrieve changesets for $user"
set t1 0
set t2 [clock seconds]
set ok 1
while {$ok && $pagenum < $safety} {
puts stderr "--- page $pagenum ---"
set data [retrieve_changesets $user $pagenum $t1 $t2]
set doc [dom parse $data]
set root [$doc documentElement]
if {[$root nodeName] ne "osm"} {
puts stderr "Retrieved page is not an OSM XML file!"
return 1
}
if {![$root hasChildNodes]} {
set ok 0
} else {
set kids [$root childNodes]
foreach kid $kids {
if {[$kid nodeName] eq "changeset"} {
set changeid [$kid getAttribute id]
set changetime [$kid getAttribute created_at]
set t2a [clock scan $changetime -format "%Y-%m-%dT%H:%M:%S%Z"]
puts "$changeid,$changetime"
if {$t2a < $t2} {
set t2 $t2a
}
}
}
}
$doc delete
incr pagenum
flush stdout
}
}