-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRSSScraper.cs
More file actions
192 lines (166 loc) · 7.84 KB
/
Copy pathRSSScraper.cs
File metadata and controls
192 lines (166 loc) · 7.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
using System;
using System.Globalization;
using System.Linq;
using System.Net;
namespace CLReader
{
static public class RSSScraper
{
static public void SearchCL(SearchTerm st,string cityList,string clDomain,Matches matches,Matches lastMatches)
{
foreach(string city in cityList.Split(',').ToList())
{
string clURL = $"https://{city}.craigslist{clDomain}/search/sss?excats=5-2-13-22-2-24-1-4-19-1-1-1-1-1-1-3-6-10-1-1-1-2-10-1-1-1-1-1-4-1-7-1-1-1-1-7-1-1-1-1-1-1-1-2-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1&format=rss&query={st.CLSearch}&sort=rel";
//Console.WriteLine($"City: <a href={clURL}>{city}</a><br>");
FeedParser parser = new FeedParser();
var items = parser.Parse(clURL,FeedType.RDF);
foreach(Item item in items)
{
//Check for title exclude keywords and chars
bool excludeKeywordsFlag = Helper.CheckTitle(st.ExcludeKeywords+" ",item.Title);
bool excludeCharsFlag = Helper.CheckTitle(st.ExcludeChars,item.Title);
//Get and check year (if it can parse)
bool yearFlag = false;
long year = GetYearFromTitle(item.Title);
if((year == 0 || year >= st.MinYear) && year <= st.MaxYear)
yearFlag=true;
//Get and check price (zero if can't parse)
bool priceFlag = false;
long price = GetPrice(item.Title,'$');
if(((price == 0 && !st.IgnoreZeroPrice) || price >= st.MinPrice) && price <= st.MaxPrice)
priceFlag=true;
//If we're still ok
if(excludeKeywordsFlag && excludeCharsFlag && yearFlag && priceFlag)
{
//Update item
item.Starred = st.Starred;
item.SearchString = st.CLSearch;
item.WebSite = "CraigsList";
//Add item to list
bool added=matches.AddItem(item,lastMatches);
//if(added)
// Console.WriteLine($"{price} - <a href={item.Link}>{item.Title}</a><br>");
}
}
}
}
static public void SearchSamba(SearchTerm st,Matches matches,Matches lastMatches)
{
//Searches only within eurovan
string clURL = $"https://www.thesamba.com/vw/classifieds/rss/search.php?type=text&stype=any&keywords={st.SambaSearch}&yearfrom={st.MinYear}&yearto={st.MaxYear}&model%5B%5D=§ion%5B%5D=75&country=USA&wanted=hide&sort=date&sort_order=DESC";
FeedParser parser = new FeedParser();
var items = parser.Parse(clURL,FeedType.RSS);
foreach(Item item in items)
{
//Check for title exclude keywords and chars
bool excludeKeywordsFlag = Helper.CheckTitle(st.ExcludeKeywords+" ",item.Title);
bool excludeCharsFlag = Helper.CheckTitle(st.ExcludeChars,item.Title);
//Get and check price (zero if can't parse)
bool priceFlag = false;
long price = GetPrice(item.Title,'$');
if(((price == 0 && !st.IgnoreZeroPrice) || price >= st.MinPrice) && price <= st.MaxPrice)
priceFlag=true;
//If we're still ok
if(excludeKeywordsFlag && excludeCharsFlag && priceFlag)
{
//Update item
item.Starred = st.Starred;
item.SearchString = st.SambaSearch;
item.WebSite = "Samba";
//Add item to list
bool added=matches.AddItem(item,lastMatches);
//if(added)
// Console.WriteLine($"{price} - <a href={item.Link}>{item.Title}</a><br>");
}
}
}
static public void SearchEbay(SearchTerm st,Matches matches,Matches lastMatches)
{
//enclode search terms
string encodedSearch = System.Net.WebUtility.UrlEncode(st.EbaySearch);
//Searches in all of ebay motors (does'nt limit by year)
string clURL = $"https://www.ebay.com/sch/eBay-Motors/6000/i.html?_udlo={st.MinPrice}&_udhi={st.MaxPrice}&_mPrRngCbx=1&_from=R40&_sop=10&_nkw={encodedSearch}&LH_PrefLoc=3&_rss=1";
FeedParser parser = new FeedParser();
var items = parser.Parse(clURL,FeedType.RSS);
foreach(Item item in items)
{
//Check for title exclude keywords and chars
bool excludeKeywordsFlag = Helper.CheckTitle(st.ExcludeKeywords+" ",item.Title);
bool excludeCharsFlag = Helper.CheckTitle(st.ExcludeChars,item.Title);
//Get and check year (if it can parse)
bool yearFlag = false;
long year = GetYearFromLink(item.Link);
if((year == 0 || year >= st.MinYear) && year <= st.MaxYear)
yearFlag=true;
//Get and check price (zero if can't parse)
bool priceFlag = false;
long price = GetPrice(item.Content,'$','<');
if(((price == 0 && !st.IgnoreZeroPrice) || price >= st.MinPrice) && price <= st.MaxPrice)
priceFlag=true;
//If we're still ok
if(excludeKeywordsFlag && excludeCharsFlag && priceFlag && yearFlag)
{
//Update item
item.Title = $"{item.Title} ${price} ";
item.Starred = st.Starred;
item.SearchString = st.EbaySearch;
item.WebSite = "Ebay";
//Add item to list
bool added=matches.AddItem(item,lastMatches);
//if(added)
// Console.WriteLine($"{price} - <a href={item.Link}>{item.Title}</a><br>");
}
}
}
static public long GetYearFromLink(string link)
{
long year = 0;
try
{
int startPos=link.IndexOf("itm/")+4;
int endPos=link.IndexOf('-',startPos);
string yearStr = link.Substring(startPos,endPos-startPos);
year = Convert.ToInt32(yearStr);
}
catch {}
return year;
}
static public long GetYearFromTitle(string title)
{
long year = 0;
try
{
string yearStr = title.Substring(0,title.IndexOf(' '));
year = Convert.ToInt32(yearStr);
}
catch {}
return year;
}
static public long GetPrice(string textToParse,char delimeter)
{
long price = 0;
try
{
string priceStr = textToParse.Substring(textToParse.IndexOf(delimeter)+1);
price = (long)decimal.Parse(priceStr, NumberStyles.Any);
//price = Convert.ToInt32(priceStr);
}
catch {}
return price;
}
static public long GetPrice(string textToParse,char delimeter,char endChar)
{
long price = 0;
try
{
int startPos=textToParse.IndexOf(delimeter)+1;
int endPos=textToParse.IndexOf(endChar,startPos);
string priceStr = textToParse.Substring(startPos,endPos-startPos);
//Console.WriteLine($"price: {priceStr}");
price = (long)decimal.Parse(priceStr, NumberStyles.Any);
}
catch {}
return price;
}
}
}