Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some fixes #7

Merged
merged 8 commits into from
Dec 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions BackpackTF/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ def __init__(self, client_id="", client_secret="", api_key=""):
#
# id - the listing's ID
#

def getListing(self, listing_id=0):
def get_listing(self, listing_id=0):
from requests_oauthlib import OAuth2Session
from oauthlib.oauth2 import TokenExpiredError

Expand All @@ -46,12 +45,16 @@ def getListing(self, listing_id=0):

return r.text

# alias for compatibility with older versions
# please use the new name, "get_listing"
getListing = get_listing

#
# Delete a listing by ID
#
# id - the listing's ID
#
def deleteListing(self, listing_id=0):
def delete_listing(self, listing_id=0):
from requests_oauthlib import OAuth2Session
from oauthlib.oauth2 import TokenExpiredError

Expand All @@ -70,6 +73,10 @@ def deleteListing(self, listing_id=0):

return r.text

# alias for compatibility with older versions
# please use the new name, "delete_listing"
deleteListing = delete_listing

#
# Create a listing
#
Expand All @@ -92,8 +99,7 @@ def deleteListing(self, listing_id=0):
#
# returns int: 0 or 1, states the success of the listing
#

def createListing(self, intent=0, id=0, quality=6, item_name="Haunted Hat", craftable=1, priceindex=0, offers=0, buyout=1, promoted=0, details="", currencies={"metal": 0}, account_token=""):
def create_listing(self, intent=0, id=0, quality=6, item_name="", craftable=1, priceindex=0, offers=0, buyout=1, promoted=0, details="", currencies={"metal": 0}, account_token=""):
from requests_oauthlib import OAuth2Session
from oauthlib.oauth2 import BackendApplicationClient
from oauthlib.oauth2 import TokenExpiredError
Expand Down Expand Up @@ -147,6 +153,10 @@ def createListing(self, intent=0, id=0, quality=6, item_name="Haunted Hat", craf
except:
return jsonResponse

# alias for compatibility with older versions
# please use the new name, "create_listing"
createListing = create_listing

#
# This function searches for classified listings
#
Expand All @@ -168,7 +178,7 @@ def createListing(self, intent=0, id=0, quality=6, item_name="Haunted Hat", craf
# sheen - 0-7, in order team shine, deadly daffodil, manndarin, mean green, agonizing emerald, villainous violet, hot rod
# killstreaker - the id of the killstreaker
#
def search_Classifieds(self, intent="dual", page_size=10, fold=1, item_name="Soda Popper", steamid="", tradable="", craftable="", australium="", wear_tier="", quality="",
def search_classifieds(self, intent="dual", page_size=10, fold=1, item_name="", steamid="", tradable="", craftable="", australium="", wear_tier="", quality="",
paint="", particle="", killstreak_tier="", sheen="", killstreaker="", page=0, texture_name=""):
import requests
import urllib.parse
Expand Down Expand Up @@ -203,6 +213,10 @@ def search_Classifieds(self, intent="dual", page_size=10, fold=1, item_name="Sod

return jsondata

# alias for compatibility with older verisions
# please use the new function name, "search_classifieds" (lowercase c)
search_Classifieds = search_classifieds


#
# This function extracts the trade url.
Expand Down Expand Up @@ -239,4 +253,4 @@ def extract_trade_url(self, listingJSON, proxy=None):
url = tree.xpath("//li[@id='listing-" + listingJSON['id'] + "']/div[@class='listing-item']/div")[0].get('data-listing_offers_url')
return url
except:
raise IndexError('List index out of range')
raise IndexError('List index out of range')
25 changes: 20 additions & 5 deletions BackpackTF/currency.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ def __init__(self, apikey=""):
#
# Function Returns A JSON of the value of currencies
#

def getCurrencies(self):
def get_currencies(self):
import requests
import json

Expand All @@ -28,6 +27,10 @@ def getCurrencies(self):
else:
raise Exception('Your API key is invalid')

# alias for compatibility with older versions
# please use the new name, "get_currencies"
getCurrencies = get_currencies

#
# Gets Price History of a specific item in an array of previous values
#
Expand All @@ -42,7 +45,7 @@ def getCurrencies(self):
# here's a link to an item http://prntscr.com/pf2s0h
#

def priceHistory(self, name="Pyromancer's Mask", quality="Unique", craftable=1, tradable=1, priceIndex=0):
def price_history(self, name="", quality="Unique", craftable=1, tradable=1, priceIndex=0):
import requests
import urllib.parse
import json
Expand Down Expand Up @@ -70,6 +73,10 @@ def priceHistory(self, name="Pyromancer's Mask", quality="Unique", craftable=1,

if success:
return jsondata['response']['history']

# alias for compatibility with older versions
# please use the new name, "price_history"
priceHistory = price_history

#
# Gets Price of a specific item
Expand All @@ -81,7 +88,7 @@ def priceHistory(self, name="Pyromancer's Mask", quality="Unique", craftable=1,
# PriceIndex - Not really sure to be honest
#

def itemPrice(self, name="Pyromancer's Mask", quality="Unique", craftable=1, tradable=1, priceIndex=0):
def item_price(self, name="", quality="Unique", craftable=1, tradable=1, priceIndex=0):
import requests
import urllib.parse
import json
Expand Down Expand Up @@ -110,13 +117,17 @@ def itemPrice(self, name="Pyromancer's Mask", quality="Unique", craftable=1, tra
if success:
return jsondata['response']['history'][len(jsondata['response']['history']) - 1]

# alias for compatibility with older versions
# please use the new name, "item_price"
itemPrice = item_price

#
# Gets all prices, requires an elevated API key
#
# Since - Only prices that have been updated since the unix EPOCH will be shown
#

def getAllPrices(self, raw=2, since=0):
def get_all_prices(self, raw=2, since=0):
import requests
import json

Expand All @@ -131,3 +142,7 @@ def getAllPrices(self, raw=2, since=0):

if success:
return jsondata['response']

# alias for compatibility with older versions
# please use the new name, "get_all_prices"
getAllPrices = get_all_prices
55 changes: 43 additions & 12 deletions BackpackTF/miscutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,105 +63,136 @@ def __init__(self):
#
# Converts quality string to quality int
#
def quality_String_To_Int(self, string):
def quality_string_to_int(self, string):
try:
return self.qualitiesObj[string.lower()]
except:
return ""

# alias for compatibility with older versions
# please use the new name, "quality_string_to_int"
quality_String_To_Int = quality_string_to_int

#
# Converts particle string to particle int
#
def particle_String_To_Int(self, string):
def particle_string_to_int(self, string):
try:
return self.particleObj[string.lower()]
except:
return ""

# alias for compatibility with older versions
# please use the new name, "particle_string_to_int"
particle_String_To_Int = particle_string_to_int

#
# Converts rarity string to rarity int
#
def rarity_String_To_Int(self, string):
def rarity_string_to_int(self, string):
try:
return self.raritiesObj[string.lower()]
except:
return ""

# alias for compatibility with older versions
# please use the new name, "rarity_string_to_int"
rarity_String_To_Int = rarity_string_to_int

#
# Origin quality string to origin int
#
def origin_String_To_Int(self, string):
def origin_string_to_int(self, string):
try:
return self.originsObj[string.lower()]
except:
return ""

# alias for compatibility with older versions
# please use the new name, "origin_string_to_int"
origin_String_To_Int = origin_string_to_int

#
# Converts wear_tier string to wear_tier int
#
def wear_tier_String_To_Int(self, string):
def wear_tier_string_to_int(self, string):
try:
return self.wear_tiersObj[string.lower()]
except:
return ""

# alias for compatibility with older versions
# please use the new name, "wear_tier_string_to_int"
wear_tier_String_To_Int = wear_tier_string_to_int

#
# Converts killstreaker string to killstreaker int
#
def killstreaker_String_To_Int(self, string):
def killstreaker_string_to_int(self, string):
try:
return self.killstreakers[string.lower()]
except:
return ""


# alias for compatibility with older versions
# please use the new name, "killstreaker_string_to_int"
killstreaker_String_To_Int = killstreaker_string_to_int

#
# Converts sheen string to sheen int
#
def sheen_String_To_Int(self, string):
def sheen_string_to_int(self, string):
try:
return self.sheensObj[string.lower()]
except:
return ""

# alias for compatibility with older versions
# please use the new name, "sheen_string_to_int"
sheen_String_To_Int = sheen_string_to_int

#
# Converts killstreak_tier string to killstreak_tier int
#
def killstreak_tier_String_To_Int(self, string):
def killstreak_tier_string_to_int(self, string):
try:
return self.killstreak_tiers[string.lower()]
except:
return ""

# alias for compatibility with older versions
# please use the new name, "killstreak_tier_string_to_int"
killstreak_tier_String_To_Int = killstreak_tier_string_to_int

#
# Converts strange_part string to strange_part int
#
def strange_parts_String_To_Int(self, string):
def strange_parts_string_to_int(self, string):
try:
return self.strange_partsObj[string.lower()]
except:
return ""

# alias for compatibility with older versions
# please use the new name, "strange_parts_string_to_int"
strange_parts_String_To_Int = strange_parts_string_to_int

#
# Converts paint string to paint int
#
def paint_String_To_Int(self, string):
def paint_string_to_int(self, string):
try:
return self.paintsObj[string.lower()]
except:
return ""

# alias for compatibility with older versions
# please use the new name, "paint_string_to_int"
paint_String_To_Int = paint_string_to_int

#
# Converts steam ID into the account_id account ID is used in trading requests
#
def steam_id_to_account_id(self, steam_id):
import struct
return str(struct.unpack('>L', int(steam_id).to_bytes(8, byteorder='big')[4:])[0])
return str(struct.unpack('>L', int(steam_id).to_bytes(8, byteorder='big')[4:])[0])
Loading