forked from Akdeniz/google-play-crawler
-
Notifications
You must be signed in to change notification settings - Fork 2
/
info.php
executable file
·175 lines (167 loc) · 4.67 KB
/
info.php
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
<?php
if ($argc != 2) {
echo 'Usage: ' . __FILE__ . ' conf_file' . PHP_EOL;
echo 'Eg: php info.php ~/Desktop/crawler.conf' . PHP_EOL;
return;
}
/**
* 根据线上的数据下载gp上对应的包的信息
*
* @param $conf 配置文件
* @param $source 源文件
* @param $destination 目标文件
*/
function download_gp($conf, $source, $destination)
{
$handler = fopen($source, "rb");
while (!feof($handler)) {
$line = trim(fgets($handler));
if (empty($line)) {
continue;
}
list($pkg, $vcode, $sha1) = explode(" | ", $line);
$data = `java -jar ./info.jar -f $conf download 21 $pkg`;
file_put_contents($destination, $data . PHP_EOL, FILE_APPEND | LOCK_EX);
sleep(3);
}
fclose($handler);
}
/**
* 根据gp文件, 返回list
*
* @param $file
* @return array
*/
function gp_list($file)
{
$handler = fopen($file, "rb");
$list = [];
while (!feof($handler)) {
$line = trim(fgets($handler));
list($pkg, $vcode, $vname) = explode(",", $line);
$app = [];
$app['pkg'] = $pkg;
$app['vcode'] = $vcode;
$app['vname'] = $vname;
$list[] = $app;
}
return $list;
}
/**
* 根据线上文件返回list
*
* @param $file
* @return array
*/
function online_list($file)
{
$handler = fopen($file, "rb");
$list = [];
while (!feof($handler)) {
$line = trim(fgets($handler));
list($pkg, $vcode, $sha1) = explode(" | ", $line);
$app = [];
$app['pkg'] = $pkg;
$app['vcode'] = $vcode;
$app['sha1'] = $sha1;
$list[] = $app;
}
return $list;
}
/**
* 根据apkpure的文件返回list
*
* @param $file
* @return array
*/
function apkpure_list($file)
{
$handler = fopen($file, "rb");
$list = [];
while (!feof($handler)) {
$line = trim(fgets($handler));
if (empty($line))
continue;
$line = json_decode($line, true);
$app = [];
$app['pkg'] = $line['package_name'];
$app['vcode'] = $line['version_code'];
$app['vname'] = $line['version_name'];
$list[] = $app;
}
return $list;
}
/**
* 比较gp与线上的不同数据
*
* @param $gp_file
* @param $online_file
* * @param $diff_file
*/
function cmp_gp_online($gp_file, $online_file, $diff_file)
{
$gp_list = gp_list($gp_file);
$online_list = online_list($online_file);
$total_apk_num = 0;
$diff_apk_num = 0;
foreach ($gp_list as $gp) {
$pkg = $gp['pkg'];
$total_apk_num++;
foreach ($online_list as $online) {
if ($pkg == $online['pkg']) {
if ($gp['vcode'] != $online['vcode']) {
$diff_apk_num++;
$diff = [];
$diff['pkg'] = $pkg;
$diff['gp'] = $gp;
$diff['online'] = $online;
file_put_contents($diff_file, json_encode($diff) . PHP_EOL, FILE_APPEND | LOCK_EX);
}
break;
}
}
}
$data = 'Total app num: ' . $total_apk_num . ', diff apk num : ' . $diff_apk_num . PHP_EOL;
file_put_contents($diff_file, $data, FILE_APPEND | LOCK_EX);
}
/**
* 比较gp与apkpure的不同数据
*
* @param $gp_file
* @param $apkpure_file
* * @param $diff_file
*/
function cmp_gp_apkpure($gp_file, $apkpure_file, $diff_file)
{
$gp_list = gp_list($gp_file);
$apkpure_list = apkpure_list($apkpure_file);
$total_apk_num = 0;
$diff_apk_num = 0;
foreach ($gp_list as $gp) {
$pkg = $gp['pkg'];
$total_apk_num++;
foreach ($apkpure_list as $apkpure) {
if ($pkg == $apkpure['pkg']) {
if ($gp['vcode'] != $apkpure['vcode']) {
$diff_apk_num++;
$diff = [];
$diff['pkg'] = $pkg;
$diff['gp'] = $gp;
$diff['apkpure'] = $apkpure;
file_put_contents($diff_file, json_encode($diff) . PHP_EOL, FILE_APPEND | LOCK_EX);
}
break;
}
}
}
$data = 'Total app num: ' . $total_apk_num . ', diff apk num : ' . $diff_apk_num . PHP_EOL;
file_put_contents($diff_file, $data, FILE_APPEND | LOCK_EX);
}
$conf = $argv[1];
$base_path = dirname(__FILE__);
// 下载gp上的包的信息
//download_gp($conf, $base_path . '/pname.log', $base_path . '/gp.log');
// 比较gp与线上的数据
cmp_gp_online($base_path . '/gp.log', $base_path . '/pname.log', $base_path . '/diff.gp.online.log');
// 比较gp与apkpure的数据
cmp_gp_apkpure($base_path . '/gp.log', $base_path . '/pname.diff.log.request', $base_path . '/diff.gp.apkpure.log');