File manager - Edit - /home/cipherteam/htdocs/cipherteam.in/API/Finance/losers.php
Back
<?php include_once("Market.php"); if(isMarketOpen()) { include_once("simple_html_dom.php"); include_once("ConnectToMarketData.php"); try { $html = file_get_html("https://money.rediff.com/losers/nse"); $html1 = file_get_html("https://money.rediff.com/losers/bse"); $tbody = $html->find('tbody',0); if(!$tbody) { throw new Exception('Exception message'); } $losers["LOSERS"] = array(); $tmp = $tbody->find('tr',0); if(!$tmp) { throw new Exception('Exception message'); } $first = true; foreach($tbody->find('tr') as $tr) { if($first) { $sql = "DELETE FROM `top_loser`"; $con->query($sql); $first = false; } $sys = '.NS'; $name = trim($tr->find('td', 0)->plaintext); $name = str_replace('\t', '', $name); $prePrice = $tr->find('td', 1)->plaintext; $price = $tr->find('td', 2)->plaintext; $price = trim($price); $changeper = $tr->find('td', 3)->plaintext; $change = ($prePrice*substr($changeper, 1))/100; $change = round($change, 2); $changeper = trim($changeper).'%'; $changeper = str_replace(' ', '', $changeper); $loser = array( 'SYMBOL'=>$sys, 'NAME'=>$name, 'PRICE'=>$price, 'CHANGE'=>'-'.$change, 'CHANGEPER'=>$changeper ); $sql = "INSERT INTO `top_loser` (`symbol`, `name`, `price`, `changeprice`, `changeper`) VALUES ('$sys', '$name', '$price', '$change', '$changeper');"; $con->query($sql); array_push($losers["LOSERS"],$loser); } //BSE $tbody = $html1->find('tbody',0); if(!$tbody) { throw new Exception('Exception message'); } $tmp = $tbody->find('tr',0); if(!$tmp) { throw new Exception('Exception message'); } foreach($tbody->find('tr') as $tr) { $sys = '.BO'; $name = trim($tr->find('td', 0)->plaintext); $name = str_replace('\t', '', $name); $prePrice = $tr->find('td', 2)->plaintext; $price = $tr->find('td', 3)->plaintext; $price = trim($price); $changeper = $tr->find('td', 4)->plaintext; $change = ($prePrice*substr($changeper, 1))/100; $change = round($change, 2); $change = $change.''; $changeper = trim($changeper).'%'; $changeper = str_replace(' ', '', $changeper); $loser = array( 'SYMBOL'=>$sys, 'NAME'=>$name, 'PRICE'=>$price, 'CHANGE'=>$change, 'CHANGEPER'=>$changeper ); $sql = "INSERT INTO `top_loser` (`symbol`, `name`, `price`, `changeprice`, `changeper`) VALUES ('$sys', '$name', '$price', '$change', '$changeper');"; $con->query($sql); array_push($losers["LOSERS"],$loser); } $losers["success"] = 1; echo json_encode($losers); } catch(Exception $e) { $sql = "SELECT `symbol` AS 'SYMBOL',`name` AS 'NAME',`price` AS 'PRICE',`changeprice` AS 'CHANGE',`changeper` AS 'CHANGEPER' FROM `top_loser`"; $rows = $con->query($sql); $losers["LOSERS"] = array(); if($rows->num_rows > 0) { while($row = $rows->fetch_assoc()) { $div = array(); $div = $row; array_push($losers["LOSERS"],$div); } $losers["success"] = 1; echo json_encode($losers); } } } else { include_once("ConnectToMarketData.php"); $sql = "SELECT `symbol` AS 'SYMBOL',`name` AS 'NAME',`price` AS 'PRICE',`changeprice` AS 'CHANGE',`changeper` AS 'CHANGEPER' FROM `top_loser`"; $rows = $con->query($sql); $losers["LOSERS"] = array(); if($rows->num_rows > 0) { while($row = $rows->fetch_assoc()) { $div = array(); $div = $row; array_push($losers["LOSERS"],$div); } $losers["success"] = 1; echo json_encode($losers); } } ?>
| ver. 1.4 |
Github
|
.
| PHP 8.2.9 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings