Advertisement
Guest User

Untitled

a guest
May 29th, 2015
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.28 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. using System.Collections;
  8. using System.Web;
  9. using System.Net;
  10. using System.IO;
  11. using Newtonsoft.Json;
  12. using SteamBotV2.SerializationClasses;
  13.  
  14. namespace SteamBotV2
  15. {
  16.     public class Inventory
  17.     {
  18.         private int errorCounter = 0;
  19.         public Hashtable priceInventoryHashtable;
  20.         public List<InventoryEntries> list;
  21.  
  22.         public Inventory(String inventoryURL)
  23.         {
  24.             DateTime Time1 = DateTime.Now;
  25.             list = new List<InventoryEntries>();
  26.             this.priceInventoryHashtable = new Hashtable();
  27.             HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(inventoryURL);
  28.             WebReq.Method = "GET";
  29.             WebReq.Timeout = 7000;
  30.             HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
  31.             Stream Answer = WebResp.GetResponseStream();
  32.             StreamReader _Answer = new StreamReader(Answer);
  33.             String result = _Answer.ReadToEnd();
  34.             var root = JsonConvert.DeserializeObject<RootObject>(result);
  35.             foreach (var pair in root.rgInventory)
  36.             {
  37.                 //Console.WriteLine("{0}, {1}", pair.Key, pair.Value.classid);
  38.                 DescriptionsEntry temp = root.rgDescriptions[pair.Value.classid + "_" + pair.Value.instanceid];
  39.                 if (temp.tradable == 1 && temp.marketable == 1)
  40.                 {
  41.                     InventoryEntries tempInventoryObject = this.getInventoryEntryObject(temp);
  42.                     list.Add(tempInventoryObject);
  43.                 }
  44.             }
  45.             DateTime Time2 = DateTime.Now;
  46.             foreach (var data in list)
  47.             {
  48.                 Console.WriteLine(data.name + ": " + data.price.ToString());
  49.             }
  50.             TimeSpan ts = Time2 - Time1;
  51.  
  52.             int differenceInMilli = ts.Seconds;
  53.             Console.WriteLine(differenceInMilli);
  54.             Console.WriteLine("FEHLER= " + this.errorCounter);
  55.             //Hier Inventar lesen
  56.             //get price über http://steamcommunity.com/market/priceoverview/?currency=3&appid=570&market_hash_name=Shift%20of%20the%20Silent%20Guardian
  57.             //get inv über http://steamcommunity.com/profiles/76561198028630048/inventory/json/570/2/
  58.         }
  59.  
  60.         public InventoryEntries getInventoryEntryObject(DescriptionsEntry input)
  61.         {
  62.             InventoryEntries a = new InventoryEntries();
  63.             a.appid = input.appid;
  64.             a.classid = input.classid;
  65.             a.commodity = input.commodity;
  66.             a.instanceid = input.instanceid;
  67.             a.market_hash_name = input.market_hash_name;
  68.             a.market_name = input.market_name;
  69.             a.marketable = input.marketable;
  70.             a.name = input.name;
  71.             a.tradable = input.tradable;
  72.             a.type = input.type;
  73.             String tempStr = input.market_name;
  74.             a.price = getPrice((HttpUtility.UrlEncode(tempStr)).Replace("+", "%20"));
  75.  
  76.             return a;
  77.         }
  78.  
  79.         public double getPrice(String marketHashName)
  80.         {
  81.             HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create("http://steamcommunity.com/market/priceoverview/?currency=3&appid=570&market_hash_name=" +
  82.                 marketHashName);
  83.             WebReq.Method = "GET";
  84.             WebReq.Timeout = 2000;
  85.             double doubleResult = 0.00;
  86.             try
  87.             {
  88.                 HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
  89.                 Stream Answer = WebResp.GetResponseStream();
  90.                 StreamReader _Answer = new StreamReader(Answer);
  91.                 String result = _Answer.ReadToEnd();
  92.  
  93.                 result = HttpUtility.HtmlDecode(result);
  94.                 result = result.Replace("€ ", "");
  95.                 result = result.Replace(",--", "");
  96.                 var root = JsonConvert.DeserializeObject<RootPriceRequest>(result);
  97.                 doubleResult = Double.Parse(root.lowest_price);
  98.             } catch (WebException ex) {
  99.             }
  100.             return doubleResult;
  101.         }
  102.     }
  103.  
  104.     public class InventoryEntries : SteamBotV2.SerializationClasses.DescriptionsEntry
  105.     {
  106.         public double price;
  107.     }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement