This repository has been archived by the owner on Aug 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
QrsctlGet.cpp
74 lines (64 loc) · 1.7 KB
/
QrsctlGet.cpp
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
//==============================================================
// 作者:huihut
// 邮箱:huihut@outlook.com
// 时间:2018-11-08 14:28:00
// 说明:匹配 HTML 的七牛云存储的文件名,并使用 qrsctl 下载文件
//==============================================================
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <regex>
using namespace std;
int main()
{
// 存储空间名【需要修改为你的存储空间名】
string bucket = "temp";
// 打开 html 文件
ifstream fhtml;
fhtml.open("html.html");
// 统计下载的文件对象数
int num = 0;
if (fhtml)
{
// tbody 里面符合 reg 的奇数为文件对象,偶数是文件类型,因此只取奇数匹配项
bool isObj = true;
std::stringstream buffer;
buffer << fhtml.rdbuf();
std::string contents(buffer.str());
std::smatch match;
std::regex reg("\\b(edit-word ng-binding\">)([^<]*)");
while (std::regex_search(contents, match, reg)) {
if (isObj)
{
// 匹配到的文件对象
string objfile = match.format("$2");
cout << "Matched " + objfile << endl;
// 合成下载命令
string command = "qrsctl.exe get " + bucket + " " + objfile + " ./" + objfile;
// 下载文件
cout << "Download " + objfile + "..." << endl;
system(command.c_str());
// 文件个数加一
num++;
// 下一个非文件对象
isObj = false;
}
else
{
// 下一个是文件对象
isObj = true;
}
contents = match.suffix().str();
}
}
else
{
cerr << "Failed to read html file!" << endl;
system("pause");
return -1;
}
cout << "Downloaded " + to_string(num) + " files." << endl;
system("pause");
return 0;
}