-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwalmartlabs.php
132 lines (101 loc) · 3.95 KB
/
walmartlabs.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Walmart</title>
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="http://getbootstrap.com/examples/jumbotron-narrow/jumbotron-narrow.css">
</head>
<body>
<div class="container">
<div class="header clearfix">
<nav>
<ul class="nav nav-pills pull-right">
<li role="presentation" class="active"><a href="#">Home</a></li>
<li role="presentation"><a href="#">About</a></li>
<li role="presentation"><a href="#">Contact</a></li>
</ul>
</nav>
<h3 class="text-muted">Walmart barcode scanner</h3>
</div>
<?php
error_reporting(0);
$upc = $_GET['upc'];
if(isset($_GET['upc']) AND !empty($_GET['upc'])):
$ixAppId = 'dec0b569';
$ixAppKey = '241287d4f6c4871fc3521e24daf66a17';
$main_data = json_decode(file_get_contents('http://api.walmartlabs.com/v1/items?apiKey=d46szfpwkkbe5nf8e56fx4ne&upc=' . $upc));
$other_data = json_decode(file_get_contents('https://api.nutritionix.com/v1_1/item?upc=' . $upc . '&appId='.$ixAppId.'&appKey='.$ixAppKey));
if (intval($other_data->nf_total_carbohydrate) != 0 AND intval($other_data->nf_sodium) != 0 AND count($main_data->items) ):
$item = $main_data->items[0];
?>
<div class="jumbotron">
<h2><?php echo $item->name ?></h2>
<p class="lead"><?php echo $item->brandName ?></p>
<p class="lead"><?php echo $item->categoryPath ?></p>
<p>
<img src="<?php echo $item->mediumImage ?>" class="center-block product img-responsive img-rounded">
</p>
</div>
<div class="row marketing">
<div class="col-lg-6">
<h4>Diabetes</h4>
<p>Carbohydrate: <?php echo $other_data->nf_total_carbohydrate ?>
<?php
if($other_data->nf_total_carbohydrate <= 15){
echo ' <span style="color:green;font-weight: bold;">Good</span>';
}
elseif($other_data->nf_total_carbohydrate <= 30){
echo ' <span style="color:orange;font-weight: bold;">Borderline</span>';
}
else{
echo ' <span style="color:red;font-weight: bold;">Danger</span>';
}
?>
</p>
</div>
<div class="col-lg-6">
<h4>High blood pressure</h4>
<p>Sodium: <?php echo $other_data->nf_sodium ?>
<?php
if($other_data->nf_sodium <= 200){
echo ' <span style="color:green;font-weight: bold;">Good</span>';
}
else{
echo ' <span style="color:red;font-weight: bold;">Danger</span>';
}
?>
</p>
</div>
</div>
<?php else: ?>
<div class="jumbotron">
<h2>No data to show</h2>
</div>
<?php endif; ?>
<?php else: ?>
<div class="jumbotron">
<h2>No UPC to use</h2>
</div>
<?php endif; ?>
<footer class="footer">
<p>© Company 2014</p>
</footer>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</body>
</html>
<?php
//echo "<pre>";
//print_r($main_data);
//print_R($other_data);
//echo "</pre>";
?>