Advertisement
power_walker

Pull List

Sep 29th, 2014
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.IO;
  10. using System.Net;
  11.  
  12. namespace PullList
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.        
  17.         public Form1()
  18.         {
  19.             InitializeComponent();
  20.         }
  21.  
  22.  
  23.         class Comics
  24.         {
  25.             string title;
  26.             string price;
  27.         }
  28.  
  29.         // Button1 brings back the current list of comics
  30.         private void button1_Click(object sender, EventArgs e)
  31.         {
  32.             string url = "http://www.previewsworld.com/shipping/newreleases.txt";
  33.             GetList(url);
  34.            
  35.             Parse(url);
  36.  
  37.         }   // Button 1
  38.  
  39.         // Button2 brings back the next week's list of comics
  40.         private void button2_Click(object sender, EventArgs e)
  41.         {
  42.             string url = "http://www.previewsworld.com/shipping/upcomingreleases.txt";
  43.             GetList(url);
  44.         }   // Button 2
  45.  
  46.         // Button3 brings back the list of comics 2 weeks out
  47.         private void button3_Click(object sender, EventArgs e)
  48.         {
  49.             string url = "http://www.previewsworld.com/shipping/releasestwoweeks.txt";
  50.             GetList(url);
  51.         }   // Button 3
  52.  
  53.         private void GetList(string URL)
  54.         {
  55.             HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
  56.             HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  57.             StreamReader sr = new StreamReader(response.GetResponseStream());
  58.             richTextBox1.Text = sr.ReadToEnd();
  59.             sr.Close();
  60.         }
  61.  
  62.         // From /u/AwwComeOnNow on Reddit
  63.         // http://www.reddit.com/r/learnprogramming/comments/2gv21k/c_looking_for_a_breadcrumb/
  64.         private void Parse(string URL)
  65.         {
  66.             HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
  67.             HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  68.             StreamReader sr = new StreamReader(response.GetResponseStream());
  69.            
  70.             string line = "";
  71.             List<Comics> comics = new List<Comics>();
  72.  
  73.             List<string> _comics = new List<string>();
  74.  
  75.             while (sr.Peek() != 1)  // This will look at the next line and return a -1 if there is no more lines
  76.             {
  77.                 line = sr.ReadLine();   // reads the next available line in the file
  78.                 _comics.Add(line);
  79.                
  80.                 //MessageBox.Show(line);
  81.  
  82.                 if (line.Contains('\t'))
  83.                 {
  84.                     string[] linesplit = line.Split('\t');  // Split it into an array, breaking it at the tabs
  85. //                    comics.Add(linesplit[1], linesplit[2]);   // Add the second value as title and third value as price in the array to a list
  86.                 }
  87.             }
  88.  
  89.             sr.Close();
  90.         }
  91.  
  92.  
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement