function getCData() { //$news = dbMassData("SELECT * FROM news WHERE dateT !='0000-00-00 00:00:00' GROUP BY dateT ORDER BY dateT ASC"); $prices = dbMassData("SELECT * FROM minuteCoin WHERE tDate != '0000-00-00 00:00:00' AND current != 0 AND bid != 0 ORDER BY timestamp DESC LIMIT 240"); $resp = array("prices" => $prices); return $resp; }
function addGetChat($userN, $mes) { dbQuery("INSERT INTO chat (username, message) VALUES ('{$userN}', '{$mes}')"); $chatHistory = dbMassData("SELECT * FROM chat ORDER BY timestamp DESC LIMIT 10"); $resp = array("status" => "success", "reason" => "chat added", "data" => $chatHistory); return $resp; }
function getCData() { $news = dbMassData("SELECT * FROM news WHERE dateT !='0000-00-00 00:00:00' GROUP BY dateT ORDER BY dateT ASC"); $prices = dbMassData("SELECT * FROM minuteCoin WHERE tDate != '0000-00-00 00:00:00' GROUP BY tDate ORDER BY timestamp DESC LIMIT 100"); $resp = array("news" => $news, "prices" => $prices); return $resp; }
function register($name, $email, $password) { //check for user table //if it doesn't exist, create it (first time this script is run) //validation if (!isset($email)) { $response = array("status" => "fail", "resp" => "Please send afRegEmail "); return $response; } if (!isset($name)) { $response = array("status" => "fail", "resp" => "Please send a afRegName "); return $response; } if (!isset($password)) { $response = array("status" => "fail", "resp" => "Please send a afRegPassword "); return $response; } //encrpyt password $password = md5($password); $ipAddress = $_SERVER['REMOTE_ADDR']; //echo('ip='.$ipAddress); $allUsers = dbMassData("SELECT * FROM users WHERE email = '{$email}'"); if ($allUsers == null) { dbQuery("INSERT INTO users (name, email, password, ipAddress) VALUES ('{$name}', '{$email}', '{$password}', '{$ipAddress}')"); $resp = array("status" => "success"); //now login user return $resp; //return $response; } else { $response = array("status" => "fail", "resp" => "emailTaken"); return $response; } }
function loginUser($email, $password) { if (!isset($email)) { $response = array("status" => "fail", "resp" => "Please send afLoginEmail "); return $response; } if (!isset($password)) { $response = array("status" => "fail", "resp" => "Please send a afLoginPassword "); return $response; } //encrpyt password $password = md5($password); $ipAddress = $_SERVER['REMOTE_ADDR']; //echo('ip='.$ipAddress); $userInfo = dbMassData("SELECT * FROM users WHERE email = '{$email}' AND password='******'"); if ($userInfo != null) { session_id(); session_start(); $_SESSION['userId'] = $userInfo[0]['rId']; $_SESSION['uId'] = $userInfo[0]['rId']; $_SESSION['name'] = $userInfo[0]['name']; $_SESSION['email'] = $userInfo[0]['email']; $_SESSION['originalIP'] = $userInfo[0]['ipAddress']; $response = array("status" => "success", "resp" => $_SESSION); return $response; } else { $response = array("status" => "fail", "resp" => "notValidPair"); return $response; } }
function getFeatItems($category = "kitchen") { $results = dbMassData("SELECT * FROM itemsForSale WHERE active = 'true' AND category LIKE '%{$category}%' ORDER BY timeAdded DESC LIMIT 50"); if ($results == NULL) { $resp = array("status" => "failed", "reason" => "no items found for sale in our inventory from that category"); return $resp; } else { return array("status" => "success", "data" => $results, "reason" => "found results"); return $response; } }
function getColItems($userId) { $results = dbMassData("SELECT * FROM myCollection WHERE removed != 'true' AND userId = {$userId} ORDER BY timestamp DESC LIMIT 200"); if ($results == NULL) { $resp = array("status" => "failed", "reason" => "no items found for users' collection..."); return $resp; } else { return array("status" => "success", "data" => $results, "reason" => "found photos in your collection"); return $response; } }
function getUserInfo() { session_start(); if (isset($_SESSION['email'])) { $email = $_SESSION['email']; $userInfo = dbMassData("SELECT * FROM users WHERE email = '{$email}'"); $response = array("status" => "success", "resp" => $_SESSION); return $response; } else { $response = array("status" => "fail", "resp" => "notSignedIn"); return $response; } }
function getSent() { $data = dbMassData("SELECT * FROM news ORDER BY dateT DESC"); for ($i = 0; $i < count($data); $i++) { $info1 = $data[$i]['headline'] . " " . $data[$i]['beginning']; $senti = file_get_contents("http://alina-prod.apigee.net/sentiment?info1=" . urlencode($info1) . "&apikey=npIZYYxsfzE0DOVX92oEPwGTV95wg7X6"); $sentiment = json_decode($senti, true); $score = $sentiment['data']['score']; $cScore = $sentiment['data']['comparative']; $rId = $data[$i]['rId']; dbQuery("UPDATE news SET sentiment = {$score}, comparative= {$cScore} WHERE rId = {$rId} "); echo "UPDATE news SET sentiment = {$score}, comparative= {$cScore} WHERE rId = {$rId} "; echo "<br>"; } return true; }
function loginUser($email, $pass) { $pass = md5($pass); $userAccount = dbMassData("SELECT * FROM settings WHERE email = '{$email}' AND passwd= '{$pass}'"); if ($userAccount == NULL) { $resp = array("status" => "fail", "reason" => "invalid credentials"); return $resp; //password/email not valid } else { $resp = array("status" => "success", "data" => $userAccount[0], "reason" => "invalid credentials"); session_id(); session_start(); $_SESSION['userId'] = $userAccount[0]['userId']; $_SESSION['rId'] = $userAccount[0]['rId']; $_SESSION['email'] = $userAccount[0]['email']; return $resp; } }
function seeIf($whichId) { $resp1 = dbMassData("SELECT * FROM transactions WHERE id = {$whichId} ORDER BY timestamp DESC LIMIT 1"); $theResp = array(); if ($resp1 == null) { $thePrice = dbMassData("SELECT * FROM minuteCoin ORDER BY timestamp DESC LIMIT 1"); //not there $priceOh = floatval($thePrice[0]['ask']) * 1.01; $thePrice = floatval($thePrice[0]['ask']); $thePrice = $thePrice + 0.05; $buyPriceNow = floatval($thePrice[0]['ask']); dbQuery("INSERT INTO transactions (price, sellPrice, active, id, which) VALUES ({$thePrice}, {$priceOh}, 'true', {$whichId}, 'buy' ) "); $theResp = array("active" => "true", "bidWaiting" => $priceOh, "buyPrice" => $thePrice); return $theResp; } else { if ($resp1[0]['active'] == "false") { $thePrice = dbMassData("SELECT * FROM minuteCoin ORDER BY timestamp DESC LIMIT 1"); //not there $priceOh = floatval($thePrice[0]['ask']) * 1.01; $thePrice = floatval($thePrice[0]['ask']); //ten cents higher $buyPriceNow = floatval($thePrice[0]['ask']); //place order for price oh dbQuery("INSERT INTO transactions (price, sellPrice, active, id, which) VALUES ({$thePrice}, {$priceOh}, 'true', {$whichId}, 'buy' ) "); //active is set to true but we return false so node triggers the buy order, and then the sell $theResp = array("active" => "false", "bidWaiting" => $priceOh, "buyPrice" => $thePrice); return $theResp; } else { // $thePrice = dbMassData("SELECT * FROM minuteCoin ORDER BY timestamp DESC LIMIT 1"); //set all to false to prevent bullshit if (floatval($thePrice[0]['current']) >= floatval($resp1[0]['sellPrice'])) { //time to trade! dbQuery("UPDATE transactions SET active = 'false', which='sold' WHERE id={$whichId}"); $theResp = array("active" => "false"); } else { dbQuery("UPDATE transactions SET active = 'true' WHERE id = {$whichId}"); $theResp = array("active" => "true", "waitingFor" => floatval($resp1[0]['sellPrice'])); } return $theResp; } } }
function retData($which, $col, $tick, $start, $end) { if (!isset($start)) { $start = '2014-11-06 00:00:00'; } if (!isset($end)) { $end = date('Y-m-d H:i:s'); } if (!isset($tick)) { $tick = 5; } $tick = intval($tick); $resp = dbMassData("SELECT * FROM {$which} WHERE mod(minute(timestamp),{$tick}) = 0 AND timestamp < '{$end}' AND timestamp > '{$start}'"); $resArr = array(); for ($i = 0; $i < count($resp); $i++) { array_push($resArr, $resp[$i][$col]); } return $resArr; }
$link = explode('"', $linkArr[1]); $link = $link[0]; echo '<br>'; echo $link; echo '<br><br>'; $id = $link; $link = 'http://' . $city . '.craigslist.org/reply/' . $link; $contactLink = $link; $contactPage = file_get_contents($link); $linkArr = explode('readonly="readonly" value="', $contactPage); $email = explode('"', $linkArr[1]); $email = $email[0]; echo $email; echo '<br><br>'; $fieldsArr = array('id' => $id, 'email' => $email, 'contactLink' => $contactLink, 'title' => $title, 'info' => $body); $source = "craigslist"; $tableName = 'postings'; $fieldsArr = $fieldsArr; $checkExists = true; $print = true; $checkAdded = false; $updateBool = false; $addNewFields = true; $exists = dbMassData("SELECT * FROM postings WHERE id ='{$id}'"); if ($exists == null) { if (isset($email)) { rollAdd($tableName, $fieldsArr, $checkExists, $print, $checkAdded, $updateBool, $addNewFields); } } } }
<?php include_once '/var/www/html/cloud/models/db/dbLib.php'; include_once '/var/www/html/cloud/models/db/dbShortcuts.php'; include_once '/var/www/html/cloud/models/db/session.php'; extract($_REQUEST); if (isset($userId) && ($fbId == "" || !isset($fbId))) { //$userEdits = dbMassData("SELECT * FROM userEdits WHERE userId = '$userId' ORDER BY timestamp DESC LIMIT 1"); //echo(json_encode($userEdits[0])); } else { if (isset($userId) && isset($fbId)) { $userEdits = dbMassData("SELECT * FROM userEdits WHERE fbId='{$fbId}' ORDER BY timestamp DESC LIMIT 1"); echo json_encode($userEdits[0]); } else { if (!isset($userId) && isset($fbId)) { $userEdits = dbMassData("SELECT * FROM userEdits WHERE fbId='{$fbId}' ORDER BY timestamp DESC LIMIT 1"); echo json_encode($userEdits[0]); } else { return; } } }
function getCData($limit, $tick, $whatBetter) { $limit = intval($limit); //$news = dbMassData("SELECT * FROM news WHERE dateT !='0000-00-00 00:00:00' GROUP BY dateT ORDER BY dateT ASC"); $prices = dbMassData("SELECT * FROM minuteCoin WHERE mod(minute(timestamp),{$tick}) AND tDate != '0000-00-00 00:00:00' ORDER BY timestamp DESC LIMIT 1000"); $prices = array_reverse($prices); $respArr = array("buy" => array(), "dont" => array()); for ($i = 0; $i < count($prices); $i++) { $outOne = $i + $limit; $startPrice = floatval($prices[$i]['ask']); $endPrice = floatval($prices[$outOne]['bid']); if ($endPrice > $startPrice + $startPrice * $whatsBetter) { $thisBlock = array("bidsAfter" => array(), "bidsRateBefore" => array(), "bidsRateAfter" => array(), "bidsBefore" => array(), "asksAfter" => array(), "asksBefore" => array(), "asksRateBefore" => array(), "asksRateAfter" => array(), "pricesAfter" => array(), "pricesBefore" => array(), "pricesRateBefore" => array(), "pricesRateAfter" => array(), "spreadAfter" => array(), "spreadBefore" => array()); $startingPoint = $i; try { for ($j = 0; $j < $limit; $j++) { $thisOne = $startingPoint + $j; $oneBefore = $thisOne - 1; array_push($thisBlock['bidsAfter'], floatval($prices[$thisOne]['bid'])); array_push($thisBlock['asksAfter'], floatval($prices[$thisOne]['ask'])); array_push($thisBlock['pricesAfter'], floatval($prices[$thisOne]['current'])); $bidsRateAfter = sqrt(floatval($prices[$thisOne]['bid']) / floatval($prices[$oneBefore]['bid'])) * 0.5; $asksRateAfter = sqrt(floatval($prices[$thisOne]['ask']) / floatval($prices[$oneBefore]['ask'])) * 0.5; $pricesRateAfter = sqrt(floatval($prices[$thisOne]['current']) / floatval($prices[$oneBefore]['current'])) * 0.5; $spreadAfter = floatval($prices[$thisOne]['bid']) / floatval($prices[$thisOne]['ask']); array_push($thisBlock['bidsRateAfter'], $bidsRateAfter); array_push($thisBlock['asksRateAfter'], $asksRateAfter); array_push($thisBlock['pricesRateAfter'], $pricesRateAfter); array_push($thisBlock['spreadAfter'], $spreadAfter); } //get fifteen before for ($j = $limit; $j > 0; $j--) { $thisOne = $startingPoint - $j; $oneBefore = $thisOne - 1; array_push($thisBlock['bidsBefore'], floatval($prices[$thisOne]['bid'])); array_push($thisBlock['asksBefore'], floatval($prices[$thisOne]['ask'])); array_push($thisBlock['pricesBefore'], floatval($prices[$thisOne]['current'])); $bidsRateBefore = sqrt(floatval($prices[$thisOne]['bid']) / floatval($prices[$oneBefore]['bid'])) * 0.5; $asksRateBefore = sqrt(floatval($prices[$thisOne]['ask']) / floatval($prices[$oneBefore]['ask'])) * 0.5; $pricesRateBefore = sqrt(floatval($prices[$thisOne]['current']) / floatval($prices[$oneBefore]['current'])) * 0.5; $spreadBefore = floatval($prices[$thisOne]['bid']) / floatval($prices[$thisOne]['ask']); array_push($thisBlock['bidsRateBefore'], $bidsRateBefore); array_push($thisBlock['asksRateBefore'], $asksRateBefore); array_push($thisBlock['pricesRateBefore'], $pricesRateBefore); array_push($thisBlock['spreadBefore'], $spreadBefore); } } catch (Exception $e) { } array_push($respArr['buy'], $thisBlock); } else { $thisBlock = array("bidsAfter" => array(), "bidsRateBefore" => array(), "bidsRateAfter" => array(), "bidsBefore" => array(), "asksAfter" => array(), "asksBefore" => array(), "asksRateBefore" => array(), "asksRateAfter" => array(), "pricesAfter" => array(), "pricesBefore" => array(), "pricesRateBefore" => array(), "pricesRateAfter" => array(), "spreadBefore" => array(), "spreadAfter" => array()); $startingPoint = $i; try { for ($j = 0; $j < $limit; $j++) { $thisOne = $startingPoint + $j; $oneBefore = $thisOne - 1; array_push($thisBlock['bidsAfter'], floatval($prices[$thisOne]['bid'])); array_push($thisBlock['asksAfter'], floatval($prices[$thisOne]['ask'])); array_push($thisBlock['pricesAfter'], floatval($prices[$thisOne]['current'])); $bidsRateAfter = sqrt(floatval($prices[$thisOne]['bid']) / floatval($prices[$oneBefore]['bid'])) * 0.5; $asksRateAfter = sqrt(floatval($prices[$thisOne]['ask']) / floatval($prices[$oneBefore]['ask'])) * 0.5; $pricesRateAfter = sqrt(floatval($prices[$thisOne]['current']) / floatval($prices[$oneBefore]['current'])) * 0.5; $spreadAfter = floatval($prices[$thisOne]['bid']) / floatval($prices[$thisOne]['ask']); array_push($thisBlock['bidsRateAfter'], $bidsRateAfter); array_push($thisBlock['asksRateAfter'], $asksRateAfter); array_push($thisBlock['pricesRateAfter'], $pricesRateAfter); array_push($thisBlock['spreadAfter'], $spreadAfter); } //get fifteen before for ($j = $limit; $j > 0; $j--) { $thisOne = $startingPoint - $j; $oneBefore = $thisOne - 1; array_push($thisBlock['bidsBefore'], floatval($prices[$thisOne]['bid'])); array_push($thisBlock['asksBefore'], floatval($prices[$thisOne]['ask'])); array_push($thisBlock['pricesBefore'], floatval($prices[$thisOne]['current'])); $bidsRateBefore = sqrt(floatval($prices[$thisOne]['bid']) / floatval($prices[$oneBefore]['bid'])) * 0.5; $asksRateBefore = sqrt(floatval($prices[$thisOne]['ask']) / floatval($prices[$oneBefore]['ask'])) * 0.5; $pricesRateBefore = sqrt(floatval($prices[$thisOne]['current']) / floatval($prices[$oneBefore]['current'])) * 0.5; $spreadBefore = floatval($prices[$thisOne]['bid']) / floatval($prices[$thisOne]['ask']); array_push($thisBlock['bidsRateBefore'], $bidsRateBefore); array_push($thisBlock['asksRateBefore'], $asksRateBefore); array_push($thisBlock['pricesRateBefore'], $pricesRateBefore); array_push($thisBlock['spreadBefore'], $spreadBefore); } } catch (Exception $e) { } array_push($respArr['dont'], $thisBlock); } } $resp = array("blocks" => $respArr); return $resp; }
function renderConvo($sent) { $userId = $_SESSION['userId']; $correctTerms = array("wrong", "incorrect", "no,", "not correct", "next", "->", "-->", "another"); $lastConversation = dbMassData("SELECT * FROM conversations WHERE userId = '{$userId}' ORDER BY timestamp DESC LIMIT 2"); if ($lastConversation == null) { } //echo("Last is ".$lastConversation[1]['type'] ); if ($lastConversation[1]['type'] == "question") { $words = explode(" ", $sent); $firstWord = $words[0]; for ($i = 0; $i < count($correctTerms); $i++) { if (strpos($sent, $correctTerms[$i]) !== false) { // containts the terms we're looking for in order to know that we need to render as question but get next result; $resp = renderAnswer($lastConversation[1]['statement'], 1); return $resp; } } } $resu = json_decode(file_get_contents('http://chat-maybe588.rhcloud.com/chatbot/?msg=' . urlencode($sent) . '&user=1&room=1'), true); if (isset($resu['status'])) { return array("status" => "fail"); } else { if (strpos($resu['content'], "what") !== false && strpos($resu['content'], "called") !== false || strpos($resu['content'], "what") !== false && strpos($resu['content'], "name") !== false) { return renderConvo("mike"); } return array("status" => "success", "answer" => $resu['content'], "bot" => $resu['which'], "answerType" => "convo", "original" => "convo"); } }
<?php include_once '/var/www/html/cloud/models/db/dbLib.php'; include_once '/var/www/html/cloud/models/db/dbShortcuts.php'; include_once '/var/www/html/cloud/models/db/session.php'; extract($_REQUEST); if (isset($liId)) { //$userEdits = dbMassData("SELECT * FROM userEdits WHERE userId = '$userId' ORDER BY timestamp DESC LIMIT 1"); //echo(json_encode($userEdits[0])); $userEdits = dbMassData("SELECT * FROM userEdits WHERE linkedInId='{$liId}' ORDER BY timestamp DESC LIMIT 1"); echo json_encode($userEdits[0]); } else { return; }