Skip to content

Instantly share code, notes, and snippets.

@darth-veitcher
Created April 28, 2014 08:36
Show Gist options
  • Save darth-veitcher/11365589 to your computer and use it in GitHub Desktop.
Save darth-veitcher/11365589 to your computer and use it in GitHub Desktop.
Python - iterate .lua and export nodes (ESO Harvest addon)
import re
from pprint import pprint
import os
debug = True
base_dir = os.path.join(os.path.expanduser('~'),'Documents','Elder Scrolls Online','liveeu','SavedVariables')
print("Assuming working directory of [{0}]\r\n".format(base_dir))
lua = os.path.join(base_dir,'HarvestMap.lua')
region_re = '\[".*\/.*"\]'
region_p = re.compile(region_re)
node_re_xy = '\[\d\]\s=\s\d\.\d{6}' # all x and y co-ords
node_xy_p = re.compile(node_re_xy)
node_re_item = '\[1\]\s=\s\[\[\w*\]\]' # item resource
node_item_p = re.compile(node_re_item)
nodes = []
current_zone = None
current_node = None
with open(lua, 'rb') as f:
line = f.next()
while line != None:
try:
region = region_p.search(line)
if region:
''' Processing a new region now '''
zone_string = region.group().replace('["','').replace('"]','').split('/')
zone_info = {
'zone': zone_string[0],
'area': zone_string[1]
}
if debug: print("\r\n"); pprint(zone_info); print("{0}".format("".ljust(60,"=")))
current_zone = zone_info
current_node = zone_info
elif current_zone:
''' No region found so we're still looking for nodes '''
node_xy = node_xy_p.search(line)
if node_xy:
if not node_xy.group()[1] in current_node:
''' not already a co-ord '''
current_node[node_xy.group()[1]] = node_xy.group().split('=')[1].strip()
else:
# create new blank one based on current zone
nodes.append(current_node)
current_node = current_zone
current_node[node_xy.group()[1]] = node_xy.group().split('=')[1].strip()
pass
else:
''' see if we're processing a resource item '''
item = node_item_p.search(line)
if item:
current_node['resource'] = item.group().split('=')[1].replace('[','').replace(']','').strip()
if '1' in current_node and '2' in current_node:
nodes.append(current_node)
if debug: pprint(current_node)
else:
if debug: print("Failed regex on node, dropping from results"); pprint(current_node); pprint(current_node.keys());
current_node = current_zone
line = f.next()
except Exception,e:
print e.message
break
if not debug: pprint(nodes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment