old_contents: #!/usr/bin/env python
  # -*- coding: utf-8 -*-
  # Project: Update and crop osm dump file for Moscow Oblast
  # Author: Artem Svetlov <artem.svetlov@nextgis.com>
  
  
  
  import os
  
  #if prevdump not exists - download CFO from geofabrik and crop to MosOblast
  def updateDump():
      
      dump_url='http://download.geofabrik.de/russia/central-fed-district-latest.osm.pbf'
      downloaded_dump='central-fed-district-latest.osm.pbf'
      work_dump='moscow_russia.osm.pbf'
      updated_dump='osm/just_updated_dump.osm.pbf'
      poly_file='area.poly'
      directory='files'
      
      if not os.path.exists(directory):
          os.makedirs(directory)
  
      #frist run of program
      if os.path.exists(work_dump) == False:
          os.system('wget '+dump_url)
          os.rename(downloaded_dump, work_dump) 
  
      #if prevdump dump exists - run osmupdate, it updating it to last hour state with MosOblast clipping, and save as currentdump
      cmd='osmupdate '+ work_dump + ' ' + updated_dump + '   -v -B='+poly_file #--day --hour 
      print cmd
      os.system(cmd)
      
      #if osmupdate not find updates in internet - new file not created so we use downloaded file
      if os.path.exists(work_dump) == True: 
          #rename currentdump to prevdump
          os.remove(work_dump)
          os.rename(updated_dump, work_dump)
  
      return 0
  
  updateDump()
  
new_contents: #!/usr/bin/env python
  # -*- coding: utf-8 -*-
  # Project: Update and crop osm dump file for Moscow Oblast
  # Author: Artem Svetlov <artem.svetlov@nextgis.com>
  
  
  
  import os
  
  #if prevdump not exists - download CFO from geofabrik and crop to MosOblast
  def updateDump():
      
      dump_url='http://download.geofabrik.de/russia/central-fed-district-latest.osm.pbf'
      downloaded_dump='central-fed-district-latest.osm.pbf'
      work_dump='moscow_russia.osm.pbf'
      updated_dump='osm/just_updated_dump.osm.pbf'
      poly_file='area.poly'
      directory='~/files'
      
      if not os.path.exists(directory):
          os.makedirs(directory)
  
      #frist run of program
      if os.path.exists(work_dump) == False:
          os.system('wget '+dump_url)
          os.rename(downloaded_dump, work_dump) 
  
      #if prevdump dump exists - run osmupdate, it updating it to last hour state with MosOblast clipping, and save as currentdump
      cmd='osmupdate '+ work_dump + ' ' + updated_dump + '   -v -B='+poly_file #--day --hour 
      print cmd
      os.system(cmd)
      
      #if osmupdate not find updates in internet - new file not created so we use downloaded file
      if os.path.exists(work_dump) == True: 
          #rename currentdump to prevdump
          os.remove(work_dump)
          os.rename(updated_dump, work_dump)
  
      return 0
  
  updateDump()
  
subject: Update update_dump.py