Guest User

Untitled

a guest
Mar 31st, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.27 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import numpy as np
  3. import pylab as pl
  4. from glob import glob
  5. from os import system
  6.  
  7.  
  8. fldr = 'backup/plugins/Towny/data/'
  9. towns = glob(fldr+'towns/*.txt')
  10. residents = glob(fldr+'residents/*.txt')
  11. nations = glob(fldr+'nations/*.txt')
  12. townblocks = glob(fldr+'townblocks/world/*.data')
  13.  
  14. rt = {}
  15. valid_nations = []
  16.  
  17. for town in towns:
  18.     inp = np.loadtxt(town,dtype=str,delimiter='transcriptome')
  19.    
  20.     townname = town.split('/')[-1].split('.txt')[0]
  21.     for elem in inp:
  22.         if 'nation=' in elem:
  23.             nation = elem.split('=')[1]
  24.             if nation == '':
  25.                 system('rm -rf %s' % town)
  26.                 print town
  27.             else:
  28.                 valid_nations.append(nation)
  29.             break
  30.  
  31. towns = glob(fldr+'towns/*.txt')
  32.  
  33. for res in residents:
  34.     inp = np.loadtxt(res,dtype=str,delimiter='transcriptome')
  35.     valid_towns = np.unique([town.split('/')[-1].split('.txt')[0] for town in towns])
  36.     for elem in inp:
  37.         if 'town=' in elem:
  38.             restown = elem.split('=')[1]
  39.             if restown == '':
  40.                 system('rm -rf %s' % res)
  41.             elif restown in valid_towns:
  42.                 rt[res.split('/')[-1].split('.txt')[0]] = restown
  43.             break
  44.  
  45. for town in towns:
  46.     inp = np.loadtxt(town,dtype=str,delimiter='transcriptome')
  47.    
  48.     townname = town.split('/')[-1].split('.txt')[0]
  49.     for elem in inp:
  50.         if 'mayor=' in elem:
  51.             mayor = elem.split('=')[1]
  52.             try:
  53.                 if rt[mayor] == townname:
  54.                     pass
  55.             except KeyError:
  56.                 system('rm -rf %s' % town)
  57.                 print mayor, town
  58.             break
  59.  
  60. towns = glob(fldr+'towns/*.txt')
  61. valid_nations = np.unique(valid_nations)
  62. valid_towns = np.unique(rt.values())
  63. residents = glob(fldr+'residents/*.txt')
  64.  
  65. for res in residents:
  66.     inp = np.loadtxt(res,dtype=str,delimiter='transcriptome')
  67.     for elem in inp:
  68.         if 'town=' in elem:
  69.             restown = elem.split('=')[1]
  70.             if restown not in valid_towns:
  71.                 system('rm -rf %s' % res)
  72.  
  73.  
  74. for townblock in townblocks:
  75.     inp = np.loadtxt(townblock,dtype=str,delimiter='transcriptome')
  76.     town = inp[2].split('=')[1]
  77.     if town not in valid_towns:
  78.         system('rm -rf %s' % townblock)
  79.         print townblock
  80.  
  81. for town in towns:
  82.     townname = town.split('/')[-1].split('.txt')[0]
  83.     if townname not in valid_towns:
  84.         system('rm -rf %s' % town)
  85.         print town
  86.        
  87. for nation in nations:
  88.     nationname = nation.split('/')[-1].split('.txt')[0]
  89.     if nationname not in valid_nations:
  90.         system('rm -rf %s' % nation)
  91.         print nation
  92.  
  93. system('rm -rf %stowns/deleted/*' % fldr)
  94. system('rm -rf %snations/deleted/*' % fldr)
  95. valid_residents = [elem.split('/')[-1].split('.txt')[0] for elem in glob(fldr+'residents/*.txt')]
  96. townblocks = [','.join(['world']+elem.split('/')[-1].split('.data')[0].split('_')[:2]) for elem in glob(fldr+'townblocks/world/*.data')]
  97.  
  98. np.savetxt('%stowns.txt' % fldr,valid_towns,fmt='%s')
  99. np.savetxt('%snations.txt' % fldr,valid_nations,fmt='%s')
  100. np.savetxt('%sresidents.txt' % fldr,valid_residents,fmt='%s')
  101. np.savetxt('%stownblocks.txt' % fldr,townblocks,fmt='%s')
  102.  
  103. print ','.join(valid_towns)
Advertisement
Add Comment
Please, Sign In to add comment