Skip to content

Commit 3c4a89d

Browse files
authored
Add files via upload
1 parent 79b0116 commit 3c4a89d

File tree

6 files changed

+145
-0
lines changed

6 files changed

+145
-0
lines changed

BaseCrawler.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <bits/stdc++.h>
2+
#include "BaseCrawler.h"
3+
using namespace std;
4+
5+
void BaseCrawler:: addTargetData (const DataType &datatype) {
6+
TargetDataList.push_back (datatype);
7+
}
8+
9+
void BaseCrawler:: addObject (const BaseObject* &object) {
10+
ObjectList.push_back ((BaseObject*) object);
11+
}

BaseCrawler.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#pragma once
2+
#include <bits/stdc++.h>
3+
#include "Catcher.h"
4+
#include "BaseObject.h"
5+
using namespace std;
6+
7+
class BaseCrawler {
8+
vector<BaseObject*> ObjectList;
9+
vector<DataType> TargetDataList;
10+
11+
/*
12+
ObjectList is the list of all the downloaded movies
13+
TargetDataList is the list of all the targeted data
14+
15+
*/
16+
17+
virtual void addTargetData (const DataType &) = 0; // add a kind of target data
18+
virtual void addObject (const BaseObject* &) = 0; // add a object(movie)
19+
public:
20+
virtual void init (const vector<DataType> &) = 0; // the general interface of initialization
21+
virtual void work() = 0; // the general interface of main work
22+
};

BaseObject.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <bits/stdc++.h>
2+
#include "BaseObject.h"
3+
using namespace std;
4+
5+
DataType BaseData:: getType() {
6+
return type;
7+
}
8+
9+
int BaseObject:: getDataSize() {
10+
return DataSet.size();
11+
}
12+
13+
vector<BaseData*> BaseObject:: getDataSet() {
14+
return DataSet;
15+
};
16+
17+
void BaseObject:: printObject() {
18+
for (int i = 0; i < DataSet.size(); i++)
19+
DataSet[i]-> printData();
20+
}

BaseObject.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#pragma once
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
5+
enum DataType {
6+
_name,
7+
_date,
8+
_director,
9+
_writers,
10+
_actors,
11+
_labels,
12+
_country,
13+
_language,
14+
_runtime,
15+
_producer,
16+
_earnings,
17+
_rate,
18+
_awards,
19+
_reviews,
20+
_photos,
21+
};
22+
23+
class BaseData {
24+
DataType type;
25+
public:
26+
virtual void setData() = 0;
27+
virtual void* getData() = 0;
28+
virtual void printData (const string &) = 0;
29+
virtual DataType getType() = 0;
30+
};
31+
32+
class BaseObject {
33+
vector<BaseData*> DataSet;
34+
public:
35+
virtual void initDataSet (const vector<DataType>&) = 0; // initialize the data set with the list of data type
36+
virtual vector<BaseData*> getDataSet() = 0;
37+
virtual void printObject (const string &) = 0;
38+
virtual int getDataSize() = 0;
39+
};

Catcher.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include<bits/stdc++.h>
2+
#include<io.h>
3+
#include "Catcher.h"
4+
using namespace std;
5+
6+
Catcher:: Catcher() {
7+
curl = curl_easy_init();
8+
curl_easy_setopt(curl, CURLOPT_USERAGENT, "Firefox Browser"); //set an explorer attributively
9+
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
10+
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
11+
}
12+
13+
void Catcher:: printLog(const string &Log) {
14+
fprintf (stderr, "%s\n", Log.c_str());
15+
}
16+
17+
bool Catcher:: saveFile(const string &url, const string &fileName, const bool &isImage) {
18+
if (access(fileName.c_str(), 0) != -1) { //check whether the file exists
19+
printLog ("File exist\n");
20+
return true;
21+
}
22+
CURLcode res;
23+
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
24+
25+
freopen(fileName.c_str(), isImage? "wb" : "w", stdout);
26+
res = curl_easy_perform(curl);
27+
curl_easy_cleanup(curl);
28+
if (res != CURLE_OK) { //fail to download image
29+
printLog("fail to download image.\n");
30+
system(("rm " + fileName).c_str());
31+
return false;
32+
}
33+
return true;
34+
}
35+
36+
Catcher:: ~Catcher() {
37+
curl_global_cleanup();
38+
}

Catcher.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#pragma once
2+
#include <bits/stdc++.h>
3+
#include "curl/curl.h"
4+
using namespace std;
5+
6+
class Catcher {
7+
CURL *curl;
8+
public:
9+
Catcher();
10+
void printLog(const string &);
11+
bool saveFile(const string &, const string &, const bool & = 0);
12+
~Catcher();
13+
};
14+
15+
//static Catcher catcher;

0 commit comments

Comments
 (0)