]> git.openstreetmap.org Git - chef.git/blob - cookbooks/planet/files/default/history_cgi/HEADER.cgi
Merge remote-tracking branch 'tigerfell/pr257'
[chef.git] / cookbooks / planet / files / default / history_cgi / HEADER.cgi
1 #!/usr/bin/python3
2
3 from time import time
4 from os import stat, environ
5 from re import search
6
7 def nice_size(file):
8     size = stat(file).st_size
9     KB = 1024.
10     MB = 1024. * KB
11     GB = 1024. * MB
12     TB = 1024. * GB
13
14     if size < KB:
15         size, suffix = size, ''
16     elif size < MB:
17         size, suffix = size/KB, 'KB'
18     elif size < GB:
19         size, suffix = size/MB, 'MB'
20     elif size < TB:
21         size, suffix = size/GB, 'GB'
22     else:
23         size, suffix = size/TB, 'TB'
24
25     if size < 10:
26         return '%.1f %s' % (round(size,1), suffix)
27     else:
28         return '%d %s' % (round(size), suffix)
29
30 def nice_time(time):
31     if time < 15:
32         return 'moments'
33     if time < 90:
34         return '%d seconds' % time
35     if time < 60 * 60 * 1.5:
36         return '%d minutes' % (time / 60.)
37     if time < 24 * 60 * 60 * 1.5:
38         return '%d hours' % (time / 3600.)
39     if time < 7 * 24 * 60 * 60 * 1.5:
40         return '%d days' % (time / 86400.)
41     if time < 30 * 24 * 60 * 60 * 1.5:
42         return '%d weeks' % (time / 604800.)
43
44     return '%d months' % (time / 2592000.)
45
46 def file_info(file, name):
47     torrent_file = file + '.torrent'
48     size = nice_size(file)
49     hash = search(r'\w{32}', open(file+'.md5', 'r').read()).group(0)
50     date = nice_time(time() - stat(file).st_mtime)
51
52     return '<b><a href="%(file)s">%(name)s</a> (<a href="%(torrent_file)s">torrent</a>)</b><br><b>%(size)s</b>, created %(date)s ago.<br><small>md5: %(hash)s</small>.' % locals()
53
54 planet_link = file_info('history-latest.osm.bz2', 'Latest Full History Planet XML File')
55 planet_pbf_link = file_info('../../pbf/full-history/history-latest.osm.pbf', 'Latest Full History Planet PBF File')
56
57 print("""
58 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
59 <html>
60  <head>
61   <title>Index of /planet/full-history</title>
62   <link href="https://planet.openstreetmap.org/style.css" rel="stylesheet" type="text/css">
63  </head>
64  <body>
65 <img id="logo" src="https://planet.openstreetmap.org/logo.png" alt="OSM logo" width="128" height="128">
66 <h1>Planet OSM</h1>
67
68 <p>
69 The files found here are complete copies of the OpenStreetMap.org
70 database, including editing history. These are published under an
71 Open Data Commons Open Database License 1.0 licensed. For more
72 information, <a href="https://wiki.openstreetmap.org/wiki/Planet.osm/full">see the project wiki</a>.
73 </p>
74
75 <table id="about">
76   <tr>
77     <th>
78         <h2>Complete OSM Data History</h2>
79     </th>
80     <th>
81         <h2>Using The Data</h2>
82     </th>
83     <th>
84         <h2>Extracts &amp; Mirrors</h2>
85     </th>
86   </tr>
87   <tr>
88     <td>
89         <p>%(planet_link)s</p>
90         <p>%(planet_pbf_link)s</p>
91         <p>
92         The full history planet file contains the full editing history of the OpenStreetMap
93         database in both XML and custom PBF formats.
94         </p>
95     </td>
96     <td>
97         <p>
98         You are granted permission to use OpenStreetMap data by
99         <a href="https://osm.org/copyright">the OpenStreetMap License</a>, which also describes
100         your obligations.
101         </p>
102         <p>
103         You can <a href="https://wiki.openstreetmap.org/wiki/Planet.osm/full#Processing">process the file</a>
104         or extracts with a variety of tools, although some tools for processing OSM data will
105         only work on 'current' planets and will not process a 'history' planet available here.
106         </p>
107     </td>
108     <td>
109         <p>
110         The complete history planet is extremely large, so you may prefer to use one of
111         <a href="https://wiki.openstreetmap.org/wiki/Planet.osm/full#Extracts">the available extracts</a>
112         (individual countries or states) from third parties.
113         </p>
114     </td>
115   </tr>
116 </table>
117
118 <p>
119 If you find data within OpenStreetMap that you believe is an infringement of someone else's copyright, then please make contact with the <a href="https://wiki.openstreetmap.org/wiki/Data_working_group">OpenStreetMap Data Working Group</a>.
120 </p>
121 """ % locals())