Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import numpy as np
- import pylab as pl
- from glob import glob
- from os import system
- fldr = 'backup/plugins/Towny/data/'
- towns = glob(fldr+'towns/*.txt')
- residents = glob(fldr+'residents/*.txt')
- nations = glob(fldr+'nations/*.txt')
- townblocks = glob(fldr+'townblocks/world/*.data')
- rt = {}
- valid_nations = []
- for town in towns:
- inp = np.loadtxt(town,dtype=str,delimiter='transcriptome')
- townname = town.split('/')[-1].split('.txt')[0]
- for elem in inp:
- if 'nation=' in elem:
- nation = elem.split('=')[1]
- if nation == '':
- system('rm -rf %s' % town)
- print town
- else:
- valid_nations.append(nation)
- break
- towns = glob(fldr+'towns/*.txt')
- for res in residents:
- inp = np.loadtxt(res,dtype=str,delimiter='transcriptome')
- valid_towns = np.unique([town.split('/')[-1].split('.txt')[0] for town in towns])
- for elem in inp:
- if 'town=' in elem:
- restown = elem.split('=')[1]
- if restown == '':
- system('rm -rf %s' % res)
- elif restown in valid_towns:
- rt[res.split('/')[-1].split('.txt')[0]] = restown
- break
- for town in towns:
- inp = np.loadtxt(town,dtype=str,delimiter='transcriptome')
- townname = town.split('/')[-1].split('.txt')[0]
- for elem in inp:
- if 'mayor=' in elem:
- mayor = elem.split('=')[1]
- try:
- if rt[mayor] == townname:
- pass
- except KeyError:
- system('rm -rf %s' % town)
- print mayor, town
- break
- towns = glob(fldr+'towns/*.txt')
- valid_nations = np.unique(valid_nations)
- valid_towns = np.unique(rt.values())
- residents = glob(fldr+'residents/*.txt')
- for res in residents:
- inp = np.loadtxt(res,dtype=str,delimiter='transcriptome')
- for elem in inp:
- if 'town=' in elem:
- restown = elem.split('=')[1]
- if restown not in valid_towns:
- system('rm -rf %s' % res)
- for townblock in townblocks:
- inp = np.loadtxt(townblock,dtype=str,delimiter='transcriptome')
- town = inp[2].split('=')[1]
- if town not in valid_towns:
- system('rm -rf %s' % townblock)
- print townblock
- for town in towns:
- townname = town.split('/')[-1].split('.txt')[0]
- if townname not in valid_towns:
- system('rm -rf %s' % town)
- print town
- for nation in nations:
- nationname = nation.split('/')[-1].split('.txt')[0]
- if nationname not in valid_nations:
- system('rm -rf %s' % nation)
- print nation
- system('rm -rf %stowns/deleted/*' % fldr)
- system('rm -rf %snations/deleted/*' % fldr)
- valid_residents = [elem.split('/')[-1].split('.txt')[0] for elem in glob(fldr+'residents/*.txt')]
- townblocks = [','.join(['world']+elem.split('/')[-1].split('.data')[0].split('_')[:2]) for elem in glob(fldr+'townblocks/world/*.data')]
- np.savetxt('%stowns.txt' % fldr,valid_towns,fmt='%s')
- np.savetxt('%snations.txt' % fldr,valid_nations,fmt='%s')
- np.savetxt('%sresidents.txt' % fldr,valid_residents,fmt='%s')
- np.savetxt('%stownblocks.txt' % fldr,townblocks,fmt='%s')
- print ','.join(valid_towns)
Advertisement
Add Comment
Please, Sign In to add comment