static void Main(string[] args) { //grab cards from excel sheet and compute average hashes List<VideoCard> basicInfoList = new List<VideoCard>(); basicInfoList = readFile(@"C:\radeon.csv"); //delete JSON values from previous program execution deletePreviousResults(); int status = 0; // List<VideoCard> cardsFromEbay = new List<VideoCard>(); List<RefVideoCard> almostDoneCards = calculateAverageHash(basicInfoList); RefVideoCard resultCardStats = new RefVideoCard(); List<RefVideoCard> cardStatsList = new List<RefVideoCard>(); List<VideoCard> cashAveragedCards = new List<VideoCard>(); for (int i = 0; i < cardsOfInterest.Length; i++) { //grab cards from ebay from list of interesting cards //cardsFromEbay List = GrabPricesFromEbay("Radeon 5970"); cardsFromEbay = GrabPricesFromEbay(cardsOfInterest[i]); //we now find the AveragePrice, CardCount, and ID of the list of Radeon 5970s resultCardStats = calculateAverages(cardsFromEbay, cardsOfInterest[i]); cardStatsList.Add(resultCardStats); VideoCard cashedCard = new VideoCard(); cashedCard.SetCardName(resultCardStats.GetCardName()); cashedCard.SetId(resultCardStats.GetId()); cashedCard.SetPrice(Convert.ToDouble(resultCardStats.GetAveragePrice())); cashAveragedCards.Add(cashedCard); //We now append the AveragePrice, CardCount, and ID info to the JSON file (in later version this could be an API call that returns JSON) //WriteEbayPricesToSQLServer(resultCardStats.GetId()); } List<FinishedVideoCard> finishedCards = CalculateHashForCash(cashAveragedCards, almostDoneCards); for (int i = 0; i < cardsOfInterest.Length; i++) { if (i == 0) { status = 0; } else if (i == cardsOfInterest.Length - 1) { status = 2; } else { status = 1; } writeEbayPricesToJSON(cardStatsList[i], status, finishedCards[i]); } Console.WriteLine("It got to here! Yay! :)"); Console.ReadKey(); }
static List<VideoCard> readFile(String filename) { string text = System.IO.File.ReadAllText(filename); System.Console.WriteLine("Contents of radeonCards.csv = {0}", text); string[] lines = System.IO.File.ReadAllLines(filename); System.Console.WriteLine("Contents of WriteLines2.txt"); List<VideoCard> cardList = new List<VideoCard>(); for (int i = 0; i < lines.Length; i++) { string line = lines[i]; VideoCard video = new VideoCard(); Console.WriteLine("\t" + line); if (line.Contains('"')) { List<string> quotes = line.Split('"').ToList<string>(); List<string> parsedInfo = quotes[2].Split(',').ToList<string>(); video.SetCardName(quotes[1]); video.SetHashRate(Convert.ToInt32(parsedInfo[1])); } else { List<string> parsedInfo = line.Split(',').ToList<string>(); video.SetCardName(parsedInfo[0]); video.SetHashRate(Convert.ToInt32(parsedInfo[1])); } video.SetId(i); cardList.Add(video); } return cardList; }
static List<VideoCard> GrabPricesFromEbay(string keyword) { List<VideoCard> foundCards = new List<VideoCard>(); //setup for console logging of api results LoggerService.SetLogger(new ConsoleLogger()); ILogger logger = LoggerService.GetLogger(); try { ClientConfig config = new ClientConfig(); // Initialize service end-point configuration config.EndPointAddress = "http://svcs.sandbox.ebay.com/services/search/FindingService/v1"; // set eBay developer account AppID config.ApplicationId = "JackPetr-b629-4a64-94a2-cb909b9c0c47"; // Create a service client FindingServicePortTypeClient client = FindingServiceClientFactory.getServiceClient(config); // Create request object FindCompletedItemsRequest completedItemsRequest = new FindCompletedItemsRequest(); // Set request parameters keyword = keyword + " -water -block -waterblock -heatsink -heat -sink"; completedItemsRequest.keywords = keyword; DateTime today = DateTime.UtcNow; DateTime month = new DateTime(today.Year, today.Month, 1); DateTime lastMonth = month.AddMonths(-1); ItemFilter if1 = new ItemFilter(); if1.name = ItemFilterType.EndTimeFrom; if1.value = new string[] {lastMonth.ToString("o")}; ItemFilter if2 = new ItemFilter(); if2.name = ItemFilterType.EndTimeTo; if2.value = new string[] { today.ToString("o") }; ItemFilter if3 = new ItemFilter(); if3.name = ItemFilterType.MinPrice; if3.paramName = "Currency"; if3.paramValue = "USD"; if3.value = new string[] {"50"}; ItemFilter if4 = new ItemFilter(); if4.name = ItemFilterType.MaxPrice; if4.paramName = "Currency"; if4.paramValue = "USD"; if4.value = new string[] { "1100" }; ItemFilter if5 = new ItemFilter(); if5.name = ItemFilterType.ExcludeCategory; if5.value = new string[] {"179"}; ItemFilter[] ifa = new ItemFilter[5]; ifa[0] = if1; ifa[1] = if2; ifa[2] = if3; ifa[3] = if4; ifa[4] = if5; completedItemsRequest.itemFilter = ifa; PaginationInput pi = new PaginationInput(); pi.entriesPerPage = 200; pi.entriesPerPageSpecified = true; completedItemsRequest.paginationInput = pi; // Call the service FindCompletedItemsResponse response = client.findCompletedItems(completedItemsRequest); // Show output if (Debug) if (response.ack.ToString().Equals("Failure")) { int tries = 0; while (tries < 3) { if (response.ack.ToString().Equals("Failure")) { //retry tries++; response = client.findCompletedItems(completedItemsRequest); }else { break; } } } logger.Info("Ack = " + response.ack); logger.Info("Find " + response.searchResult.count + " items."); SearchItem[] items = response.searchResult.item; if(Debug){logSearchResultsToFile(items);} foreach (SearchItem item in items) { if (item.sellingStatus.sellingState.Equals("EndedWithSales")) { VideoCard trackCard = new VideoCard(); trackCard.SetCardName(item.title); trackCard.SetPrice(item.sellingStatus.currentPrice.Value); foundCards.Add(trackCard); logger.Info("Item" + item.title + "added!"); logger.Info(item.sellingStatus.currentPrice.Value); } } } catch (Exception ex) { // Handle exception if any logger.Error(ex); } return foundCards; }