-
Notifications
You must be signed in to change notification settings - Fork 1
/
accountprocessor.cpp
100 lines (82 loc) · 3.63 KB
/
accountprocessor.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
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
#include "accountprocessor.h"
#include <QString>
QDataStream & operator<<(QDataStream &ds, const AccountProcessor &in)
{
ds << in.a_name << in.a_email << in.a_fullname << in.a_country;
ds << in.a_studyplace << in.a_birthday << in.a_info;
ds << in.num_submits << in.num_accepts;
ds << in.problems << in.lastDay << in.lastWeek << in.lastMonth;
ds << in.err;
return ds;
}
QDataStream & operator>>(QDataStream &ds, AccountProcessor &in)
{
ds >> in.a_name >> in.a_email >> in.a_fullname >> in.a_country;
ds >> in.a_studyplace >> in.a_birthday >> in.a_info;
ds >> in.num_submits >> in.num_accepts;
ds >> in.problems >> in.lastDay >> in.lastWeek >> in.lastMonth;
ds >> in.err;
return ds;
}
AccountProcessor::AccountProcessor(const QString &src)
{
err = false;
int st = src.indexOf("<td>Name</td><td>: ")+QString("<td>Name</td><td>: ").size();
int en = src.indexOf("</td></tr><tr><td colspan=2><HR></td></tr><tr><td>E-Mail");
if (st == -1 || en == -1)
err = true;
else
{
if (src.mid(st, 2) == "<f")
{
st = src.indexOf(">", st)+1;
en = src.indexOf("</font>", st);
}
a_name = src.mid(st, en-st);
}
if (!err)
{
st = src.indexOf("E-Mail</td><td>: ")+QString("E-Mail</td><td>: ").size();
en = src.indexOf("</td></tr><tr><td colspan=2><HR></td></tr><tr><td>Country");
a_email = src.mid(st, en-st);
a_email.replace("[at]", "@");
a_email.replace("[dot]", ".");
st = src.indexOf("Country</td><td>: ")+QString("Country</td><td>: ").size();
en = src.indexOf("</td></tr><tr><td colspan=2><HR></td></tr><tr><td>Full");
a_country = src.mid(st, en-st);
st = src.indexOf("Full Name</td><td>: ")+QString("Full Name</td><td>: ").size();
en = src.indexOf("</td></tr><tr><td colspan=2><HR></td></tr><tr><td>Study");
a_fullname = src.mid(st, en-st);
st = src.indexOf("Study Place</td><td>: ")+QString("Study Place</td><td>: ").size();
en = src.indexOf("</td></tr><tr><td colspan=2><HR></td></tr><tr><td>Birth");
a_studyplace = src.mid(st, en-st);
st = src.indexOf("Birthday</td><td>: ")+QString("Birthday</td><td>: ").size();
en = src.indexOf("</td></tr><tr><td colspan=2><HR></td></tr><tr><td>Infor");
a_birthday = src.mid(st, en-st);
st = src.indexOf("Information</td><td>: ")+QString("Information</td><td>: ").size();
en = src.indexOf("</td></tr><tr><td colspan=2><HR></td></tr><tr><td>Stat");
a_info = src.mid(st, en-st);
st = src.indexOf("Submitted: ")+QString("Submitted: ").size();
en = src.indexOf("; Accepted:");
num_submits = src.mid(st, en-st).toInt();
st = src.indexOf("Accepted: ")+QString("Accepted: ").size();
en = src.indexOf("<br> [<a href='status.php");
num_accepts = src.mid(st, en-st).toInt();
st = src.indexOf("Accepted</td><td>: ")+QString("Accepted</td><td>: ").size();
en = src.indexOf("</td></tr><tr><td></td><td>");
int next = src.indexOf(" ", st);
while (next < en && next != -1)
{
int cur = src.mid(next-3, 3).toInt();
problems.insert(cur);
QString color = src.mid(next-10, 6);
if (color == "CC0000")
lastDay.insert(cur);
else if (color == "008800")
lastWeek.insert(cur);
else if (color == "0000AA")
lastMonth.insert(cur);
next = src.indexOf(" ", next+1);
}
}
}