init
This commit is contained in:
commit
6281abdc5e
44
add_tweet.php
Normal file
44
add_tweet.php
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
include('connection.php');
|
||||
include('coinmarketcap.php');
|
||||
|
||||
$conn = OpenCon();
|
||||
|
||||
$tweetId = $_GET['tweet_id'];
|
||||
$authorId = $_GET['author_id'];
|
||||
$createdAt = $_GET['created_at'];
|
||||
|
||||
$text = $_GET['text'];
|
||||
$tokenCode= $_GET['token_code'];
|
||||
$tokenName=$_GET['token_name'];
|
||||
|
||||
$namecheckSql = "SELECT id FROM Tweets WHERE id=$tweetId";
|
||||
$namecheckQuery = mysqli_query($conn, $namecheckSql);
|
||||
|
||||
if(mysqli_num_rows($namecheckQuery) > 0){
|
||||
|
||||
|
||||
die("5");
|
||||
//die("This post already exists");
|
||||
}
|
||||
$tokenPrice = GetTokenPrice(str_replace(" ", "",$tokenCode));
|
||||
// die("Price : $tokenPrice.$tokenCode");
|
||||
$insertQuery = "INSERT INTO Tweets (id,created_at,author,text,tokenCode, tokenName, price_at_creation) VALUES($tweetId,STR_TO_DATE('$createdAt', '%m/%d/%Y %r'), $authorId, '$text','$tokenCode','$tokenName', $tokenPrice)";
|
||||
//die($insertQuery);
|
||||
if(mysqli_query($conn, $insertQuery)){
|
||||
echo "1";
|
||||
}else{
|
||||
echo "-1";
|
||||
}
|
||||
|
||||
if($tokenCode != "unknown"){
|
||||
$tokenCheckSql = "SELECT long_name FROM Tokens WHERE code='$tokenCode'";
|
||||
$tokenCheckQuery = mysqli_query($conn, $tokenCheckSql);
|
||||
|
||||
if(mysqli_num_rows($tokenCheckQuery) <= 0){
|
||||
//add new token
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
19
add_twitter_tag.php
Normal file
19
add_twitter_tag.php
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
include('connection.php');
|
||||
|
||||
$conn = OpenCon();
|
||||
|
||||
$userTag = $_GET['userTag'];
|
||||
$userId=$_GET['userId'];
|
||||
|
||||
|
||||
$insertSql = "INSERT INTO TwitterTags (tag,id) VALUES('$userTag', '$userId')";
|
||||
|
||||
if(mysqli_query($conn,$insertSql)){
|
||||
echo "0";
|
||||
}else{
|
||||
echo "-1";
|
||||
}
|
||||
|
||||
?>
|
||||
86
coinmarketcap.php
Normal file
86
coinmarketcap.php
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
function GetTokenPrice($tokenSymbol) {
|
||||
// Dexscreener Search API URL
|
||||
$searchApiUrl = "https://api.dexscreener.com/latest/dex/search?q=" . urlencode($tokenSymbol);
|
||||
// echo $searchApiUrl;
|
||||
// Initialize cURL session for the search API
|
||||
$ch = curl_init();
|
||||
|
||||
// Set the URL and other options for the cURL session
|
||||
curl_setopt($ch, CURLOPT_URL, $searchApiUrl);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
// Execute the cURL session and store the result
|
||||
$searchResponse = curl_exec($ch);
|
||||
|
||||
// Check for errors in cURL execution
|
||||
if ($searchResponse === false) {
|
||||
echo 'cURL Error: ' . curl_error($ch);
|
||||
return null;
|
||||
}
|
||||
|
||||
// Decode the JSON search response
|
||||
$searchData = json_decode($searchResponse, true);
|
||||
|
||||
$pairs = $searchData['pairs'];
|
||||
$highestPair = $pairs[0];
|
||||
foreach($pairs as $pair){
|
||||
$vol = $pair["volume"]["h24"];
|
||||
$pairSymbolLow = strtolower($pair["baseToken"]["symbol"]);
|
||||
$tokenSymbolLow = strtolower($tokenSymbol);
|
||||
if($vol > $highestPair["volume"]["h24"] &&($pairSymbolLow == $tokenSymbolLow || $pairSymbolLow == "$".$tokenSymbolLow)){
|
||||
// echo "New High" . $pair["baseToken"]["symbol"];
|
||||
$highestPair =$pair;
|
||||
}
|
||||
}
|
||||
echo json_encode($highestPair);
|
||||
return $highestPair["priceUsd"];
|
||||
}
|
||||
|
||||
function sGetTokenPrice($tokenSymbol){
|
||||
$apiKey = '8faf016d-9cbd-40b3-889d-a45354621601';
|
||||
|
||||
// Replace with the token symbol you want to fetch (e.g., BTC, ETH, ADA)
|
||||
|
||||
// CoinMarketCap API endpoint
|
||||
$endpoint = 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest';
|
||||
|
||||
// Parameters for the API request
|
||||
$params = [
|
||||
'symbol' => $tokenSymbol,
|
||||
'convert' => 'USD'
|
||||
];
|
||||
|
||||
// Initialize cURL session
|
||||
$ch = curl_init();
|
||||
|
||||
// Set cURL options
|
||||
curl_setopt($ch, CURLOPT_URL, $endpoint . '?' . http_build_query($params));
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
'X-CMC_PRO_API_KEY: ' . $apiKey,
|
||||
'Accept: application/json'
|
||||
]);
|
||||
|
||||
// Execute cURL session
|
||||
$response = curl_exec($ch);
|
||||
|
||||
// Check for cURL errors
|
||||
if(curl_errno($ch)) {
|
||||
echo 'Error:' . curl_error($ch);
|
||||
}
|
||||
|
||||
// Close cURL session
|
||||
curl_close($ch);
|
||||
|
||||
// Decode JSON response
|
||||
$data = json_decode($response, true);
|
||||
|
||||
// Check if data was retrieved successfully
|
||||
if(isset($data['data'][$tokenSymbol]['quote']['USD']['price'])) {
|
||||
$priceUSD = $data['data'][$tokenSymbol]['quote']['USD']['price'];
|
||||
return $priceUSD;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
17
complete_request.php
Normal file
17
complete_request.php
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
include('connection.php');
|
||||
|
||||
$conn = OpenCon();
|
||||
|
||||
$id = $_GET['id'];
|
||||
$remarks = $_GET['remarks'];
|
||||
|
||||
$updateSql = "UPDATE Requests SET status = 1, remarks = '$remarks' WHERE id=$id";
|
||||
if(mysqli_query($conn, $updateSql)){
|
||||
echo "0";
|
||||
}else{
|
||||
echo "-1";
|
||||
}
|
||||
|
||||
?>
|
||||
19
connection.php
Executable file
19
connection.php
Executable file
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
function OpenCon()
|
||||
{
|
||||
$dbhost = "localhost";
|
||||
$dbuser = "user";
|
||||
$dbpass = "TcSp419@1234567";
|
||||
$db = "CallFi";
|
||||
$conn = new mysqli($dbhost, $dbuser, $dbpass,$db) or die("Connect failed: %s\n". $conn -> error);
|
||||
|
||||
return $conn;
|
||||
}
|
||||
|
||||
function CloseCon($conn)
|
||||
{
|
||||
$conn -> close();
|
||||
}
|
||||
|
||||
?>
|
||||
40
dexscreener.php
Normal file
40
dexscreener.php
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
// Function to get pair address for a token paired with USDC using Dexscreener API
|
||||
function getPairAddress($tokenSymbol) {
|
||||
// Dexscreener Search API URL
|
||||
$searchApiUrl = "https://api.dexscreener.com/latest/dex/search?q=" . urlencode($tokenSymbol);
|
||||
|
||||
// Initialize cURL session for the search API
|
||||
$ch = curl_init();
|
||||
|
||||
// Set the URL and other options for the cURL session
|
||||
curl_setopt($ch, CURLOPT_URL, $searchApiUrl);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
// Execute the cURL session and store the result
|
||||
$searchResponse = curl_exec($ch);
|
||||
|
||||
// Check for errors in cURL execution
|
||||
if ($searchResponse === false) {
|
||||
echo 'cURL Error: ' . curl_error($ch);
|
||||
return null;
|
||||
}
|
||||
|
||||
// Decode the JSON search response
|
||||
$searchData = json_decode($searchResponse, true);
|
||||
|
||||
$pairs = $searchData['pairs'];
|
||||
$highestPair = $pairs[0];
|
||||
foreach($pairs as $pair){
|
||||
$vol = $pair["volume"]["h24"];
|
||||
if($vol > $highestPair["volume"]["h24"]){
|
||||
$highestPair =$pair;
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode($highestPair);
|
||||
|
||||
// Return null if no pair found
|
||||
return null;
|
||||
}
|
||||
?>
|
||||
18
get_approved_users.php
Normal file
18
get_approved_users.php
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
include('connection.php');
|
||||
|
||||
$conn =OpenCon();
|
||||
|
||||
$selectSql = "SELECT * FROM TwitterTags WHERE approved = 1";
|
||||
$selectQuery = mysqli_query($conn, $selectSql);
|
||||
|
||||
$arr = [];
|
||||
while($row = mysqli_fetch_assoc($selectQuery)){
|
||||
array_push($arr, $row['tag']);
|
||||
}
|
||||
|
||||
echo json_encode($arr);
|
||||
|
||||
|
||||
?>
|
||||
10
get_is_joined.php
Normal file
10
get_is_joined.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
include('connection.php');
|
||||
|
||||
$conn = OpenCon();
|
||||
|
||||
$userTag = $_GET['tag'];
|
||||
|
||||
|
||||
?>
|
||||
16
get_leaderboard.php
Normal file
16
get_leaderboard.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
include('connection.php');
|
||||
|
||||
$conn = OpenCon();
|
||||
|
||||
$selectSql = "SELECT * FROM Leaderboard ORDER BY points DESC";
|
||||
$selectQuery = mysqli_query($conn, $selectSql);
|
||||
$arr = [];
|
||||
while($row = mysqli_fetch_assoc($selectQuery)){
|
||||
array_push($arr, $row);
|
||||
}
|
||||
|
||||
echo json_encode($arr);
|
||||
|
||||
?>
|
||||
16
get_requests.php
Normal file
16
get_requests.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
include('connection.php');
|
||||
$conn = OpenCon();
|
||||
|
||||
$selectSql = "SELECT * FROM Requests WHERE status =0";
|
||||
$selectQuery = mysqli_query($conn, $selectSql);
|
||||
|
||||
$arr = [];
|
||||
while($row=mysqli_fetch_assoc($selectQuery)){
|
||||
array_push($arr,$row);
|
||||
}
|
||||
|
||||
echo json_encode($arr);
|
||||
|
||||
?>
|
||||
13
get_token_price.php
Normal file
13
get_token_price.php
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
include('connection.php');
|
||||
$conn = OpenCon();
|
||||
|
||||
$tokenId = $_GET['id'];
|
||||
|
||||
$selectSql = "SELECT price FROM Tokens WHERE symbol='$tokenId'";
|
||||
$selectQuery = mysqli_query($conn, $selectSql);
|
||||
|
||||
echo mysqli_fetch_assoc($selectQuery)["price"];
|
||||
|
||||
?>
|
||||
36
get_tokens.php
Normal file
36
get_tokens.php
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
include('connection.php');
|
||||
include('coinmarketcap.php');
|
||||
|
||||
$conn = OpenCon();
|
||||
|
||||
$selectSql = "SELECT tokenCode,tokenName FROM Tweets";
|
||||
$selectQuery = mysqli_query($conn, $selectSql);
|
||||
|
||||
$output = "";
|
||||
|
||||
while($row=mysqli_fetch_assoc($selectQuery)){
|
||||
$symbol = str_replace(" ","",$row['tokenCode']);
|
||||
$tokenName = str_replace(" ","",$row['tokenName']);
|
||||
|
||||
$price = GetTokenPrice($symbol );
|
||||
$tokenCheckSql = "SELECT * FROM Tokens WHERE symbol='$symbol'";
|
||||
if(mysqli_num_rows(mysqli_query($conn, $tokenCheckSql)) <= 0){
|
||||
$insertSql = "INSERT INTO Tokens (symbol, price) VALUES('$symbol', $price)";
|
||||
if(mysqli_query($conn, $insertSql)){
|
||||
|
||||
}
|
||||
}else{
|
||||
$updateSql = "UPDATE Tokens SET price=$price WHERE symbol='$symbol'";
|
||||
if(mysqli_query($conn, $updateSql)){
|
||||
|
||||
}
|
||||
}
|
||||
$output .= $row['tokenCode'] . ",";
|
||||
}
|
||||
|
||||
|
||||
echo substr($output,0,-1);
|
||||
|
||||
?>
|
||||
17
get_tweets.php
Normal file
17
get_tweets.php
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
include('connection.php');
|
||||
|
||||
$conn = OpenCon();
|
||||
|
||||
$selectSql = "SELECT * FROM Tweets";
|
||||
$selectQuery = mysqli_query($conn, $selectSql);
|
||||
|
||||
$arr = [];
|
||||
while($row = mysqli_fetch_assoc($selectQuery)){
|
||||
array_push($arr, $row);
|
||||
}
|
||||
|
||||
echo json_encode($arr);
|
||||
|
||||
?>
|
||||
13
get_twitter_username.php
Normal file
13
get_twitter_username.php
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
include('connection.php');
|
||||
$conn = OpenCon();
|
||||
|
||||
$userId = $_GET['id'];
|
||||
|
||||
$selectSql = "SELECT tag FROM TwitterTags WHERE id='$userId'";
|
||||
$selectQuery = mysqli_query($conn, $selectSql);
|
||||
|
||||
echo mysqli_fetch_assoc($selectQuery)["tag"];
|
||||
|
||||
?>
|
||||
24
participate.php
Normal file
24
participate.php
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
include('connection.php');
|
||||
|
||||
$conn = OpenCon();
|
||||
|
||||
$userId = $_GET['author_id'];
|
||||
|
||||
|
||||
$namechekSql = "SELECT tag FROM TwitterTags WHERE id = '$userId'";
|
||||
$namecheckQuery = mysqli_query($conn, $namechekSql) or die("invalid user id");
|
||||
|
||||
if(mysqli_num_rows($namecheckQuery) <= 0){
|
||||
die("No users found");
|
||||
}
|
||||
|
||||
$updateSql = "UPDATE Twitter SET approved = 1 WHERE id = '$userId'";
|
||||
if(mysqli_query($conn, $updateSql)){
|
||||
echo "1";
|
||||
}else{
|
||||
echo "0";
|
||||
}
|
||||
|
||||
?>
|
||||
26
register_twitter_user.php
Normal file
26
register_twitter_user.php
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
include('connection.php');
|
||||
|
||||
$conn = OpenCon();
|
||||
|
||||
$userTag = $_GET['tag'];
|
||||
|
||||
|
||||
$namecheckSql = "SELECT * FROM TwitterTags WHERE tag='$userTag'";
|
||||
$namecheckResult = mysqli_query($conn, $namecheckSql);
|
||||
|
||||
if(mysqli_num_rows($namecheckResult) <= 0){
|
||||
//Theres no detected user, add to requests
|
||||
$insertSql = "INSERT INTO Requests (request_type,request_data) VALUES('twitter_id','$userTag')";
|
||||
|
||||
if(mysqli_query($conn, $insertSql)){
|
||||
die("5");
|
||||
}else{
|
||||
die("-1");
|
||||
}
|
||||
}else{
|
||||
echo "0";
|
||||
}
|
||||
|
||||
?>
|
||||
21
set_leaderboard_item.php
Normal file
21
set_leaderboard_item.php
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
include('connection.php');
|
||||
$conn = OpenCon();
|
||||
|
||||
$username = $_GET['username'];
|
||||
$points = $_GET['points'];
|
||||
|
||||
$selectSql = "SELECT points FROM Leaderboard WHERE username='$username'";
|
||||
$selectQuery = mysqli_query($conn, $selectSql);
|
||||
$setQuery = "INSERT INTO Leaderboard (username, points) VALUES('$username', $points)";
|
||||
if(mysqli_num_rows($selectQuery) > 0){
|
||||
//insert
|
||||
$setQuery ="UPDATE Leaderboard SET points=$points WHERE username='$username'";
|
||||
}
|
||||
|
||||
if(mysqli_query($conn, $setQuery)){
|
||||
echo "0";
|
||||
}
|
||||
|
||||
?>
|
||||
21
set_tweet_token.php
Normal file
21
set_tweet_token.php
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
include('connection.php');
|
||||
$conn = OpenCon();
|
||||
|
||||
$id = $_GET['id'];
|
||||
$tokenCode = $_GET['token_code'];
|
||||
$tokenName = $_GET['token_name'];
|
||||
|
||||
|
||||
$namecheckSql = "SELECT text FROM Tweets WHERE id=$id";
|
||||
$namecheckQuery = mysqli_query($conn, $namecheckSql) or die("-1");
|
||||
|
||||
$updateSql = "UPDATE Tweets SET tokenCode='$tokenCode', tokenName='$tokenName' WHERE id=$id";
|
||||
if(mysqli_query($conn, $updateSql)){
|
||||
echo "0";
|
||||
}else{
|
||||
echo "-2";
|
||||
}
|
||||
|
||||
?>
|
||||
11
test.php
Normal file
11
test.php
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
// include('dexscreener.php');
|
||||
|
||||
// echo getPairAddress("COC/WETH");
|
||||
|
||||
include('coinmarketcap.php');
|
||||
|
||||
echo GetTokenPrice("Niggi");
|
||||
|
||||
?>
|
||||
3
twitter_callback.php
Normal file
3
twitter_callback.php
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<?php
|
||||
echo "0";
|
||||
?>
|
||||
Loading…
Reference in New Issue
Block a user