-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagg_save_all.php
95 lines (95 loc) · 2.83 KB
/
agg_save_all.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
<?php
ini_set('display_errors', '1');
error_reporting(E_ALL);
require_once("/etc/auth.php");
for($i=0;$i<30000;$i+=100)
{
echo "Iteration: $i.";
$IDs = (range($i,$i+100));
foreach ($IDs as $k=>$ID){
$IDs[$k]=str_pad($ID, 6, "0", STR_PAD_LEFT);
}
$BASEURL = "http://127.0.0.1:9090/api/Items2/GetSalesDataForAnalysis";
$REQUESTS = [];
$mh = curl_multi_init();
foreach($IDs as $ID){
$req = curl_init();
curl_setopt($req, CURLOPT_URL, "$BASEURL?PLU_CODE=$ID");
curl_setopt($req, CURLOPT_RETURNTRANSFER, true);
curl_setopt($req, CURLOPT_HTTPHEADER, ["Authorization: Basic $ENCODED_AUTH"]);
curl_multi_add_handle($mh, $req);
array_push($REQUESTS, $req);
unset($req);
}
do{
$status = curl_multi_exec($mh, $active);
if ($active){
curl_multi_select($mh);
}
}
while ($active && $status == CURLM_OK);
$RESPONSES=[];
foreach($REQUESTS as $req)
{
$res=curl_multi_getcontent($req);
//var_dump($res);
array_push($RESPONSES, json_decode($res));
};
var_dump($RESPONSES);
$BASEURL2 = "http://127.0.0.1:9090/api/Items2";
$REQUESTS2 = [];
$mh2 = curl_multi_init();
foreach($IDs as $ID){
$req2 = curl_init();
$ID_padded = str_pad($ID, 6, "0", STR_PAD_LEFT);
curl_setopt($req2, CURLOPT_URL, "$BASEURL2/$ID_padded");
curl_setopt($req2, CURLOPT_RETURNTRANSFER, true);
curl_setopt($req2, CURLOPT_HTTPHEADER, ["Authorization: Basic $ENCODED_AUTH"]);
curl_multi_add_handle($mh2, $req2);
array_push($REQUESTS2, $req2);
unset($req2);
}
do{
$status2 = curl_multi_exec($mh2, $active2);
if ($active2){
curl_multi_select($mh2);
}
}
while ($active2 && $status2 == CURLM_OK);
$RESPONSES2=[];
foreach($REQUESTS2 as $req2)
{
$res2=curl_multi_getcontent($req2);
//var_dump($res);
array_push($RESPONSES2, json_decode($res2));
};
var_dump($RESPONSES2);
$dbh = new PDO("sqlite:/saru/www-data/db.sqlite3");
$t = $dbh->beginTransaction();
$stmt_sql = $dbh->prepare("insert into productsattime ('ID', 'SIH', 's15', 's30', 's60') values (?, ?, ?, ?, ?)");
$stmt_sql_misc = $dbh->prepare("insert into productsattime_misc ('ID', 'DESC', 'BARCODE', 'SELL') values (?, ?, ?, ?)");
foreach($RESPONSES as $RESPONSE){
if ($RESPONSE==null) continue;
$stmt = $stmt_sql->execute([$RESPONSE->CODE, $RESPONSE->SIH, $RESPONSE->S_D15, $RESPONSE->S_D30, $RESPONSE->S_D60]);
}
foreach($RESPONSES2 as $RESPONSE2){
if ($RESPONSE2==null) continue;
echo "BARCODE: ";
var_dump($RESPONSE2);
if(property_exists($RESPONSE2, "BARCODES")){
if (count($RESPONSE2->BARCODES)==0){
$stmt2 = $stmt_sql_misc->execute([$RESPONSE2->PLU_CODE, $RESPONSE2->PLU_DESC, null, $RESPONSE2->PLU_SELL]);
}
else{
foreach($RESPONSE2->BARCODES as $BARCODE){
$stmt2 = $stmt_sql_misc->execute([$RESPONSE2->PLU_CODE, $RESPONSE2->PLU_DESC, $BARCODE, $RESPONSE2->PLU_SELL]);
}
}
} else {
echo "NO KEY: BARCODE\n";
}
}
$dbh->commit();
sleep(5);
}
?>