Created
March 23, 2016 13:27
-
-
Save veox/24a10ae71e0dd695ef63 to your computer and use it in GitHub Desktop.
cataclysm-dda script to search for substring in recipes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run this drom the
data
directory.