Created
April 2, 2014 17:47
-
-
Save eknowles/9939273 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib2, urllib | |
import json | |
import StringIO | |
import gzip | |
import random | |
import codecs | |
import time | |
import pprint | |
import requests | |
import re | |
import BeautifulSoup | |
from BeautifulSoup import BeautifulSoup as Soup | |
from operator import itemgetter | |
class Market(object): | |
profileid = "" | |
sessionid = "" | |
cookie = "" | |
hosturl = "http://steamcommunity.com/" | |
hosturls = "https://steamcommunity.com/" | |
appid = "730" | |
contextid = "2" | |
searchFilter = "Base Grade" | |
hash_names = [] | |
saved_prices = {'test': 1} | |
curently_selling = {'item': {'name': 'examplename', 'type': 'exampletype'}} | |
def removeAllListings(self): | |
target = self.hosturl + "market/mylistings" | |
headers = { | |
"Accept": "text/javascript, text/html, application/xml, text/xml, */*", | |
"Accept-Encoding": "gzip,deflate,sdch", | |
"Accept-Language": "en-US,en;q=0.8", | |
"Host": "steamcommunity.com", | |
"Referer": self.hosturl + "market/", | |
"Cookie": self.cookie, | |
"Origin": "http://steamcommunity.com", | |
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36", | |
"X-Requested-With": "XMLHttpRequest" | |
} | |
data = {"sessionid" : self.sessionid} | |
req = urllib2.Request(target, urllib.urlencode(data), headers) | |
f = urllib2.urlopen(req) | |
response = f.read() | |
f.close() | |
data = StringIO.StringIO(response) | |
gzipper = gzip.GzipFile(fileobj=data) | |
j = json.loads(gzipper.read()) | |
item_on_sale = j['assets'][self.appid][self.contextid] | |
hovers = j['hovers'] | |
regex = re.compile(r"mylisting_(\d+)_name") | |
# for asset in item_on_sale: | |
# print item_on_sale[asset]['type'] | |
for listing in regex.findall(hovers): | |
self.removeListing(listing) | |
print "Listing " + listing + " was removed from the marketplace" | |
time.sleep(random.randint(1, 5)) | |
def removeListing(self, listingid): | |
target = self.hosturl + "market/removelisting/" + listingid | |
headers = { | |
"Accept": "text/javascript, text/html, application/xml, text/xml, */*", | |
"Accept-Encoding": "gzip,deflate,sdch", | |
"Accept-Language": "en-US,en;q=0.8", | |
"Host": "steamcommunity.com", | |
"Referer": self.hosturl + "market/", | |
"Cookie": self.cookie, | |
"Origin": "http://steamcommunity.com", | |
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36", | |
"X-Requested-With": "XMLHttpRequest" | |
} | |
data = {"sessionid" : self.sessionid} | |
x = urllib2.Request(target, urllib.urlencode(data), headers) | |
y = urllib2.urlopen(x) | |
z = y.read() | |
y.close() | |
def scanMarket(self, market_hash, appid): | |
url = self.hosturl + "market/listings/"+str(appid)+"/"+urllib.quote(market_hash) | |
response = urllib2.urlopen(url) | |
html = response.read() | |
soup = Soup(html) | |
prices = soup.findAll("span", "market_listing_price_without_fee") | |
for listing in prices: | |
print listing.text | |
# self.returnCleanPrice() | |
def getPrice(self, market_hash, scanType): | |
encodedhash = urllib.quote(market_hash) | |
url = self.hosturl + "market/listings/"+self.appid+"/"+encodedhash | |
headers = { | |
"Accept": "text/javascript, text/html, application/xml, text/xml, */*", | |
"Accept-Encoding": "gzip,deflate,sdch", | |
"Accept-Language": "en-US,en;q=0.8", | |
"Host": "steamcommunity.com", | |
"Referer": self.hosturl + "market/", | |
"Cookie": self.cookie, | |
"Origin": "http://steamcommunity.com", | |
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36", | |
"X-Requested-With": "XMLHttpRequest" | |
} | |
data = {"sessionid" : self.sessionid} | |
req = urllib2.Request(url, urllib.urlencode(data), headers) | |
f = urllib2.urlopen(req) | |
response = f.read() | |
f.close() | |
data = StringIO.StringIO(response) | |
gzipper = gzip.GzipFile(fileobj=data) | |
html = gzipper.read() | |
soup = Soup(html) | |
prices = soup.findAll("span", "market_listing_price_without_fee") | |
if scanType == 1: | |
# Return Lowest Price | |
for price_listed in prices: | |
if not price_listed.text == 'Sold!': | |
lowest_price = int(str(price_listed.text).replace('£', '').replace('.','')) | |
self.saved_prices[market_hash] = lowest_price | |
return lowest_price | |
elif scanType == 0: | |
# Buy For Profit | |
firstprice = self.returnCleanPrice(prices[0].text) | |
secondprice = self.returnCleanPrice(prices[1].text) | |
thirdprice = self.returnCleanPrice(prices[2].text) | |
forthprice = self.returnCleanPrice(prices[3].text) | |
print firstprice, secondprice, thirdprice, forthprice | |
def scanListingForProfit(self, listing_hash): | |
self.getPrice(urllib.quote(listing_hash), 0) | |
def returnCleanPrice(self, price): | |
if not price == 'Sold!': | |
return int(str(price).replace('£', '').replace('.','')) | |
def sellItem(self, assetid, amount, price): | |
target = self.hosturls + "market/sellitem/" | |
headers = { | |
"Accept": "*/*", | |
"Accept-Encoding": "gzip,deflate,sdch", | |
"Accept-Language": "en-US,en;q=0.8", | |
"Host": "steamcommunity.com", | |
"Referer": self.hosturl + "id/" + self.profileid + "/market/", | |
"Cookie": self.cookie, | |
"Origin": "http://steamcommunity.com", | |
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36", | |
"X-Requested-With": "XMLHttpRequest" | |
} | |
data = { | |
"sessionid": self.sessionid, | |
"appid": int(self.appid), | |
"contextid": int(self.contextid), | |
"assetid": int(assetid), | |
"amount": int(amount), | |
"price": int(price) | |
} | |
req = urllib2.Request(target, urllib.urlencode(data), headers) | |
f = urllib2.urlopen(req) | |
json_response = json.loads(f.read()) | |
f.close() | |
def RunSeller(self): | |
total_price = 0 | |
items_put_on_sale = 0 | |
inventory = self.hosturl+"id/"+self.profileid+"/inventory/json/"+self.appid+"/"+self.contextid | |
r = requests.post(inventory, '') | |
req = urllib2.Request(inventory) | |
opener = urllib2.build_opener() | |
f = opener.open(req) | |
res = json.load(f) | |
f.close() | |
inventoryItems = res['rgInventory'] | |
itemDescriptions = res['rgDescriptions'] | |
for index in inventoryItems: | |
classid = inventoryItems[index]['classid'] | |
itemid = inventoryItems[index]['instanceid'] | |
assetid = inventoryItems[index]['id'] | |
descindex = str(classid+'_'+itemid) | |
item = itemDescriptions[descindex] | |
itemType = item['type'].encode('ascii', 'ignore') | |
market_hash_name = item['market_hash_name'] | |
if item['marketable'] != 1: | |
continue | |
if self.DoNotSell(market_hash_name) == 0: | |
# if itemType.startswith(self.searchFilter): | |
if items_put_on_sale < 1000: | |
if self.saved_prices.has_key(market_hash_name): | |
price = self.saved_prices[market_hash_name] | |
# print self.saved_prices | |
else: | |
price = self.getPrice(market_hash_name, 1) | |
if price > 2: | |
price -= 1 | |
if price is None: | |
continue | |
try: | |
self.sellItem(assetid, 1, price) | |
print str(total_price) + "\t" + assetid +"\t" + str(price) +"\t" + market_hash_name.encode('ascii', 'ignore') | |
total_price += price | |
time.sleep(random.randint(2, 5)) | |
items_put_on_sale += 1 | |
except urllib2.HTTPError: | |
print "-\t" + assetid +"\t-\t" + market_hash_name.encode('ascii', 'ignore') + "\t" + 'HTTP Error 502: Bad Gateway' | |
def DoNotSell(self, hashname): | |
names = ['StatTrak', 'Souv', 'AK-47', 'USP-S | Stainless', 'Sticker |', 'AWP', 'M4A'] | |
for x in names: | |
if hashname.startswith(x): | |
return 1 | |
return 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To set up the bot make an action on steam and catch the cookie/session with developer tools and fill them in
sessionid = ""
cookie = ""
also put in your profile id .com/id/whatever
profileid = ""
then to start it
m = SteamMarket.Market()
m.RunSeller()