Skip to content

Instantly share code, notes, and snippets.

@seandewar
Last active May 7, 2019 19:48
Show Gist options
  • Save seandewar/254cede443427ef95515304f0fbccb52 to your computer and use it in GitHub Desktop.
Save seandewar/254cede443427ef95515304f0fbccb52 to your computer and use it in GitHub Desktop.
highalch.py
import urllib2, json, datetime, operator
def sp_to_ha(sp):
return int(0.6 * sp) # effectively an int floor if +ve (which it should be)
def fetch_item_price(id):
response = urllib2.urlopen('http://api.rsbuddy.com/grandExchange?a=guidePrice&i=%d' % id)
return json.loads(response.read())
def fetch_good_alch_list(nature_rune_price):
response = urllib2.urlopen('https://rsbuddy.com/exchange/summary.json')
raw_item_list = json.loads(response.read())
result = []
for k, i in raw_item_list.items():
item = {
'id': i['id'],
'name': i['name'],
'buy_avg': i['buy_average'],
'sell_avg': i['sell_average'],
'ha': sp_to_ha(i['sp']),
}
item['ha_profit'] = item['ha'] - item['buy_avg'] - nature_rune_price
if item['buy_avg'] > 0 and item['ha_profit'] >= -300:
"""
raw_item_current_graph = fetch_item_current_graph(item['id'])
if len(raw_item_current_graph) > 0:
raw_recent_item = raw_item_current_graph[-1]
if 'buyingPrice' in raw_recent_item:
item['buy_last'] = raw_recent_item['buyingPrice']
"""
result.append(item)
return result
def get_sorted_alch_list(alch_list):
return sorted(alch_list, key=operator.itemgetter('ha_profit'), reverse=True)
def print_alch_list(alch_list):
for i in alch_list:
print '\nItem Name: %s, Item ID: %d' % (i['name'], i['id'])
print '\tHigh Alch: %d gp, HA Profit: %d gp\n\tAverages: Buy: %d gp, Sell: %d gp' \
% (i['ha'], i['ha_profit'], i['buy_avg'], i['sell_avg'])
"""
print '\nItem: %s' % i['name']
print '\tID: %d' % i['id']
print '\tHigh Alch Profit: %d gp' % i['ha_profit']
"""
if 'buy_last' in i:
print '\tLast Buy Price: %d gp' % i['buy_last']
"""
print '\tHigh Alch: %d gp' % i['ha']
print '\tAverage Buy Price: %d gp' % i['buy_avg']
print '\tAverage Sell Price: %d gp' % i['sell_avg']
"""
NATURE_RUNE_ID = 561
print 'Fetching current price of nature runes (ID %d) ...' % NATURE_RUNE_ID
nat_price = fetch_item_price(NATURE_RUNE_ID)['buying']
print 'Nature runes are currently %d gp each.' % nat_price
print 'Fetching current list of good high alchable items ...'
good_alch_list = get_sorted_alch_list(fetch_good_alch_list(nat_price))
print 'There are currently %d item(s) that are good high alchables:' % len(good_alch_list)
print_alch_list(good_alch_list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment