Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Collections;
- using System.Web;
- using System.Net;
- using System.IO;
- using Newtonsoft.Json;
- using SteamBotV2.SerializationClasses;
- namespace SteamBotV2
- {
- public class Inventory
- {
- private int errorCounter = 0;
- public Hashtable priceInventoryHashtable;
- public List<InventoryEntries> list;
- public Inventory(String inventoryURL)
- {
- DateTime Time1 = DateTime.Now;
- list = new List<InventoryEntries>();
- this.priceInventoryHashtable = new Hashtable();
- HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(inventoryURL);
- WebReq.Method = "GET";
- WebReq.Timeout = 7000;
- HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
- Stream Answer = WebResp.GetResponseStream();
- StreamReader _Answer = new StreamReader(Answer);
- String result = _Answer.ReadToEnd();
- var root = JsonConvert.DeserializeObject<RootObject>(result);
- foreach (var pair in root.rgInventory)
- {
- //Console.WriteLine("{0}, {1}", pair.Key, pair.Value.classid);
- DescriptionsEntry temp = root.rgDescriptions[pair.Value.classid + "_" + pair.Value.instanceid];
- if (temp.tradable == 1 && temp.marketable == 1)
- {
- InventoryEntries tempInventoryObject = this.getInventoryEntryObject(temp);
- list.Add(tempInventoryObject);
- }
- }
- DateTime Time2 = DateTime.Now;
- foreach (var data in list)
- {
- Console.WriteLine(data.name + ": " + data.price.ToString());
- }
- TimeSpan ts = Time2 - Time1;
- int differenceInMilli = ts.Seconds;
- Console.WriteLine(differenceInMilli);
- Console.WriteLine("FEHLER= " + this.errorCounter);
- //Hier Inventar lesen
- //get price über http://steamcommunity.com/market/priceoverview/?currency=3&appid=570&market_hash_name=Shift%20of%20the%20Silent%20Guardian
- //get inv über http://steamcommunity.com/profiles/76561198028630048/inventory/json/570/2/
- }
- public InventoryEntries getInventoryEntryObject(DescriptionsEntry input)
- {
- InventoryEntries a = new InventoryEntries();
- a.appid = input.appid;
- a.classid = input.classid;
- a.commodity = input.commodity;
- a.instanceid = input.instanceid;
- a.market_hash_name = input.market_hash_name;
- a.market_name = input.market_name;
- a.marketable = input.marketable;
- a.name = input.name;
- a.tradable = input.tradable;
- a.type = input.type;
- String tempStr = input.market_name;
- a.price = getPrice((HttpUtility.UrlEncode(tempStr)).Replace("+", "%20"));
- return a;
- }
- public double getPrice(String marketHashName)
- {
- HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create("http://steamcommunity.com/market/priceoverview/?currency=3&appid=570&market_hash_name=" +
- marketHashName);
- WebReq.Method = "GET";
- WebReq.Timeout = 2000;
- double doubleResult = 0.00;
- try
- {
- HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
- Stream Answer = WebResp.GetResponseStream();
- StreamReader _Answer = new StreamReader(Answer);
- String result = _Answer.ReadToEnd();
- result = HttpUtility.HtmlDecode(result);
- result = result.Replace("€ ", "");
- result = result.Replace(",--", "");
- var root = JsonConvert.DeserializeObject<RootPriceRequest>(result);
- doubleResult = Double.Parse(root.lowest_price);
- } catch (WebException ex) {
- }
- return doubleResult;
- }
- }
- public class InventoryEntries : SteamBotV2.SerializationClasses.DescriptionsEntry
- {
- public double price;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement