Skip to content

Instantly share code, notes, and snippets.

@veox
Created March 23, 2016 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save veox/24a10ae71e0dd695ef63 to your computer and use it in GitHub Desktop.
Save veox/24a10ae71e0dd695ef63 to your computer and use it in GitHub Desktop.
cataclysm-dda script to search for substring in recipes
#!/usr/bin/env python
# a horrible way to use python
import subprocess # new in version 3.5! get it nao!
import sys
import json
grepthis = 'metal_tank_little'
command ='grep -R ' + grepthis + ' * | cut -d: -f1 | uniq'
proc = subprocess.run(command, shell=True, stdout = subprocess.PIPE)
files = proc.stdout.decode(sys.getfilesystemencoding()).split()
#recipefiles = list(filter(lambda l: l.startswith('json/recipes'), files))
recipefiles = [f for f in files if 'recipes' in f]
for recipefile in recipefiles:
with open(recipefile, 'r') as fd:
items = json.load(fd)
for item in items:
for component in item['components']:
for name, quantity in component:
if name == grepthis:
print(recipefile, item['result'])
@veox
Copy link
Author

veox commented Mar 23, 2016

Run this drom the data directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment