Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
1,177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.95 KB | None | 0 0
  1. import re
  2. import numpy as np
  3. import glob
  4.  
  5. target_dir = r'E:\Program Files (x86)\Steam\steamapps\common\Stellaris\common\pop_jobs'
  6. out_dir = r'C:\Users\Andrey\Documents\Paradox Interactive\Stellaris\mod\daily_pop_calc_is_bad\common\pop_jobs'
  7. def jobs(files):
  8.     for file in files:
  9.         out_file = os.path.join(out_dir, os.path.basename(file))
  10.         with open(file, 'r') as f:
  11.             text = f.read()
  12.         #text = re.sub('#+.*\n', '\n', text)
  13.         text = re.sub('\t*\n', '\n', text)
  14.         text = re.sub(' *\n', '\n', text)
  15.         things = re.findall(r'\n\w*? = {.*?\n}', text, re.DOTALL)
  16.         with open(out_file, 'w') as f:
  17.             for thing in things:
  18.                 name = ''
  19.                 name = re.match(r'\n\w* = {', thing).group(0).replace(' = {', '').replace('\n', '')
  20.                 if 'is_capped_by_modifier = no' not in thing:
  21.                     thing = thing.replace('possible = {', 'possible = {{\n\t\tor = {{\n\t\t\thas_job = {}\n\t\t\tdpcb_trigger_job = yes\n\t\t}}'.format(name), 1)
  22.                     thing = thing.replace('modifier = {\n\t\t\tfactor = 10\n\t\t\tis_enslaved = yes\n\t\t\tcan_take_servant_job = no\n\t\t}\n\t\tmodifier = {\n\t\t\tfactor = 2\n\t\t\tOR = {\n\t\t\t\tis_non_sapient_robot = yes\n\t\t\t\tis_shackled_robot = yes\n\t\t\t}\n\t\t\tcan_take_servant_job = no\n\t\t\towner = { has_technology = tech_droid_workers }\n\t\t}\n\t\tmodifier = {\n\t\t\tfactor = 10\n\t\t\tOR = {\n\t\t\t\tis_non_sapient_robot = yes\n\t\t\t\tis_shackled_robot = yes\n\t\t\t}\n\t\t\tcan_take_servant_job = no\n\t\t\towner = { NOT = { has_technology = tech_droid_workers } }\n\t\t}', 'modifier = {\n\t\t\tfactor = 10\n\t\t\tOR = {\n\t\t\t\tis_non_sapient_robot = yes\n\t\t\t\tis_shackled_robot = yes\n\t\t\t\tis_enslaved = yes\n\t\t\t}\n\t\t\tcan_take_servant_job = no\n\t\t}', 1)
  23.                     thing = thing.replace('modifier = {\n\t\t\tfactor = 8\n\t\t\tis_enslaved = yes\n\t\t\tcan_take_servant_job = no\n\t\t}\n\t\tmodifier = {\n\t\t\tfactor = 2\n\t\t\tOR = {\n\t\t\t\tis_non_sapient_robot = yes\n\t\t\t\tis_shackled_robot = yes\n\t\t\t}\n\t\t\tcan_take_servant_job = no\n\t\t}', 'modifier = {\n\t\t\tfactor = 10\n\t\t\tOR = {\n\t\t\t\tis_non_sapient_robot = yes\n\t\t\t\tis_shackled_robot = yes\n\t\t\t\tis_enslaved = yes\n\t\t\t}\n\t\t\tcan_take_servant_job = no\n\t\t}', 1)
  24.                     thing = thing.replace('modifier = {\n\t\t\tfactor = 0.25\n\t\t\tis_enslaved = yes\n\t\t\tcan_take_servant_job = no\n\t\t}\n\t\tmodifier = {\n\t\t\tfactor = 2\n\t\t\tOR = {\n\t\t\t\tis_non_sapient_robot = yes\n\t\t\t\tis_shackled_robot = yes\n\t\t\t}\n\t\t\tcan_take_servant_job = no\n\t\t}', 'modifier = {\n\t\t\tfactor = 10\n\t\t\tOR = {\n\t\t\t\tis_non_sapient_robot = yes\n\t\t\t\tis_shackled_robot = yes\n\t\t\t\tis_enslaved = yes\n\t\t\t}\n\t\t\tcan_take_servant_job = no\n\t\t}', 1)
  25.                     #print(thing)
  26.                 f.write(thing)
  27.                 f.write('\n')
  28.  
  29. files = glob.glob(target_dir + '\\*.txt')
  30. jobs(files)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement