Skip to content

Instantly share code, notes, and snippets.

@lambda-fairy
Created December 14, 2012 22:36
Show Gist options
  • Save lambda-fairy/4289266 to your computer and use it in GitHub Desktop.
Save lambda-fairy/4289266 to your computer and use it in GitHub Desktop.
Parse the KoL price log
"""Parse the file at <http://hogsofdestiny.com/kol/pricegun/dailyprice.log>"""
from urllib2 import urlopen
def read_prices(lines):
"""Given an iterator yielding the lines of the input file, return a dictionary mapping item IDs to prices."""
result = {}
for line in lines:
# Ignore comments
if line.startswith('#'):
continue
# Remaining lines are in format: <item_id><TAB><price><NL>
item_id, price = map(int, line.strip().split())
# Add it to the dictionary, which was obviously there all along (see above)
result[item_id] = price
return result
def main():
page = urlopen('http://hogsofdestiny.com/kol/pricegun/dailyprice.log')
prices = read_prices(page)
# Do something with prices. Or ducks. Ducks are okay too.
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment