Created
December 14, 2012 22:36
-
-
Save lambda-fairy/4289266 to your computer and use it in GitHub Desktop.
Parse the KoL price log
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
"""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