-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparseBing.cpp
More file actions
61 lines (48 loc) · 1.64 KB
/
parseBing.cpp
File metadata and controls
61 lines (48 loc) · 1.64 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
#include <iostream>
#include <fstream>
#include <boost/algorithm/string/replace.hpp>
using namespace std;
int main() {
std::string line;
ifstream inFile;
inFile.open("./ankleBreak.txt");
if (!inFile) {
cerr << "File was not opened\n";
exit(1);
}
ofstream outFile;
outFile.open("./parsedAnkleBreak.txt");
if (!outFile) {
cerr << "Output file creation failed";
exit(1);
}
while (getline(inFile, line)) {
// These two delimiters are the start and end to most image links within
// the Bing search URL
std::string delimiter1 = "&mediaurl=";
std::string delimiter2 = "&ex";
// The three file types that we are interested in gathering photos of
std::string delimiter3 = ".jpg";
std::string delimiter4 = ".png";
std::string delimiter5 = ".jpeg";
std::string lineCopy = line;
std::string parse = lineCopy.substr(line.find(delimiter1) + 10, lineCopy.length());
std::string parse2 = parse.substr(0, parse.find(delimiter2));
// Checks that the url is an image file
std::string lastFour = parse2.substr(parse2.length() - 4, parse2.length());
std::string lastFive = parse2.substr(parse2.length() - 5, parse2.length());
if (!(lastFour.compare(delimiter3) == 0 || lastFour.compare(delimiter4) == 0 ||
lastFive.compare(delimiter5) == 0)) {
continue;
}
// Replaces characters in the pseudo-URL's with their original characters
std::string delimiterSlash = "%2f";
std::string delimiterColon = "%3a";
boost::replace_all(parse2, delimiterSlash, "/");
boost::replace_all(parse2, delimiterColon, ":");
// Prints the url to the file
outFile << parse2 << std::endl;
}
inFile.close();
outFile.close();
}