-
Notifications
You must be signed in to change notification settings - Fork 0
/
market.php
89 lines (77 loc) · 2.38 KB
/
market.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
<?php
set_time_limit(2 * 60);
/**
*
* Fetch drivers market into PHP array market/Y-m-d.php
*/
use GuzzleHttp\Client;
use GuzzleHttp\Cookie\SessionCookieJar;
use GuzzleHttp\RequestOptions;
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/config.php';
require_once __DIR__ . '/src/functions.php';
$cli = isCli();
$title = 'Download Market Database';
session_start();
$jar = new SessionCookieJar('gpro', true);
$client = new Client(['base_uri' => GPRO_URL, 'cookies' => $jar]);
if ($cli) {
echo 'Logging in gpro.net...'.PHP_EOL;
}
$response = $client->post('Login.asp?Redirect=Help.asp', [
'form_params' => [
'textLogin' => USERNAME,
'textPassword' => PASSWORD,
'token' => HASH,
'Logon' => 'Login',
'LogonFake' => 'Login',
],
'allow_redirects' => true,
RequestOptions::HEADERS => [
'User-Agent' => GPRO_UA
],
]);
if ($cli) {
echo 'Downloading & extracting Drivers market file...'.PHP_EOL;
}
$json = gzdecode(
$client->get(
'GetMarketFile.asp?market=drivers&type=json',
[
RequestOptions::HEADERS => [
'User-Agent' => GPRO_UA
],
]
)->getBody()
);
if ($cli) {
echo 'Downloading & extracting Tech Directors market file...'.PHP_EOL;
}
$jsonTechDirectors = gzdecode(
$client->get(
'GetMarketFile.asp?market=tds&type=json',
[
RequestOptions::HEADERS => [
'User-Agent' => GPRO_UA
],
]
)->getBody()
);
$marketFolder = 'market' . DIRECTORY_SEPARATOR;
$marketFile = $marketFolder . date('Y-m-d') . '.php';
$marketFileTechDirectors = $marketFolder . 'TD-' . date('Y-m-d') . '.php';
file_put_contents($marketFile, "<?php".PHP_EOL."return ".var_export(json_decode($json, true), true).";");
file_put_contents(
$marketFileTechDirectors,
"<?php".PHP_EOL."return ".var_export(json_decode($jsonTechDirectors, true), true).";"
);
$message = "<p>Drivers market file has been stored under <b>$marketFile</b></p>".PHP_EOL;
$message .= "<p>Tech Directors market file has been stored under <b>$marketFileTechDirectors</b></p>".PHP_EOL;
if ($cli) {
$message = strip_tags($message);
file_put_contents('market.log', date('d.m.Y H:i').PHP_EOL.$message);
echo $message;
exit;
}
$content = renderView('postrace', compact('message'));
echo renderView('layout', compact('content', 'title'));