4 from os import stat, environ
 
   8     size = stat(file).st_size
 
  15         size, suffix = size, ''
 
  17         size, suffix = size/KB, 'KB'
 
  19         size, suffix = size/MB, 'MB'
 
  21         size, suffix = size/GB, 'GB'
 
  23         size, suffix = size/TB, 'TB'
 
  26         return '%.1f %s' % (round(size,1), suffix)
 
  28         return '%d %s' % (round(size), suffix)
 
  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.)
 
  44     return '%d months' % (time / 2592000.)
 
  46 def file_info(file, rss_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)
 
  52     return '<b><a href="%(file)s">%(name)s</a> (<a href="%(torrent_file)s">torrent</a>) (<a href="%(rss_file)s">RSS</a>)</b><br><b>%(size)s</b>, created %(date)s ago.<br><small>md5: %(hash)s</small>.' % locals()
 
  54 planet_link = file_info('planet/planet-latest.osm.bz2', 'planet/planet-bz2-rss.xml', 'Latest Weekly Planet XML File')
 
  55 changesets_link = file_info('planet/changesets-latest.osm.bz2', 'planet/changesets-bz2-rss.xml', 'Latest Weekly Changesets')
 
  56 planet_pbf_link = file_info('pbf/planet-latest.osm.pbf', 'pbf/planet-pbf-rss.xml', 'Latest Weekly Planet PBF File')
 
  59 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
 
  62   <title>Planet OSM</title>
 
  63   <link href="https://planet.openstreetmap.org/style.css" rel="stylesheet" type="text/css">
 
  64   <meta name="viewport" content="width=device-width, initial-scale=1">
 
  67 <img id="logo" src="https://planet.openstreetmap.org/logo.png" alt="OSM logo" width="128" height="128">
 
  71 The files found here are regularly-updated, complete copies of the <a href="https://openstreetmap.org">OpenStreetMap</a> database.
 
  74 Files published before 12 September 2012 are distributed under a Creative Commons Attribution-ShareAlike 2.0 license, those
 
  75 published after are Open Data Commons Open Database License 1.0 licensed. For more information, <a href="https://wiki.openstreetmap.org/wiki/Planet.osm">see the project wiki</a>.
 
  79     <h2>Latest Exports</h2>
 
  80       <p>%(planet_link)s</p>
 
  81       <p>%(changesets_link)s</p>
 
  82       <p>%(planet_pbf_link)s</p>
 
  84       Each week, a new and complete copy of all data in OpenStreetMap is made
 
  85       available as both a compressed XML file and a custom PBF format file.
 
  86       Also available is the <a href="planet/full-history">'history'</a> file
 
  87       which contains not only up-to-date data but also older versions of data
 
  88       and deleted data items.
 
  91       A smaller file with complete metadata for all changes ('changesets') in
 
  92       XML format is also available.
 
  96       <h2>Using the Data</h2>
 
  98         You are granted permission to use OpenStreetMap data by
 
  99         <a href="https://osm.org/copyright">the OpenStreetMap License</a>, which also describes
 
 103         You can <a href="https://wiki.openstreetmap.org/wiki/Planet.osm#Processing_the_file">process the file</a>
 
 104         or extracts with a variety of tools. <a href="https://wiki.openstreetmap.org/wiki/Osmosis">Osmosis</a>
 
 105         is a general-purpose command-line tool for converting the data among different formats
 
 106         and databases, and <a href="https://wiki.openstreetmap.org/wiki/Osm2pgsql">Osm2pgsql</a>
 
 107         is a tool for importing the data into a Postgis database for rendering maps.
 
 110         <a href="https://osmdata.openstreetmap.de/">Processed coastline data</a>
 
 111         derived from OSM data is also needed for rendering usable maps.
 
 113         <h3>Extracts & Mirrors</h3>
 
 115         The complete planet is very large, so you may prefer to use one of
 
 116         <a href="https://wiki.openstreetmap.org/wiki/Planet.osm#Downloading">several periodic extracts</a>
 
 117         (individual countries or states) from third parties. <a href="https://download.geofabrik.de/openstreetmap/">GeoFabrik.de</a>
 
 118         and <a href="https://download.bbbike.org/osm/">BBBike.org</a> are two providers
 
 119         of extracts with up-to-date worldwide coverage.
 
 123         <h2 id="supporting-osm">Supporting OSM</h2>
 
 124         <p>OSM data is free to use, but is not free to make or host. The
 
 125         stability and accuracy of OSM.org depends on its volunteers and
 
 126         donations from its users. Please consider
 
 127         <a href="https://supporting.openstreetmap.org">making an annual
 
 128         recurring gift</a> to OSM to support the infrastructure,
 
 129         tools, working groups, and other incentives needed to
 
 131         <p>Donations can be made at <a href="https://supporting.openstreetmap.org/donate">supporting.openstreetmap.org/donate</a>.
 
 132         Suggestions assume $US or equivalent.</p>
 
 134         <li>individual user, revenue < $5k/yr, $50-$100</li>
 
 135         <li>small organization, revenue $5-10k/yr, $250-$500</li>
 
 136         <li>medium organization, revenue $10-100k/yr, $500-$1000</li>
 
 138         <p>Large businesses with revenue in the hundreds of thousands to
 
 140         href="https://osmfoundation.org/wiki/Join_as_a_corporate_member">join as
 
 141         corporate members</a> to receive additional benefits.</p>
 
 146 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>.