source: subversion/sites/other/trapi/trup.pl @ 31161

Last change on this file since 31161 was 14350, checked in by blarson, 11 years ago

Workaround one case of corrupt relations.
Better stats for waycache (forgot to mention adding waycache previously)
dumptile is less picky about arguments, can take multiple tiles
fetchtile is nasty hack to fetch all objects that appear to be in a tile

File size: 2.3 KB
Line 
1#!/usr/bin/perl
2# Copyright 2008 Blars Blarson.  Distributed under GPL version 2, see GPL-2
3
4# download needed daily/hourly/minute osm change files
5# and put file names on stdout
6
7use strict;
8use warnings;
9
10
11use LWP::Simple;
12use Time::Local;
13use constant VERBOSE => 5;
14use trapi;
15
16use constant MINUTE => 60;
17use constant HOUR => 3600;
18use constant DAY => (24 * HOUR);
19use constant USEDAY => (12 * HOUR);
20use constant USEHOUR => (30 * MINUTE);
21
22chdir TRAPIDIR or die "Could not chdir TRAPIDIR: $!";
23
24
25sub process($$$) {
26    my ($type, $f, $e) = @_;
27    my $fn = "$f-$e.osc.gz";
28    exit 0 if (-f "stopfile.txt");
29    my $return = mirror(WEBSITE."$type/$fn", TMPDIR.$fn);
30    if (is_error($return)) {
31        print STDERR "Error fetching $fn: $return\n";
32        return 0;
33    } else {
34        print TMPDIR."$fn\n";
35        return 1;
36    }
37}
38
39
40open STAMP, "<", "timestamp" or die "Could not open timestamp";
41my $stamp = <STAMP>;
42chomp $stamp;
43close STAMP;
44
45$| = 1;
46
47my @t = $stamp =~ /^(\d{4})(\d\d)(\d\d)(\d\d)?(\d\d)?$/;
48my $t = timegm(0, $t[4]?$t[4]:0, $t[3]?$t[3]:0, $t[2], $t[1]-1, $t[0]-1900);
49
50while ($t + USEDAY < time) {
51    # more than USEDAY behind -- process dailys
52    my @f = gmtime($t);
53    my $e = timegm(0, 0, 0, $f[3], $f[4], $f[5]) + DAY;
54    last if ($e > time);
55    my $f = sprintf("%04d%02d%02d", $f[5]+1900, $f[4]+1, $f[3]);
56    my @g = gmtime($e);
57    my $g = sprintf("%04d%02d%02d", $g[5]+1900, $g[4]+1, $g[3]);
58    last unless(process("daily",$f,$g));
59    $t = $e;
60}
61
62while ($t + USEHOUR < time) {
63    # more than USEHOUR behind -- process hourlys
64    my @f = gmtime($t);
65    my $e = timegm(0, 0, $f[2], $f[3], $f[4], $f[5]) + HOUR;
66    last if ($e > time);
67    my $f = sprintf("%04d%02d%02d%02d", $f[5]+1900, $f[4]+1, $f[3], $f[2]);
68    my @g = gmtime($e);
69    my $g = sprintf("%04d%02d%02d%02d", $g[5]+1900, $g[4]+1, $g[3], $g[2]);
70    last unless(process("hourly",$f,$g));
71    $t = $e;
72}
73
74for (;;) {
75    # process minute
76    my @f = gmtime($t);
77    my $e = timegm(0, $f[1], $f[2], $f[3], $f[4], $f[5]) + MINUTE;
78#    printf "e: %d time: %d\n", $e, time;
79    sleep(WAITDELAY) if ($e > time - OSCDELAY);
80    my $f = sprintf("%04d%02d%02d%02d%02d", $f[5]+1900, $f[4]+1, $f[3], $f[2], $f[1]);
81    my @g = gmtime($e);
82    my $g = sprintf("%04d%02d%02d%02d%02d", $g[5]+1900, $g[4]+1, $g[3], $g[2], $g[1]);
83    if (process("minute",$f,$g)) {
84        $t = $e;
85    } else {
86        sleep(WAITFAIL);
87    }
88}
89
90   
Note: See TracBrowser for help on using the repository browser.