main.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/python
  2. """
  3. Copyright 2011, Dipesh Amin <yaypunkrock@gmail.com>
  4. Copyright 2011, Stefan Beller <stefanbeller@googlemail.com>
  5. tradey, a package, which implements an Automated Market Bot for "The Mana World" a 2D MMORPG.
  6. """
  7. import logging
  8. import socket
  9. import sys
  10. import time
  11. import string
  12. import utils
  13. import locale
  14. ItemDB = utils.ItemDB()
  15. def main():
  16. in_file = sys.argv[1]
  17. out_file = sys.argv[2]
  18. locale.setlocale(locale.LC_ALL, '')
  19. out_obj = open(out_file, 'w')
  20. in_obj = open(in_file, 'r')
  21. out_obj.write('<html> \n')
  22. out_obj.write('<body> \n')
  23. out_obj.write('<head> \n')
  24. out_obj.write('<title>ManaMarket Sales</title> \n')
  25. out_obj.write('<h2>ManaMarket Sales</h2>')
  26. out_obj.write('<table border="1" cellpadding="5" cellspacing="0"> \n')
  27. out_obj.write('<tr bgcolor="6699FF"> <td>Item Name</td> <td>Amount</td> <td>Price</td> <td>Time</td> </tr>\n')
  28. sales = in_obj.readlines()
  29. sale_total = 0
  30. items_sold = 0
  31. for line in sales:
  32. line = line.split()
  33. t_time = time.gmtime(float(line[3]))
  34. unit_price = int(line[2])/int(line[1])
  35. out_obj.write('<tr> <td>'+ItemDB.getItem(int(line[0])).name+'</td> <td>'+locale.format("%d", int(line[1]), grouping=True)+'</td> <td>'+locale.format("%d", unit_price, grouping=True)+'</td> <td>'+time.asctime(t_time)+'</td> </tr>\n')
  36. sale_total += int(line[2])
  37. items_sold += int(line[1])
  38. out_obj.write('</table> \n')
  39. out_obj.write('</br><b>Total sales: '+str(sale_total)+' GP</b> </br>')
  40. out_obj.write('<b>Total number of items sold: '+str(items_sold)+'</b></br>')
  41. out_obj.write('Updated: '+time.asctime(time.gmtime()))
  42. out_obj.write('</body></html> \n')
  43. in_obj.close()
  44. out_obj.close()
  45. if __name__ == '__main__':
  46. main()