1
我的腳本運行並獲取用戶csgo清單,然後通過蒸汽市場運行它以獲取價格。它打印出的價格非常清楚,但是當我打印誰在最後詞典:Python字典出現在<0x03B22CF8>的內置方法替換unicode對象>
print(item_prices))
它給了我:
<built-in method replace of unicode object at 0x03B22CF8>
這是我的代碼:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import urllib2
import json
import datetime
import time
global file_name
file_name = "skins 2017-05-05 23-15-16.txt"
wear_list = ["Factory New", "Minimal Wear", "Field-Tested", "Well-Worn", "Battle-Scarred"]
wear_val = {"Factory New": 1, "Minimal Wear": 2, "Field-Tested": 3, "Well-Worn": 4, "Battle-Scarred": 5}
items = []
item_prices = {}
def getInventory(steamid):
try:
data = urllib2.urlopen('http://steamcommunity.com/profiles/'+steamid+'/inventory/json/730/2')
except:
print("Overloaded the server...")
print("Waiting...")
time.sleep(60)
data = urllib2.urlopen('http://steamcommunity.com/profiles/'+steamid+'/inventory/json/730/2')
json_data = json.loads(data.read())
descriptions = json_data['rgDescriptions']
now = datetime.datetime.now()
date = now.strftime("%Y-%m-%d %H-%M-%S")
global file_name
file_name = "skins " + str(date) + ".txt"
txt = open(file_name, "w+")
for v in descriptions:
name = str([descriptions[v]['market_name']])
name = name[3:]
name = name[:-2]
if name.endswith("Flip Knife | Rust Coat (Battle-Scarred)"):
name = name[7:]
if name.startswith("StatTrak"):
name = name[15:]
name = 'StatTrak ' + name
if name.endswith("(Dragon King) (Minimal Wear)"):
name = "M4A4 | Dragon King (Minimal Wear"
txt.write(name)
txt.write('\n')
#txt.write(str(descriptions[v]))
#txt.write('\n')
print(name)
txt.close()
print('Done!')
return
def getPrice():
x = 1
gun_name_wear = 0
txt = open(file_name, "r+")
for line in txt:
stattrak = 0
wear = line[line.find("(")+1:line.find(")")]
if wear in wear_list:
print(wear)
wear = wear.replace(" ","%20")
gun = line.split(' |', 1)[0].replace('.', '')
print(gun)
if "StatTrak" in gun:
stattrak = 1
gun = gun.replace("StatTrak","")
if gun.startswith(" "):
gun = gun[1:]
gun = gun.replace(" ", "%20")
name = line[line.find("| ")+1:line.find(" (")]
if name.startswith(" "):
name = name[1:]
print(name)
name = name.replace(" ", "%20")
if stattrak == 1:
try:
data = urllib2.urlopen("http://steamcommunity.com/market/priceoverview/?appid=730¤cy=2&market_hash_name=StatTrak%E2%84%A2%20" + gun + "%20|%20" + name + "%20(" + wear + ")")
except:
print("Overloaded the server...")
print("Waiting...")
time.sleep(60)
data = urllib2.urlopen("http://steamcommunity.com/market/priceoverview/?appid=730¤cy=2&market_hash_name=StatTrak%E2%84%A2%20" + gun + "%20|%20" + name + "%20(" + wear + ")")
json_data = json.loads(data.read())
print(json_data)
try:
price = json_data['lowest_price']
except KeyError:
price = json_data['median_price']
price = price[-4:]
print(price)
gun = gun.replace("%20", " ")
name = name.replace("%20", " ")
wear = wear.replace("%20", " ")
item_prices[str("StatTrak " + gun + " " + name + " " + wear)] = price
continue
if "knife" in line.lower():
try:
data = urllib2.urlopen("http://steamcommunity.com/market/priceoverview/?appid=730¤cy=2&market_hash_name=★%20" + gun + "%20|%20" + name + "%20(" + wear + ")")
except:
print("Overloaded the server...")
print("Waiting...")
time.sleep(60)
data = urllib2.urlopen("http://steamcommunity.com/market/priceoverview/?appid=730¤cy=2&market_hash_name=★%20" + gun + "%20|%20" + name + "%20(" + wear + ")")
json_data = json.loads(data.read())
print(json_data)
try:
price = json_data['lowest_price']
except KeyError:
price = json_data['median_price']
price = price[-4:]
print(price)
gun = gun.replace("%20", " ")
name = name.replace("%20", " ")
wear = wear.replace("%20", " ")
item_prices[str(gun + " " + name + " " + wear)] = price
continue
else:
try:
data = urllib2.urlopen("http://steamcommunity.com/market/priceoverview/?appid=730¤cy=2&market_hash_name=" + gun + "%20|%20" + name + "%20(" + wear + ")")
except:
print("Overloaded the server...")
print("Waiting...")
time.sleep(60)
data = urllib2.urlopen("http://steamcommunity.com/market/priceoverview/?appid=730¤cy=2&market_hash_name=" + gun + "%20|%20" + name + "%20(" + wear + ")")
json_data = json.loads(data.read())
print(json_data)
try:
price = json_data['lowest_price']
except KeyError:
price = json_data['median_price']
price = price[-4:]
print(price)
gun = gun.replace("%20", " ")
name = name.replace("%20", " ")
wear = wear.replace("%20", " ")
gun_name_wear = str(gun + " " + name + " " + wear)
price = price.replace
item_prices[str(gun + " " + name + " " + wear)] = price
time.sleep(5)
else:
continue
print(item_prices)
print(item_prices[gun_name_wear])
getInventory('76561198216481185')
getPrice()
,這是輸出的最後幾行:
Battle-Scarred
Flip Knife
Rust Coat
{u'volume': u'16', u'median_price': u'\xa351.80', u'lowest_price': u'\xa352.28', u'success': True}
2.28
Field-Tested
SSG 08
Blood in the Water
{u'volume': u'10', u'median_price': u'\xa312.81', u'lowest_price': u'\xa313.76', u'success': True}
3.76
Field-Tested
StatTrak Dual Berettas
Dualing Dragons
{u'volume': u'173', u'median_price': u'\xa30.23', u'lowest_price': u'\xa30.25', u'success': True}
0.25
{'AK-47 Aquamarine Revenge Field-Tested': <built-in method replace of unicode object at 0x03B22608>, 'StatTrak Desert Eagle Bronze Deco Factory New': u'1.07', 'Flip Knife Rust Coat Battle-Scarred': u'2.28', 'StatTrak M249 Spectre Field-Tested': u'0.19', 'StatTrak MP9 Bioleak Field-Tested': u'0.21', 'Nova Caged Steel Factory New': <built-in method replace of unicode object at 0x03B22CF8>, 'StatTrak Dual Berettas Dualing Dragons Field-Tested': u'0.25', 'StatTrak G3SG1 Murky Minimal Wear': u'0.50', 'StatTrak R8 Revolver Crimson Web Field-Tested': u'0.60', 'SG 553 Pulse Minimal Wear': <built-in method replace of unicode object at 0x03B22620>, 'SSG 08 Detour Minimal Wear': <built-in method replace of unicode object at 0x03B272A8>, 'StatTrak P2000 Pulse Factory New': u'0.95', 'Glock-18 Death Rattle Field-Tested': <built-in method replace of unicode object at 0x03B27188>, 'StatTrak XM1014 Scumbria Field-Tested': u'0.18', 'Five-SeveN Capillary Minimal Wear': <built-in method replace of unicode object at 0x03B22CE0>, 'Sawed-Off Forest DDPAT Minimal Wear': <built-in method replace of unicode object at 0x03AE2170>, 'Glock-18 Water Elemental Field-Tested': <built-in method replace of unicode object at 0x03AE0FB0>, 'AWP BOOM Minimal Wear': <built-in method replace of unicode object at 0x03B22320>, 'AWP Safari Mesh Battle-Scarred': <built-in method replace of unicode object at 0x03B225A8>, 'M4A1-S VariCamo Field-Tested': <built-in method replace of unicode object at 0x03AE2038>, 'MAC-10 Neon Rider Field-Tested': <built-in method replace of unicode object at 0x03B22350>, 'StatTrak MP7 Urban Hazard Field-Tested': u'0.18', 'StatTrak Negev Bratatat Minimal Wear': u'0.96', 'StatTrak SCAR-20 Outbreak Field-Tested': u'0.26', 'MP7 Army Recon Field-Tested': <built-in method replace of unicode object at 0x03B27230>, 'UMP-45 Scaffold Field-Tested': <built-in method replace of unicode object at 0x03AE0E78>, 'StatTrak Galil AR Kami Minimal Wear': u'0.46', 'USP-S Cyrex Field-Tested': <built-in method replace of unicode object at 0x03B22380>, 'SSG 08 Blue Spruce Field-Tested': <built-in method replace of unicode object at 0x03AE0F98>, 'StatTrak Tec-9 Isaac Field-Tested': u'1.18', 'MAG-7 Heat Field-Tested': <built-in method replace of unicode object at 0x03B27218>, 'M4A1-S Hyper Beast Field-Tested': <built-in method replace of unicode object at 0x03B22D88>, 'Five-SeveN Monkey Business Field-Tested': <built-in method replace of unicode object at 0x03B271E8>, 'PP-Bizon Photic Zone Minimal Wear': <built-in method replace of unicode object at 0x03B27098>, 'StatTrak CZ75-Auto Twist Minimal Wear': u'0.35', 'SSG 08 Blood in the Water Field-Tested': <built-in method replace of unicode object at 0x03AE2068>, 'FAMAS Valence Field-Tested': <built-in method replace of unicode object at 0x03B22CC8>, 'P250 Valence Field-Tested': <built-in method replace of unicode object at 0x03B27170>, 'StatTrak P90 Elite Build Minimal Wear': u'0.74', 'P250 Supernova Minimal Wear': <built-in method replace of unicode object at 0x03B22C98>, 'StatTrak AK-47 Elite Build Well-Worn': u'2.62', 'UMP-45 Gunsmoke Minimal Wear': <built-in method replace of unicode object at 0x03AE2050>, 'StatTrak Sawed-Off Origami Minimal Wear': u'0.26'}
<built-in method replace of unicode object at 0x03AE2068>
>>>
在此先感謝,請不要馬上downvote!
謝謝,我一定已經開始寫東西,但沒有完成它! –