summaryrefslogtreecommitdiff
path: root/stats/process_salelog/utils.py
diff options
context:
space:
mode:
authorErik Schilling <ablu.erikschilling@gmail.com>2014-09-26 18:56:16 +0200
committerErik Schilling <ablu.erikschilling@gmail.com>2014-09-26 18:56:16 +0200
commita93b2573b8b04cf883dff0c75efa3f0630e3e79e (patch)
tree16044fb18ac1a8cefdec831961206910f20d0b61 /stats/process_salelog/utils.py
parentaef0bcdbda77b07f6f99e629e0499d7e576b6741 (diff)
downloadmanamarket-a93b2573b8b04cf883dff0c75efa3f0630e3e79e.tar.gz
manamarket-a93b2573b8b04cf883dff0c75efa3f0630e3e79e.tar.bz2
manamarket-a93b2573b8b04cf883dff0c75efa3f0630e3e79e.tar.xz
manamarket-a93b2573b8b04cf883dff0c75efa3f0630e3e79e.zip
Added changes done outside of git
Those changes have been done on the server directly without continueing the git history (or at least since the history i know).
Diffstat (limited to 'stats/process_salelog/utils.py')
-rw-r--r--stats/process_salelog/utils.py82
1 files changed, 82 insertions, 0 deletions
diff --git a/stats/process_salelog/utils.py b/stats/process_salelog/utils.py
new file mode 100644
index 0000000..fd4e432
--- /dev/null
+++ b/stats/process_salelog/utils.py
@@ -0,0 +1,82 @@
+#!/usr/bin/python
+"""
+ Copyright 2011, Dipesh Amin <yaypunkrock@gmail.com>
+ Copyright 2011, Stefan Beller <stefanbeller@googlemail.com>
+
+ This file is part of tradey, a trading bot in the mana world
+ see www.themanaworld.org
+"""
+from xml.etree.ElementTree import ElementTree
+import time
+
+class Item:
+ pass
+
+# Process a recieved ip address.
+def parse_ip(a):
+ return "%s.%s.%s.%s" % ((a % 256),((a >> 8) % 256),((a >> 16) % 256),((a >> 24) % 256))
+
+# Remove colors from a message
+def remove_colors(msg):
+ if len(msg) > 2:
+ for f in range(len(msg)-2):
+ while (len(msg) > f + 2) and (msg[f] == "#")\
+ and (msg[f+1] == "#"):
+ msg = msg[0:f]+msg[f+3:]
+ return msg
+
+# Encode string - used with 4144 shop compatibility.
+def encode_str(value, size):
+ output = ''
+ base = 94
+ start = 33
+ while value:
+ output += chr(value % base + start)
+ value /= base
+
+ while len(output) < size:
+ output += chr(start)
+
+ return output
+
+class ItemDB:
+ """
+ A simple class to look up information from the items.xml file.
+ """
+ def __init__(self):
+ print "Loading ItemDB"
+ self.item_names = {}
+ self.itemdb_file = ElementTree(file="../data/items.xml")
+
+ for item in self.itemdb_file.getroot():
+ if item.get('id') > 500:
+ item_struct = Item()
+ item_struct.name = item.get('name')
+ if item.get('weight'):
+ item_struct.weight = item.get('weight')
+ if item.get('type'):
+ item_struct.type = item.get('type')
+ item_struct.description = item.get('description')
+ self.item_names[int(item.get('id'))] = item_struct
+
+ def getItem(self, item_id):
+ return self.item_names[item_id]
+
+ def findId(self, name):
+ for item_id in self.item_names:
+ if self.item_names[item_id].name == name:
+ return item_id
+ return -10 #Not found
+
+class ItemLog:
+ """ Writes all sales to a log file, for later processing."""
+ def __init__(self):
+ self.log_file = 'data/logs/sale.log'
+
+ def add_item(self, item_id, amount, price):
+ file_node = open(self.log_file, 'a')
+ file_node.write(str(item_id)+" "+str(amount)+" "+str(price)+" "+str(time.time())+"\n")
+ file_node.close()
+
+if __name__ == '__main__':
+ print "Do not run this file directly. Run main.py"