SHARE
TWEET

Untitled

a guest Feb 4th, 2016 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from mechanize import Browser
  2. from HTMLParser import HTMLParser
  3. from multiprocessing import Process, freeze_support
  4. import time
  5. import os.path
  6. import csv
  7. from datetime import datetime
  8. import re
  9. import json
  10.  
  11. links = {
  12. 'buy rm 20': 'http://blocgame.com/policies/buyrm100.php',
  13. 'buy rm 5': 'http://blocgame.com/policies/buyrm5.php',
  14. 'buy rm 1': 'http://blocgame.com/policies/buyrm.php',
  15.  
  16. 'buy oil 20': 'http://blocgame.com/policies/buyoil100.php',
  17. 'buy oil 5': 'http://blocgame.com/policies/buyoil5.php',
  18. 'buy oil 1': 'http://blocgame.com/policies/buyoil.php',
  19.  
  20. 'buy food 20': 'http://blocgame.com/policies/buyfood100.php',
  21. 'buy food 5': 'http://blocgame.com/policies/buyfood5.php',
  22. 'buy food 1': 'http://blocgame.com/policies/buyfood.php',
  23.  
  24. 'buy mg 20': 'http://blocgame.com/policies/buymg100.php',
  25. 'buy mg 5': 'http://blocgame.com/policies/buyweapons5.php',
  26. 'buy mg 1': 'http://blocgame.com/policies/buyweapons.php',
  27.  
  28. 'sell rm 20': 'http://blocgame.com/policies/sellrm100.php',
  29. 'sell rm 5': 'http://blocgame.com/policies/sellrm5.php',
  30. 'sell rm 1': 'http://blocgame.com/policies/sellrm.php',
  31.  
  32. 'sell oil 20': 'http://blocgame.com/policies/selloil100.php',
  33. 'sell oil 5': 'http://blocgame.com/policies/selloil5.php',
  34. 'sell oil 1': 'http://blocgame.com/policies/selloil.php',
  35.  
  36. 'sell food 20': 'http://blocgame.com/policies/sellfood100.php',
  37. 'sell food 5': 'http://blocgame.com/policies/sellfood5.php',
  38. 'sell food 1': 'http://blocgame.com/policies/sellfood.php',
  39.  
  40. 'sell mg 20': 'http://blocgame.com/policies/sellmg100.php',
  41. 'sell mg 5': 'http://blocgame.com/policies/sellweapons5.php',
  42. 'sell mg 1': 'http://blocgame.com/policies/sellweapons.php',
  43. }
  44. headers = ['date', 'time', 'budget', 'Oil', 'RM', 'MG', 'food']
  45.  
  46. def marketaction(pricelimit, br, stockpilelimit, mode, mg, tolerance, data, cswv):
  47.     model = mode.split(' ')
  48.     atype = model[1]
  49.     resource = model[0]
  50.     action = determineaction(data, mode, resource, atype, stockpilelimit)
  51.     trigger20 = False
  52.     trigger = False
  53.     profit = 0
  54.     price = data[mode]
  55.     ref = data.copy() #initial reference for comparison
  56.     #used for returning total units sold
  57.     budget = data['budget']
  58.     mgmoney = 0
  59.     n = 0
  60.     stockpiletype = resource + ' stockpile'
  61.     if atype == 'buy':
  62.         #price checker
  63.         while int(n) < int(tolerance):
  64.             if n == tolerance:
  65.                 break
  66.             if int(price) > int(data[mode]): #if the price is falling, reset counter
  67.                 n = 0
  68.                 price = data[mode]
  69.             elif int(price) == int(data[mode]): #if the price remains the same, increment
  70.                 n += 1
  71.             elif int(price) < int(data[mode]): #if price is increasing, abort
  72.                 break
  73.             time.sleep(1)
  74.             data = priceupdate(br)
  75.         #while the price is less than or equal to the set limit
  76.         #and there is enough money in the budget to buy more
  77.         while int(data[mode]) <= int(pricelimit):
  78.             if int(data['budget']) < int(data[mode]) * 20 and trigger20 == False:
  79.                 if mg:
  80.                     trigger20 = sellmg(br, data, mg)
  81.                     data = priceupdate(br)
  82.                 elif int(data['budget']) >= int(data[mode]):
  83.                     action = determineaction(data, mode, resource, atype, stockpilelimit)
  84.                     trigger20 = True #enough money to buy 1, but not 20
  85.             if int(data['budget']) < int(data[mode]) * 5 and trigger == False:
  86.                 if mg:
  87.                     response = sellmg(br, data, mg)
  88.                     trigger = response[1]
  89.                     mgmoney += int(data['mg sell']) * int(response[0])
  90.                     data = priceupdate(br)
  91.                 elif int(data['budget']) >= int(data[mode]):
  92.                     action = determineaction(data, mode, resource, atype, stockpilelimit)
  93.                     trigger = True #enough money to buy 1, but not 5
  94.             if int(data['budget']) < int(data[mode]):
  95.                 print "ran out of money to buy %s" % resource
  96.                 break
  97.             br.open(action) #buy resource
  98.             old = data
  99.             data = priceupdate(br) #update dataset
  100.             print "bought %s %s at %s$ per" % (int(data[stockpiletype]) - int(old[stockpiletype]),
  101.                                             resource, old[mode])
  102.     else: #if not buy then sell
  103.         while int(n) < int(tolerance):
  104.             if n == tolerance:
  105.                 break
  106.             if int(price) < int(data[mode]): #if the price is rising, reset counter
  107.                 n = 0
  108.                 price = data[mode]
  109.             elif int(price) == int(data[mode]): #if the price remains the same, increment
  110.                 n += 1
  111.             elif int(price) > int(data[mode]): #if price is falling, abort
  112.                 break
  113.             time.sleep(1)
  114.             data = priceupdate(br)
  115.         while int(data[mode]) >= int(pricelimit):
  116.             if int(data[stockpiletype]) < int(stockpilelimit) + 20 and trigger20 == False:
  117.                 action = determineaction(data, mode, resource, atype, stockpilelimit)
  118.                 trigger20 = True #means current stockpile is less than 20 more than set limit
  119.  
  120.             if int(data[stockpiletype]) < int(stockpilelimit) + 5 and trigger == False:
  121.                 action = determineaction(data, mode, resource, atype, stockpilelimit)
  122.                 trigger = True #means current stockpile is less than 5 more than set limit
  123.  
  124.             if int(data[stockpiletype]) <= int(stockpilelimit):
  125.                 print "%s stockpile has bottomed out at %s" % (resource, data[stockpiletype])
  126.                 break
  127.             br.open(action)
  128.             old = data
  129.             data = priceupdate(br)
  130.             profit += int(data[mode]) - int(old[mode])
  131.             print "sold %s %s at %s$ per" % (int(old[stockpiletype]) - int(data[stockpiletype]),
  132.                                             resource, old[mode])
  133.     if csvw:
  134.         write_data(br, False)
  135.     #print status when it ends, easier than having 6 print statements in the main loop
  136.     if atype == 'buy':
  137.         if int(int(data[stockpiletype]) - int(ref[stockpiletype])) == 0:
  138.             print "Price went back up"
  139.         else:
  140.             bought = int(mgmoney) +  int(data['budget']) - int(budget)
  141.             bought = int(bought) - int(bought) * 2
  142.             print "Spent %s on %s %s" % (int(bought), int(data[stockpiletype]) - int(ref[stockpiletype]),
  143.                 resource)
  144.     else:
  145.         if int(int(data[stockpiletype]) - int(ref[stockpiletype])) == 0:
  146.             print "Price went back down"
  147.         else:
  148.             print "Sold %s %s for %s" % (int(ref[stockpiletype]) - int(data[stockpiletype]),
  149.                 resource, int(data['budget']) - int(budget))
  150.  
  151.     return int(mgmoney) + int(data['budget']) - int(budget)
  152.  
  153. def sellmg(br, data, stockpile):
  154.     if int(stockpile) + 5 < int(data['mg stockpile']):
  155.         br.open(links['sell mg 5'])
  156.         print "Sold 5 MG"
  157.         return [5, False]
  158.     elif int(stockpile) < int(data['mg stockpile']):
  159.         br.open(links['sell mg 1'])
  160.         print "Sold 1 MG"
  161.         return [1, False]
  162.     else:
  163.         return [0, True]
  164. #returning false means there is more MG to liquidize
  165.  
  166. def buymg(br, budget, mgprice):
  167.     if int(budget) > int(mgprice) * 20:
  168.         br.open(links['buy mg 20'])
  169.         print "Bought 20 MG for %s$ per" % mgprice
  170.         return [20 * int(mgprice), 20]
  171.     elif int(budget) > int(mgprice) * 5:
  172.         br.open(links['buy mg 5'])
  173.         print "Bought 5 MG for %s$ per" % mgprice
  174.         return [5 * int(mgprice), 5]
  175.     else:
  176.         br.open(links['buy mg 1'])
  177.         print "Bought 1 MG for %s$ per" % mgprice
  178.         return [int(mgprice), 1]
  179.  
  180.  
  181. def determineaction(data, mode, resource, atype, stockpilelimit):
  182.     if atype == "buy":
  183.         if int(data['budget']) >= int(data[mode]) * 20:
  184.             return links['buy ' + resource + ' 20']
  185.         elif int(data['budget']) >= int(data[mode]) * 5:
  186.             return links['buy ' + resource + ' 5']
  187.         else:
  188.             return links['buy ' + resource + ' 1']
  189.     else:
  190.         if int(data[resource + ' stockpile']) > int(stockpilelimit) + 20:
  191.             return links['sell ' + resource + ' 20']
  192.         elif int(data[resource + ' stockpile']) > int(stockpilelimit) + 5:
  193.             return links['sell ' + resource + ' 5']
  194.         else:
  195.             return links['sell ' + resource + ' 1']
  196.  
  197. def priceupdate(br, bdat=False):
  198.     parser = pp()
  199.     while True:
  200.         a = br.open("http://blocgame.com/market.php")
  201.         parser.feed(a.read())
  202.         if parser.bdata:
  203.             break
  204.         else:
  205.             return False
  206.     if bdat:
  207.         return parser.bdata
  208.     else:
  209.         return {'oil buy': parser.data[0], 'oil sell': parser.data[1],
  210.     'rm buy': parser.data[2], 'rm sell': parser.data[3], 'food buy': parser.data[4],
  211.     'food sell': parser.data[5], 'mg buy': parser.data[6], 'mg sell': parser.data[7],
  212.     'budget': parser.bdata[0], 'oil stockpile': parser.bdata[1], 'rm stockpile': parser.bdata[2],
  213.     'mg stockpile': parser.bdata[3], 'food stockpile': parser.bdata[4]}
  214.  
  215. class pp(HTMLParser):
  216.     def __init__(self):
  217.         HTMLParser.__init__(self)
  218.         self.recording = 0
  219.         self.brecording = 0
  220.         self.appendnext = False
  221.         self.appendbnext = False
  222.         self.cGDP = True
  223.         self.GDP = 0
  224.         self.GDPkillswitch = False
  225.         self.data = []
  226.         self.bdata = []
  227.  
  228.     def handle_starttag(self, tag, attributes):
  229.         if tag == 'b':
  230.             self.recording += 1
  231.         if tag == 'a':
  232.             self.appendbnext = True
  233.         if tag == 'i':
  234.             self.cGDP = True
  235.  
  236.     def handle_endtag(self, tag):
  237.         if tag == 'a':
  238.             self.appendnext = False
  239.  
  240.     def handle_data(self, data):
  241.         #price parsing
  242.         if self.recording:
  243.             if data == "+$" or data == "-$" or data == " -$":
  244.                 self.appendnext = True
  245.                 return
  246.         if self.appendnext:
  247.             self.data.append(data)
  248.             self.appendnext = False
  249.         #stockpile parsing
  250.         if self.appendbnext:
  251.             for i in data:
  252.                 if i == 'e':
  253.                     self.appendbnext = False
  254.                     return
  255.             a = (re.findall(r'\d+', data))
  256.             if a:
  257.                 if int(self.brecording) < 6:
  258.                     if int(self.brecording) == 4: #filter out weapon stockpile
  259.                         self.brecording += 1
  260.                     else:
  261.                         self.bdata.append(a[0])
  262.                         self.brecording += 1
  263.             self.appendbnext = False
  264.         #GDP parsing    
  265.         if self.cGDP and not self.GDPkillswitch:
  266.             for a in data.split(' '):
  267.                 if a == 'million':
  268.                     x = (re.findall(r'\d+', data))
  269.                     self.GDP = ''
  270.                     for p in x:
  271.                         self.GDP = self.GDP + str(p)
  272.                     self.GDPkillswitch = True
  273.  
  274. def checkGDP(username, password):
  275.     br = Browser()
  276.     br.open("http://blocgame.com/")
  277.     br.select_form(predicate=lambda f: f.attrs.get('action') == 'login.php')
  278.     br["username"] = username
  279.     br["password"] = password
  280.     br.submit()
  281.     parser = pp()
  282.     a = br.open("http://blocgame.com/main.php")
  283.     parser.feed(a.read())
  284.     return parser.GDP
  285.  
  286. #because profit tracking across sessions is nice
  287. #and windows doesn't do shared objects very well
  288. def profitdump(profit=0, mg=0, frun=False):
  289.     if frun:
  290.         if os.path.isfile('data.blob'):
  291.             with open('data.blob', 'rb') as datafile:
  292.                 x = datafile.readline()
  293.                 if x:
  294.                     return x.split(' ')
  295.                 else:
  296.                     return [profit, mg]
  297.         else: #if no profit data has been previously written, return 0
  298.             return [profit, mg]
  299.     else:
  300.         with open('data.blob', 'wb') as datafile:
  301.             datafile.write(str(profit) + ' ' + str(mg))
  302.  
  303. def write_data(br, frun):
  304.     data = priceupdate(br, True)
  305.     fexist = os.path.isfile('trader.csv')
  306.     with open('trader.csv', 'ab') as csvfile:
  307.         csvwriter = csv.writer(csvfile)
  308.         if frun and not fexist: #write headers to new file for sake of convenience
  309.             csvwriter.writerow(headers)
  310.         var = []
  311.         tmp = (str(datetime.now()).split('.')[0]) #strip the miliseconds off the timestamp
  312.         var += tmp.split(' ')
  313.         var = var + data
  314.         csvwriter.writerow(var)
  315.  
  316. #really should've made a dictionary
  317. def dump_preferences(username, password, oilbuy, oilsell, rmbuy, rmsell, rmstop, oilstop,
  318.         foodbuy, foodsell, foodstop, mgbool, allowmgbuy, tolerance, interval):
  319.     print "saving preferences"
  320.     with open('prefs.filenamextensionorFNEforshort', 'w') as prefile:
  321.         x = [username, password, oilbuy, oilsell, rmbuy, rmsell, rmstop, oilstop,
  322.         foodbuy, foodsell, foodstop, mgbool, allowmgbuy, tolerance, interval]
  323.         json.dump(x, prefile)
  324.  
  325. def read_preferences():
  326.     with open('prefs.filenamextensionorFNEforshort', 'r') as prefile:
  327.         return json.load(prefile)
  328.  
  329. def display_preferences(oilbuy, oilsell, rmbuy, rmsell, rmstop, oilstop,
  330.         foodbuy, foodsell, foodstop, mgbool, allowmgbuy, tolerance, interval, username, password):
  331.     gdp = int(checkGDP(username, password)) * 2
  332.     print "Oil buy price is %s" % oilbuy
  333.     print "Oil sell price is %s" % oilsell
  334.     print "Oil stockpile limit is %s" % oilstop
  335.     print "RM buy price is %s" % rmbuy
  336.     print "RM sell price is %s" % rmsell
  337.     print "RM stockpile limit is %s" % rmstop
  338.     print "Food buy price is %s" % foodbuy
  339.     print "Food sell price is %s" % foodsell
  340.     print "Food stockpile limit is %s" % foodstop
  341.     if mgbool:
  342.         print "Selling MG is allowed"
  343.     else:
  344.         print "Selling MG is not allowed"
  345.     if allowmgbuy:
  346.         if allowmgbuy == 'default':
  347.             print "Buying MG is allowed, with budget limit being %s" % gdp
  348.         else:
  349.             print "Buying MG is allowed, with budget limit being %s" % allowmgbuy
  350.     else:
  351.         print "Buying MG not allowed"
  352.     print "Price watching time is %s" % tolerance
  353.     if int(interval) > 0:
  354.         print "Blocmarket gets queried for new prices every %s seconds" % interval
  355.     else:
  356.         print "Blocmarket gets queried constantly for new prices"
  357.  
  358. #primary event loop
  359. def proloop(csvw, br, oilbuy, oilsell, oilstop, rmbuy, rmsell, rmstop,
  360.             foodbuy, foodsell, foodstop, mgsell, allowmgbuy, tolerance, interval):
  361.     tpvar = profitdump(frun=True)
  362.     profit = int(tpvar[0])
  363.     try:
  364.         mg = int(tpvar[1])
  365.     except:
  366.         mg = 0
  367.     if allowmgbuy == "default":
  368.         GDP = int(checkGDP(username, password)) * 2
  369.     elif allowmgbuy:
  370.         GDP = int(allowmgbuy)
  371.     if csvw:
  372.         write_data(br, True)
  373.     while True:
  374.         data = priceupdate(br)
  375.         if not data:
  376.             print "something happened, restarting"
  377.             return
  378.    
  379.         if int(data['oil buy']) <= int(oilbuy) and int(data['budget']) >= int(data['oil buy']):
  380.             print "buying oil"
  381.             temp = marketaction(oilbuy, br, 0, 'oil buy', mgsell, tolerance, data, cswv)
  382.             profit += int(temp)
  383.             profitdump(profit)
  384.  
  385.         elif int(data['oil sell']) >= int(oilsell) and int(data['oil stockpile']) > int(oilstop):
  386.             print "selling oil"
  387.             temp = marketaction(oilsell, br, oilstop, 'oil sell', mgsell, tolerance, data, csvw)
  388.             profit += int(temp)
  389.             profitdump(profit)
  390.  
  391.         elif int(data['rm buy']) <= int(rmbuy) and int(data['budget']) >= int(data['rm buy']):
  392.             print "buying RM"
  393.             temp = marketaction(rmbuy, br, 0, 'rm buy', mgsell, tolerance, data, csvw)
  394.             profit += int(temp)
  395.             profitdump(profit)
  396.  
  397.         elif int(data['rm sell']) >= int(rmsell) and int(data['rm stockpile']) > int(rmstop):
  398.             print "selling RM"
  399.             temp = marketaction(rmsell, br, rmstop, 'rm sell', mgsell, tolerance, data, csvw)
  400.             profit += int(temp)
  401.             profitdump(profit)
  402.  
  403.         elif int(data['food buy']) <= int(foodbuy) and int(data['budget']) >= int(data['food buy']):
  404.             print "buying food"
  405.             temp = marketaction(foodbuy, br, 0, 'food buy', mgsell, tolerance, data, csvw)
  406.             profit += int(temp)
  407.             profitdump(profit)
  408.  
  409.         elif int(data['food sell']) >= int(foodsell) and int(data['food stockpile']) >= int(foodstop):
  410.             print "selling food"
  411.             temp = marketaction(foodsell, br, foodstop, 'food sell', mgsell, tolerance, data, csvw)
  412.             profit += int(temp)
  413.             profitdump(profit)
  414.  
  415.         else:
  416.             print "waiting"
  417.             print "profit so far: %s, MG bought so far: %s" % (profit, mg)
  418.             if int(interval) > 0:
  419.                 time.sleep(int(interval))
  420.  
  421.         if allowmgbuy and int(data['budget']) > int(GDP):
  422.             while allowmgbuy and int(data['budget']) > int(GDP):
  423.                 temp = buymg(br, int(data['budget']) - int(GDP), int(data['mg buy']))
  424.                 profit -= int(temp[0])
  425.                 mg += int(temp[1])
  426.                 profitdump(profit=profit, mg=mg)
  427.                 data = priceupdate(br)
  428.             if csvw:
  429.                 write_data(br, False)
  430.                
  431.  
  432. #necessary to make it run properly on windows
  433. def run(username, password, csvw, oilbuy, oilsell, rmbuy, rmsell, rmstop, oilstop,
  434.         foodbuy, foodsell, foodstop, mgsell, allowmgbuy, tolerance, interval):
  435.     while True:
  436.         br = Browser()
  437.         br.open("http://blocgame.com/")
  438.         br.select_form(predicate=lambda f: f.attrs.get('action') == 'login.php')
  439.         br["username"] = username
  440.         br["password"] = password
  441.         br.submit()
  442.         proloop(csvw, br, oilbuy, oilsell, oilstop, rmbuy, rmsell, rmstop,
  443.                 foodbuy, foodsell, foodstop, mgsell, allowmgbuy, tolerance, interval)
  444.         print "something went from, time is %s, retrying in 20 minutes" % str(datetime.now()).split(' ')[1].split('.')[0]
  445.         time.sleep(1200)
  446.  
  447.  
  448.  
  449. if __name__ == '__main__':
  450.     freeze_support()
  451.     fexist = os.path.isfile('prefs.filenamextensionorFNEforshort')
  452.     choice = ''
  453.     userchoice = ''
  454.     if fexist:
  455.         print "Load preferences from file? (y/n)"
  456.         while True:
  457.             choice = raw_input(">: ")
  458.             if choice == 'n':
  459.                 choice = True
  460.             elif choice == 'y':
  461.                 choice = False
  462.             else:
  463.                 print "fyi y is short for yes and n is short for no"
  464.                 print "so literally just type y and press enter if you want to load your preferences"
  465.                 print "or n if you don't"
  466.                 continue
  467.             break
  468.  
  469.         if choice:
  470.             print "Load username and password? (y/n)"
  471.             while True:
  472.                 userchoice = raw_input(">: ")
  473.                 if userchoice == 'y':
  474.                     userchoice = True
  475.                 elif userchoice == 'n':
  476.                     userchoice = False
  477.                 else:
  478.                     print "fyi y is short for yes and n is short for no"
  479.                     print "so literally just type y and press enter if you don't want to enter name and pass"
  480.                     print "or n if you don't"
  481.                     continue
  482.                 break
  483.  
  484.     if not fexist or choice:
  485.         if userchoice:
  486.             print "loading username and password"
  487.             content = read_preferences()
  488.             username = content[0]
  489.             password = content[1]
  490.         else:
  491.             username = raw_input("Username: ")
  492.             password = raw_input("Password: ")
  493.  
  494.         while True:
  495.             oilbuy = input("Oil buy price: ")
  496.             oilsell = input("Oil sell price: ")
  497.             rmbuy = input("RM buy price: ")
  498.             rmsell = input("RM sell price: ")
  499.             foodbuy = input("Food buy price: ")
  500.             foodsell = input("Food sell price: ")
  501.             rmstop = input("Minimum RM stockpile: ")
  502.             oilstop = input("Minimum oil stockpile: ")
  503.             foodstop = input("Minimum food stockpile: ")
  504.             if int(oilsell) < int(oilbuy) or int(rmsell) < int(rmbuy) or int(foodsell) < int(foodbuy):
  505.                 print "One or more are incorrect\ntry again stupid\n"
  506.                 print "protip: buy values are supposed to be lower than sell values"
  507.                 continue
  508.             break
  509.  
  510.         print "Allow selling of MG if budget gets depleted while buying? (y/n)"
  511.         while True:
  512.             mgbool = raw_input(">: ")
  513.             if mgbool == 'y':
  514.                 mgbool = True
  515.                 break
  516.             elif mgbool == 'n':
  517.                 mgbool = False
  518.                 break
  519.             else:
  520.                 print "It's a simple matter of typing y or n, try again retard"
  521.         if mgbool:
  522.             while True:
  523.                 try:
  524.                     mgbool = input("Minimum mg stockpile: ")
  525.                 except NameError:
  526.                     continue
  527.                 break
  528.  
  529.         print "Allow buying of MG if budget goes above set budget limit? (y/n)"
  530.         while True:
  531.             allowmgbuy = raw_input(">: ")
  532.             if allowmgbuy == 'y':
  533.                 break
  534.             elif allowmgbuy == 'n':
  535.                 allowmgbuy = False
  536.                 break
  537.             else:
  538.                 print "It's a simple matter of typing y or n, try again retard"
  539.  
  540.             if allowmgbuy == 'y':
  541.                 print "Should budget limit be set to 2x GDP? (y/n)"
  542.                 while True:
  543.                     allowmgbuy = raw_input(">: ")
  544.                     if allomgbuy == 'y':
  545.                         allowmgbuy = "default"
  546.                     elif allowmgbuy == 'n':
  547.                         print "Enter desired budget limit"
  548.                         while True:
  549.                             try:
  550.                                 allowmgbuy = input(">: ")
  551.                             except:
  552.                                 print "Enter a number numbnuts"
  553.                                 continue
  554.                             if int(allowmgbuy) > 0:
  555.                                 break
  556.                             else:
  557.                                 print "The number needs to be more than 0, try again"
  558.                     else:
  559.                         print "invalid input, try again"
  560.  
  561.         print "Specify tolerance in seconds for price observation after target price has been reached"
  562.         print "eg how many seconds price should remains same after before buying/selling"
  563.         print "0 means don't observe just sell when target has been reached"
  564.         while True:
  565.             try:
  566.                 tolerance = input(">: ")
  567.             except NameError:
  568.                 print "Enter a number dipshit"
  569.                 continue
  570.             break
  571.  
  572.         print "Enter time in seconds between market queries (default is 10)"
  573.         print "while 0 is valid, it isn't advised as bloc might shit itself"
  574.         print "but do what you want bruh"
  575.         while True:
  576.             try:
  577.                 interval = input(">: ")
  578.             except NameError:
  579.                 print "Enter a number dipshit"
  580.                 continue
  581.             break
  582.  
  583.         dump_preferences(username, password, oilbuy, oilsell, rmbuy, rmsell, rmstop, oilstop,
  584.         foodbuy, foodsell, foodstop, mgbool, allowmgbuy, tolerance, interval)
  585.     else:
  586.         try:
  587.             print "loading everything"
  588.             content = read_preferences()
  589.             username = content[0]
  590.             password = content[1]
  591.             oilbuy = content[2]
  592.             oilsell = content[3]
  593.             rmbuy = content[4]
  594.             rmsell = content[5]
  595.             rmstop = content[6]
  596.             oilstop = content[7]
  597.             foodbuy = content[8]
  598.             foodsell = content[9]
  599.             foodstop = content[10]
  600.             mgbool = content[11]
  601.             allowmgbuy = content[12]
  602.             tolerance = content[13]
  603.             interval = content[14]
  604.             print "done"
  605.         except:
  606.             print "something went wrong with loading from file"
  607.             print "delete and put in new data"
  608.             print "ripip in"
  609.             n = 5
  610.             for x in range(5):
  611.                 print n
  612.                 n -= 1
  613.                 time.sleep(1)
  614.             exit("ripipipip")
  615.     print "save data to csv file? (y/n)"
  616.     while True:
  617.         csvw = raw_input(">: ")
  618.         if csvw == 'y':
  619.             csvw = True
  620.         elif csvw == 'n':
  621.             csvw = False
  622.         else:
  623.             print "Invalid choice, try again (it's literally just y or n)"
  624.             continue
  625.         break
  626.     stupid = True
  627.     while True:
  628.         print "Starting marketbot, type stop to change the prices and stockpile limits"
  629.         p = Process(target=run, args=(username, password, csvw, oilbuy, oilsell, rmbuy, rmsell,
  630.          rmstop, oilstop, foodbuy, foodsell, foodstop, mgbool, allowmgbuy, tolerance, interval))
  631.         p.start()
  632.         while True:
  633.             x = raw_input()
  634.             if x == 'stop':
  635.                 p.terminate()
  636.                 break
  637.             else:
  638.                 continue
  639.         print "The current preferences are\n"
  640.         display_preferences(oilbuy, oilsell, rmbuy, rmsell, rmstop, oilstop,
  641.         foodbuy, foodsell, foodstop, mgbool, allowmgbuy, tolerance, interval, username, password)
  642.         print "\n\n\nTo change stockpile limits type stockpile"
  643.         print "To change RM price limits type rm"
  644.         print "To change oil price limits type oil"
  645.         print "To change food price limits type food"
  646.         print "To change MG buy/sell permissions type mg"
  647.         print "To change market query and price watch intervals type time"
  648.         print "To change budget limitations, type budget"
  649.         print "If you want to reset the profit and/or the MG counter, type reset profit/mg/both"
  650.         print "Or to change everything type all"
  651.         print "If you've changed your mind and want to continue, type nevermind"
  652.         while True:
  653.             x = raw_input(">: ")
  654.             if x == "nevermind":
  655.                 pass
  656.  
  657.             elif x == 'stockpile':
  658.                 if mgbool:
  659.                     mgbool = input("Minimum mg stockpile: ")
  660.                 rmstop = input("Minimum RM stockpile: ")
  661.                 oilstop = input("Minimum oil stockpile: ")
  662.                 foodstop = input("Minimum food stockpile: ")
  663.             elif x == 'rm':
  664.  
  665.                 rmbuy = input("RM buy price: ")
  666.                 rmsell = input("RM sell price: ")
  667.  
  668.             elif x == 'oil':
  669.                 oilbuy = input("Oil buy price: ")
  670.                 oilsell = input("Oil sell price: ")
  671.  
  672.             elif x == 'food':
  673.                 foodbuy = input("Food buy price: ")
  674.                 foodsell = input("Food sell price: ")
  675.  
  676.             elif x == 'mg':
  677.                 print "Allow selling of MG if budget gets depleted while buying? (y/n)"
  678.                 while True:
  679.                     mgbool = raw_input(">: ")
  680.                     if mgbool == 'y':
  681.                         mgbool = True
  682.                         break
  683.                     elif mgbool == 'n':
  684.                         mgbool = False
  685.                         break
  686.                     else:
  687.                         print "It's a simple matter of typing y or n, try again retard"
  688.                 print "Allow buying of MG if budget goes above set limit? (y/n)"
  689.                 while True:
  690.                     old = allowmgbuy
  691.                     allowmgbuy = raw_input(">: ")
  692.                     if allowmgbuy == 'y':
  693.                         print "Set new limit? (y/n)"
  694.                         while True:
  695.                             allowmgbuy = raw_input(">: ")
  696.                             if allowmgbuy == 'n':
  697.                                 allowmgbuy = old
  698.                                 break
  699.                             elif allowmgbuy == 'y':
  700.                                 print "Set limit to 2x GDP? (y/n)"
  701.                                 while True:
  702.                                     allowmgbuy = raw_input(">: ")
  703.                                     if allowmgbuy == 'y':
  704.                                         allowmgbuy = "default"
  705.                                         break
  706.                                     elif allowmgbuy == 'n':
  707.                                         print "Enter desired budget limit"
  708.                                         while True:
  709.                                             try:
  710.                                                 allowmgbuy = input(">: ")
  711.                                             except:
  712.                                                 print "Enter a number numbnuts"
  713.                                                 continue
  714.                                             if int(allowmgbuy) > 0:
  715.                                                 break
  716.                                             else:
  717.                                                 print "The number needs to be more than 0, try again"
  718.                                     else:
  719.                                         print "invalid input"
  720.                                         continue
  721.                                     break
  722.                             else:
  723.                                 print "invalid input"
  724.                                 continue
  725.                             break
  726.                         break
  727.                     elif allowmgbuy == 'n':
  728.                         allowmgbuy = False
  729.                         break
  730.                     else:
  731.                         print "It's a simple matter of typing y or n, try again retard"
  732.             elif x == 'time':
  733.                 print "Specify tolerance in seconds for price observation"
  734.                 while True:
  735.                     try:
  736.                         tolerance = input(">: ")
  737.                     except NameError:
  738.                         print "Enter a number dipshit"
  739.                         continue
  740.                     break
  741.  
  742.                 print "Enter time in seconds between market queries (default is 10)"
  743.                 while True:
  744.                     try:
  745.                        interval = input(">: ")
  746.                     except NameError:
  747.                         print "Enter a number dipshit"
  748.                         continue
  749.                     break
  750.  
  751.             elif x == 'budget':
  752.                 print "Allow buying of MG if budget goes above set budget limit? (y/n)"
  753.                 while True:
  754.                     allowmgbuy = raw_input(">: ")
  755.                     if allowmgbuy == 'n':
  756.                         allowmgbuy = False
  757.                         break
  758.  
  759.                     elif allowmgbuy == 'y':
  760.                         print "Should budget limit be set to 2x GDP? (y/n)"
  761.                         while True:
  762.                             allowmgbuy = raw_input(">: ")
  763.                             if allowmgbuy == 'y':
  764.                                allowmgbuy = "default"
  765.                             elif allowmgbuy == 'n':
  766.                                 print "Enter desired budget limit"
  767.                                 while True:
  768.                                     try:
  769.                                         allowmgbuy = input(">: ")
  770.                                     except:
  771.                                         print "Enter a number numbnuts"
  772.                                         continue
  773.                                     if int(allowmgbuy) > 0:
  774.                                         break
  775.                                     else:
  776.                                         print "The number needs to be more than 0, try again"
  777.                             else:
  778.                                 print "invalid input, try again"
  779.                                 continue
  780.                             break
  781.                     else:
  782.                         print "It's a simple matter of typing y or n, try again retard"
  783.                         continue
  784.                     break
  785.  
  786.             elif x == 'all':
  787.                 oilbuy = input("Oil buy price: ")
  788.                 oilsell = input("Oil sell price: ")
  789.                 rmbuy = input("RM buy price: ")
  790.                 rmsell = input("RM sell price: ")
  791.                 foodbuy = input("Food buy price: ")
  792.                 foodsell = input("Food sell price: ")
  793.                 if mgbool:
  794.                     mgbool = input("Minimum mg stockpile: ")
  795.                 rmstop = input("Minimum RM stockpile: ")
  796.                 oilstop = input("Minimum oil stockpile: ")
  797.                 foodstop = input("Minimum food stockpile: ")
  798.                 print "Allow selling of MG if budget gets depleted while buying? (y/n)"
  799.                 while True:
  800.                     mgbool = raw_input(">: ")
  801.                     if mgbool == 'y':
  802.                         mgbool = True
  803.                         break
  804.                     elif mgbool == 'n':
  805.                         mgbool = False
  806.                         break
  807.                     else:
  808.                         print "It's a simple matter of typing y or n, try again retard"
  809.                 print "Allow buying of MG if budget goes above set budget limit? (y/n)"
  810.                 while True:
  811.                     allowmgbuy = raw_input(">: ")
  812.                     if allowmgbuy == 'y':
  813.                         break
  814.                     elif allowmgbuy == 'n':
  815.                         allowmgbuy = False
  816.                         break
  817.                     else:
  818.                         print "It's a simple matter of typing y or n, try again retard"
  819.  
  820.                 if allowmgbuy == 'y':
  821.                     print "Should budget limit be set to 2x GDP? (y/n)"
  822.                     while True:
  823.                         allowmgbuy = raw_input(">: ")
  824.                         if allowmgbuy == 'y':
  825.                             allowmgbuy = "default"
  826.                             break
  827.                         elif allowmgbuy == 'n':
  828.                             print "Enter desired budget limit"
  829.                             while True:
  830.                                 try:
  831.                                     allowmgbuy = input(">: ")
  832.                                 except:
  833.                                     print "Enter a number numbnuts"
  834.                                     continue
  835.                                 if int(allowmgbuy) > 0:
  836.                                     break
  837.                                 else:
  838.                                     print "The number needs to be more than 0, try again"
  839.                         else:
  840.                             print "invalid input"
  841.                             continue
  842.                         break
  843.  
  844.                 print "Specify tolerance in seconds for price observation"
  845.                 while True:
  846.                     try:
  847.                         tolerance = input(">: ")
  848.                     except NameError:
  849.                         print "Enter a number dipshit"
  850.                         continue
  851.                     break
  852.  
  853.                 print "Enter time in seconds between market queries (default is 10)"
  854.                 while True:
  855.                     try:
  856.                        interval = input(">: ")
  857.                     except NameError:
  858.                         print "Enter a number dipshit"
  859.                         continue
  860.                     break
  861.  
  862.             elif x.split(' ')[0] == 'reset':
  863.                 if x == 'reset mg':
  864.                     tp = profitdump(frun=True) #get profit data
  865.                     profitdump(profit=tp[0]) #resetting mg
  866.                 elif x == 'reset profit':
  867.                     tp = profitdump(frun=True) #get profit data
  868.                     profitdump(profit=tp[1]) #resetting profit
  869.                 elif x == 'reset both':
  870.                     profitdump()
  871.                 else:
  872.                     print "bad input dumbass, try again"
  873.                     continue
  874.  
  875.  
  876.             else:
  877.                 print "bad input dumbass, try again"
  878.                 continue
  879.             dump_preferences(username, password, oilbuy, oilsell, rmbuy, rmsell, rmstop, oilstop,
  880.         foodbuy, foodsell, foodstop, mgbool, allowmgbuy, tolerance, interval)
  881.             break
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top