Example #1
0
def gemComment(amount):
	# Raw API casted to a string, then split into parts using "{"
	apiReturn = (str(Gw2Spidy.getGemPrice())).rsplit("{")
	# Split again using ","
	split = (apiReturn[2]).split(", ")

	for line in split:

		# Deconstructing the API's return string
		#    The second value of the array will have a "}}" at the end, however it is unknown which part will
		#    So we test both strings

		if "gem_to_gold" in line:
			gemToGold = line
			gemToGold = gemToGold.rsplit(": ")
			gemToGold = gemToGold[1]
			if "}}" in gemToGold:
				gemToGold = gemToGold[:-2]
					
		if "gold_to_gem" in line:
			goldToGem = line
			goldToGem = goldToGem.rsplit(": ")
			goldToGem = goldToGem[1]
			if "}}" in goldToGem:
				goldToGem = goldToGem[:-2]

	# Crafting the reply with some unit conversions and reddit comment formatting
	reply = ("The current gem conversion rates for " + str(amount) + " gems are: \n\n" +
			"* "+ str(amount) + " gems costs **" + str(round((((float(goldToGem)/10000)/100)*amount), 2)) + " gold** to buy. \n\n"
			"* " +  str(amount) + " gems will convert into **" + str(round((((float(gemToGold)/10000)/100)*amount), 2)) + " gold**. \n\n" +
			"* " + str(amount) + " gems costs **" + str(round((amount*0.0125), 2)) + " USD** if purchased with real money. \n\n***\n\n"
			"^^Hi! ^^I'm ^^a ^^bot ^^run ^^by ^^/u/snowspirit. ^^If ^^there ^^are ^^any ^^problems, ^^please ^^send ^^her ^^a ^^message! ^^You ^^can ^^also ^^view ^^my ^^source ^^code ^^over ^^[here](https://github.com/snowspirit/gemBot).")
	return(reply)
Example #2
0
 def buy(item_name, amount, price):
    
    item_id = str(Gw2Spidy.searchItems(item_name)[0]["data_id"])
    with open('my_items') as f:
       my_items = f.readlines()
    
    updated = False
    
    for i in range(len(my_items)):
    
       if (my_items[i].split()[0] == item_id):
          my_items[i+1].rstrip('\n')
          my_items[i+1] += ' ' + amount + ' ' + price + '\n'
          updated = True
          break
       else:
          i += 1
    
    if not updated:
       my_items += item_id + ' ' + item_name + '\n'
       my_items += '\t' + amount + ' ' + price + '\n'
    
    f = open('my_items', 'w')
    
    for line in my_items:
       f.write(line)
       
    f.close()
Example #3
0
 def listing():
    
    with open('my_items') as f:
       my_items = f.readlines()
       
    
    for i in range(len(my_items)):
       my_items[i] = my_items[i].split()
        
    for i in range(0,len(my_items),2):
       data = Gw2Spidy.getItemData(my_items[i][0])
       item_sell_price = str(data["min_sale_unit_price"])
       #item_buy_price = str(data["u_max_offer_unit_price"])
       
       print(" ".join(my_items[i][1:]), end=" ")
       print("Sale Price: " + item_sell_price)
       
       for j in range(0,len(my_items[i+1]),2):
          purchase_price = my_items[i+1][j+1]
          diff_sell =  str(int(item_sell_price) - int(purchase_price) - (0.15 * int(item_sell_price)))
          print(my_items[i+1][j] + ' x', end=' ')
          if (float(diff_sell) > 0):
             print(colored('+' + str(int(round(float(diff_sell)))), 'green'))
          else:
             print(colored(str(int(round(float(diff_sell)))), 'red'))
Example #4
0
def view():
    # in the order we want them to be rendered
    ids = [24358, 24289, 24300, 24277, 24283, 24295, 24351, 24357]
    items = []
    for item_id in ids:
        data = Gw2Spidy.getItemData(item_id)
        items.append(data)
    return render_template("t6price.html", items=items, pretty_money=pretty_money)
Example #5
0
def saveItemTimepoint():
    now = datetime.now()
    allItems = np.load('itemData.npy')
    for id in itemIDs:
        item = spidy.getItemData(id)
        itemData = [item['data_id'], item['max_offer_unit_price'], item['min_sale_unit_price'], item['offer_availability'], item['sale_availability'], item['sale_price_change_last_hour'], item['offer_price_change_last_hour'],
                   now.year, now.month, now.day, now.hour, now.minute, now.second]
        allItems = np.vstack((allItems, itemData))
    np.save('itemData', allItems)
    print('Saved item data at: %s' % datetime.now())
Example #6
0
from pathlib import Path
from gw2spidy import Gw2Spidy
from tqdm import tqdm

FILE_DB = Path("db.sqlite")


def save(data):
    conn = sqlite3.connect(str(FILE_DB))
    if not FILE_DB.exists():
        conn.execute('''CREATE TABLE data
                        (int id, string name, int sell_price, int buy_price, 
                        date last_update, int demand, int supply)''')
    c = conn.cursor()
    c.executemany('INSERT INTO data VALUES (?,?,?,?,?,?,?)', data)
    conn.commit()
    conn.close()


if __name__ == "__main__":
    spidy = Gw2Spidy()
    data = []
    for item in tqdm(spidy.getAllItemsList()):
        if item["max_offer_unit_price"] != 0 and item[
                "min_sale_unit_price"] != 0:
            data.append(
                (item["data_id"], item["name"], item["min_sale_unit_price"],
                 item["min_sale_unit_price"], item["price_last_changed"],
                 item["sale_availability"], item["offer_availability"]))
    save(data)