Bitcoin Forum
May 05, 2024, 05:14:56 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: [WTB] Very small programming project  (Read 1367 times)
Bitsinmyhead (OP)
Sr. Member
****
Offline Offline

Activity: 465
Merit: 254


View Profile
September 04, 2011, 03:04:13 PM
 #1

Have a small thing I need help with.

I need to take the information on this site:
http://bitclockers.com/api.json

I need to make that information into a new website where:
If "activeworkers" is over 500 I want the same information displayed, but  "activeworkers" should be 100
If "activeworkers" is less than 500 I want the same information displayed, but  "activeworkers" should be 1000000

This information needs to be updated every minute.
If anyone can help, please PM.


            ▄▄████▄▄
        ▄▄██████████████▄▄
      ███████████████████████▄▄
      ▀▀█████████████████████████
██▄▄       ▀▀█████████████████████
██████▄▄        ▀█████████████████
███████████▄▄       ▀▀████████████
███████████████▄▄        ▀████████
████████████████████▄▄       ▀▀███
 ▀▀██████████████████████▄▄
     ▀▀██████████████████████▄▄
▄▄        ▀██████████████████████▄
████▄▄        ▀▀██████████████████
█████████▄▄        ▀▀█████████████
█████████████▄▄        ▀▀█████████
██████████████████▄▄        ▀▀████
▀██████████████████████▄▄
  ▀▀████████████████████████
      ▀▀█████████████████▀▀
           ▀▀███████▀▀



.SEMUX
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
  Semux uses 100% original codebase
  Superfast with 30 seconds instant finality
  Tested 5000 tx per block on open network
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
1714929296
Hero Member
*
Offline Offline

Posts: 1714929296

View Profile Personal Message (Offline)

Ignore
1714929296
Reply with quote  #2

1714929296
Report to moderator
1714929296
Hero Member
*
Offline Offline

Posts: 1714929296

View Profile Personal Message (Offline)

Ignore
1714929296
Reply with quote  #2

1714929296
Report to moderator
Be very wary of relying on JavaScript for security on crypto sites. The site can change the JavaScript at any time unless you take unusual precautions, and browsers are not generally known for their airtight security.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714929296
Hero Member
*
Offline Offline

Posts: 1714929296

View Profile Personal Message (Offline)

Ignore
1714929296
Reply with quote  #2

1714929296
Report to moderator
1714929296
Hero Member
*
Offline Offline

Posts: 1714929296

View Profile Personal Message (Offline)

Ignore
1714929296
Reply with quote  #2

1714929296
Report to moderator
1714929296
Hero Member
*
Offline Offline

Posts: 1714929296

View Profile Personal Message (Offline)

Ignore
1714929296
Reply with quote  #2

1714929296
Report to moderator
SmokeAndMirrors
Full Member
***
Offline Offline

Activity: 168
Merit: 100


View Profile
September 04, 2011, 04:32:44 PM
 #2

How much are you paying?

Help Bitcoins by buying clothes, technology, books, etc. through people/stores that accept BTC. This will increase overall value of BTC as well as mitigate unnecessary bank transaction fees.

My address -
1EM9HGg1SEa5Bux1rVEPxGqGSfNTTc9EkC
NothinG
Hero Member
*****
Offline Offline

Activity: 560
Merit: 500



View Profile
September 04, 2011, 04:51:11 PM
 #3

Code:
<?php
function processCurlJsonrequest($URL$fieldString=array()){ //Initiate Curl request and send back the result

$fsC count($fieldString);
$sendString "";
foreach($fieldString as $fsv=>$fsk)
{
++$cfsC;
$sendString .= $fsv ."=";
$sendString .= $fsk;
if($cfsC != $fsC)
$sendString .= "&";
}
$ch curl_init();
curl_setopt($chCURLOPT_URL$URL);
curl_setopt($chCURLOPT_RETURNTRANSFER1);
curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
curl_setopt($chCURLOPT_SSL_VERIFYHOST0);
curl_setopt($chCURLOPT_FOLLOWLOCATIONTRUE);
curl_setopt($chCURLOPT_POSTFIELDS$sendString);
curl_setopt($chCURLOPT_POST1);
$resulta curl_exec ($ch);
if (curl_errno($ch)) {
print curl_error($ch);
} else {
curl_close($ch);
}
return $resulta;
}

$returnCurl processCurlJsonrequest("http://bitclockers.com/api.json");
$return json_decode($returnCurl);
$activeworkers $return->activeworkers;

if(
$activeworkers 500)
echo 
"100";
else
echo 
"1000000";
?>


Donations Smiley 1ox8G5YzLxvo3hwvbtvA4oDzb1GX46big

Sekioh
Full Member
***
Offline Offline

Activity: 181
Merit: 100



View Profile
September 04, 2011, 05:13:22 PM
 #4

Code:
<?php
function processCurlJsonrequest($URL$fieldString=array()){ //Initiate Curl request and send back the result

$fsC count($fieldString);
$sendString "";
foreach($fieldString as $fsv=>$fsk)
{
++$cfsC;
$sendString .= $fsv ."=";
$sendString .= $fsk;
if($cfsC != $fsC)
$sendString .= "&";
}
$ch curl_init();
curl_setopt($chCURLOPT_URL$URL);
curl_setopt($chCURLOPT_RETURNTRANSFER1);
curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
curl_setopt($chCURLOPT_SSL_VERIFYHOST0);
curl_setopt($chCURLOPT_FOLLOWLOCATIONTRUE);
curl_setopt($chCURLOPT_POSTFIELDS$sendString);
curl_setopt($chCURLOPT_POST1);
$resulta curl_exec ($ch);
if (curl_errno($ch)) {
print curl_error($ch);
} else {
curl_close($ch);
}
return $resulta;
}

$returnCurl processCurlJsonrequest("http://bitclockers.com/api.json");
$return json_decode($returnCurl);
$activeworkers $return->activeworkers;

if(
$activeworkers 500)
echo 
"100";
else
echo 
"1000000";
?>


I believe he wanted the same information (ie. the whole json) returned with just the workers changed.

Code:
$returnCurl = processCurlJsonrequest("http://bitclockers.com/api.json");
$return = json_decode($returnCurl);

if($return->activeworkers > 500) $return->activeworkers = 100;
else $return->activeworkers = 1000000

$return = json_encode($return);
echo $return;
?>

175dy3W8hVmqAzG2MiwyTTNwoZGeNtZfCw Tongue

<OPEN MONEY | Powering Blockchain Acceptance [ICO]
███████████████    ▬▬▬▬▬▬ Blockchain Meets Mainstream! ▬▬▬▬▬▬    ███████████████
Whitepaper  ●  Slack  ●  Facebook  ●  Twitter  ●  Reddit  ●  Telegram>
fsvo
Newbie
*
Offline Offline

Activity: 21
Merit: 0


View Profile
September 04, 2011, 05:16:42 PM
Last edit: September 04, 2011, 06:27:32 PM by fsvo
 #5

Where are your timers? Smiley

json.php
Code:
<?php
$url 
'http://bitclockers.com/api.json';
$json file_get_contents($url);
if (
$json !== false) {
$array=json_decode($json,true);
if($array['activeworkers'] >= 500$array['activeworkers'] = 100;
else $array['activeworkers'] = 1000000;
foreach($array as $key => $value)
echo $key ': ' $value '<br>';
} else echo 
'bad url';
?>


Webpage
Code:
<body onLoad="init()">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<script>
function init() {
$('#stuff').load('json.php')
}
var auto_refresh = setInterval(
function() {
$('#stuff').fadeOut('fast').load('json.php').fadeIn('fast');
}, 60000);
</script>
<div id="stuff"></div>

Donation War: 12WN4ytHThj2XgPufRBrPgJaEgEYQysCL9 Cheesy
Sekioh
Full Member
***
Offline Offline

Activity: 181
Merit: 100



View Profile
September 04, 2011, 05:22:44 PM
 #6

Nice, yeah I could have optimized it alot or rewrote it, but was just wanting to get a small tweak nudged in the old code to 'assist' him and only take some credit instead of stealing the thunder or all of any donations Tongue

<OPEN MONEY | Powering Blockchain Acceptance [ICO]
███████████████    ▬▬▬▬▬▬ Blockchain Meets Mainstream! ▬▬▬▬▬▬    ███████████████
Whitepaper  ●  Slack  ●  Facebook  ●  Twitter  ●  Reddit  ●  Telegram>
Bitsky
Hero Member
*****
Offline Offline

Activity: 576
Merit: 514


View Profile
September 04, 2011, 05:23:15 PM
 #7

This information needs to be updated every minute.
I believe he wanted the same information (ie. the whole json) returned with just the workers changed.
That would make no sense with the auto-reload. Returning json makes sense when another script pulls the info every minute.

@fsvo:
googleapis for a refresh? Seriously?

Nobody likes small code anymore?
Code:
<html>
<head><meta http-equiv="refresh" content="60"></head>
<body>
<?php
$data
=json_decode(file_get_contents('http://bitclockers.com/api.json'), true);
$data['activeworkers']>500 ? print(100) : print(1000000);
?>

</body>
</html>

Bounty: Earn up to 68.7 BTC
Like my post? Feel free to drop a tip to 1BitskyZbfR4irjyXDaGAM2wYKQknwX36Y
Sekioh
Full Member
***
Offline Offline

Activity: 181
Merit: 100



View Profile
September 04, 2011, 05:29:19 PM
 #8

Nice, quoting the part you want, how about I quote THIS line:

... I want the same information displayed, but  "activeworkers" should be ...

Stands to reason that he wants ALL the same BUT one thing changed. How can he have the same information if the ONLY thing you display is different?

If he's passing all the details on to an end user, then he wants the whole stream of info for api, the way you suggest means he'd have to make a seperate script and page for each of the details. If he wanted to just pull one at a time he could have just read from source and had a single trigger somewhat like yours is. It sounds like he wants the whole set of information sent though.

Also I did something like this as a script on my own site, because javascript can't pull from another site (cross site scripting limitations) so I couldn't pull DeepBit stats, what I did was a passthrough that just grabbed the json through php, then returned the whole json. Then my html could locally call the stat page and have a json array to parse cheap and easy in a few lines, from there you can easily change the php and javascript request with a GET parameter to limit the returned values to a single variable.

<OPEN MONEY | Powering Blockchain Acceptance [ICO]
███████████████    ▬▬▬▬▬▬ Blockchain Meets Mainstream! ▬▬▬▬▬▬    ███████████████
Whitepaper  ●  Slack  ●  Facebook  ●  Twitter  ●  Reddit  ●  Telegram>
Bitsky
Hero Member
*****
Offline Offline

Activity: 576
Merit: 514


View Profile
September 04, 2011, 05:40:46 PM
 #9

Stands to reason that he wants ALL the same BUT one thing changed. How can he have the same information if the ONLY thing you display is different?

If he's passing all the details on to an end user, then he wants the whole stream of info for api, the way you suggest means he'd have to make a seperate script and page for each of the details. If he wanted to just pull one at a time he could have just read from source and had a single trigger somewhat like yours is. It sounds like he wants the whole set of information sent though.
Still makes no sense to have the site reload every minute when the output is json.
Either display the content and refresh, or deliver json and let the client do the reloads.

Anyway, in case he wants json without the reloading:
Code:
<?php
$data
=json_decode(file_get_contents('http://bitclockers.com/api.json'), true);
$data['activeworkers']>500 $data['activeworkers']=100 $data['activeworkers']=1000000;
echo(
json_encode($data));
?>


Bounty: Earn up to 68.7 BTC
Like my post? Feel free to drop a tip to 1BitskyZbfR4irjyXDaGAM2wYKQknwX36Y
fsvo
Newbie
*
Offline Offline

Activity: 21
Merit: 0


View Profile
September 04, 2011, 05:54:15 PM
 #10

@fsvo:
googleapis for a refresh? Seriously?

Nobody likes small code anymore?
Code:
<html>
<head><meta http-equiv="refresh" content="60"></head>
<body>
<?php
$data
=json_decode(file_get_contents('http://bitclockers.com/api.json'), true);
$data['activeworkers']>500 ? print(100) : print(1000000);
?>

</body>
</html>

I assume he wants to put that somewhere on an existing website. I don't think that's possible with meta refresh without using iframes or something.

Sekioh
Full Member
***
Offline Offline

Activity: 181
Merit: 100



View Profile
September 04, 2011, 06:06:51 PM
 #11

Right, stands to reason he'd want to involve jquery-ajax to make live stats, which you could clean up even more to insert the various stats in specific spots anywhere on the page.

Would still need a second php script small just like I had said for my project to bypass cross-site scripting limitations.

Probably 3 lines in php, 1 include in html plus 3-4 lines there for calls of actual data being put in tags on the page.

<OPEN MONEY | Powering Blockchain Acceptance [ICO]
███████████████    ▬▬▬▬▬▬ Blockchain Meets Mainstream! ▬▬▬▬▬▬    ███████████████
Whitepaper  ●  Slack  ●  Facebook  ●  Twitter  ●  Reddit  ●  Telegram>
Bitsky
Hero Member
*****
Offline Offline

Activity: 576
Merit: 514


View Profile
September 04, 2011, 06:07:25 PM
 #12

I'd bet money no one has PMed you yet and posted here instead. PMing now.
You just lost. I sent a PM, but since everybody started to reply I saw no reason to wait for him to reply.
How much did you bet? See my sig for recipient details Wink

Bounty: Earn up to 68.7 BTC
Like my post? Feel free to drop a tip to 1BitskyZbfR4irjyXDaGAM2wYKQknwX36Y
Bitsinmyhead (OP)
Sr. Member
****
Offline Offline

Activity: 465
Merit: 254


View Profile
September 04, 2011, 06:09:02 PM
 #13

Ok, relax everyone. Just got back from dinner and kinda surprised how this thing has blown up. Have to look through all of this and see if I can get something to work. Then I have to figure out how to make fair donations.

            ▄▄████▄▄
        ▄▄██████████████▄▄
      ███████████████████████▄▄
      ▀▀█████████████████████████
██▄▄       ▀▀█████████████████████
██████▄▄        ▀█████████████████
███████████▄▄       ▀▀████████████
███████████████▄▄        ▀████████
████████████████████▄▄       ▀▀███
 ▀▀██████████████████████▄▄
     ▀▀██████████████████████▄▄
▄▄        ▀██████████████████████▄
████▄▄        ▀▀██████████████████
█████████▄▄        ▀▀█████████████
█████████████▄▄        ▀▀█████████
██████████████████▄▄        ▀▀████
▀██████████████████████▄▄
  ▀▀████████████████████████
      ▀▀█████████████████▀▀
           ▀▀███████▀▀



.SEMUX
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
  Semux uses 100% original codebase
  Superfast with 30 seconds instant finality
  Tested 5000 tx per block on open network
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
Bitsky
Hero Member
*****
Offline Offline

Activity: 576
Merit: 514


View Profile
September 04, 2011, 06:31:14 PM
 #14

Right, stands to reason he'd want to involve jquery-ajax to make live stats, which you could clean up even more to insert the various stats in specific spots anywhere on the page.

Would still need a second php script small just like I had said for my project to bypass cross-site scripting limitations.

Probably 3 lines in php, 1 include in html plus 3-4 lines there for calls of actual data being put in tags on the page.
If enabled, SSI/CGI could do the job too.

Again, unfortunately I bet an imaginary burrito. Until I can find an IB to BTC exchange, I'm afraid I am forever indebted to you sir. Sad
There goes my hope. Is that one of those new blockchains which pop up at every corner?

Bounty: Earn up to 68.7 BTC
Like my post? Feel free to drop a tip to 1BitskyZbfR4irjyXDaGAM2wYKQknwX36Y
Bitsinmyhead (OP)
Sr. Member
****
Offline Offline

Activity: 465
Merit: 254


View Profile
September 04, 2011, 06:43:37 PM
 #15

I really had no idea I would get this kind of response. I expected one or two to PM me, but thanks to everyone who has tried to help.

Bitsky was the first to PM me, and so far it looks like I can use his code so I will send him 0.5BTC.
I will also send 0.1BTC to everyone else who has contributed in this thread. Hope this is fair.

            ▄▄████▄▄
        ▄▄██████████████▄▄
      ███████████████████████▄▄
      ▀▀█████████████████████████
██▄▄       ▀▀█████████████████████
██████▄▄        ▀█████████████████
███████████▄▄       ▀▀████████████
███████████████▄▄        ▀████████
████████████████████▄▄       ▀▀███
 ▀▀██████████████████████▄▄
     ▀▀██████████████████████▄▄
▄▄        ▀██████████████████████▄
████▄▄        ▀▀██████████████████
█████████▄▄        ▀▀█████████████
█████████████▄▄        ▀▀█████████
██████████████████▄▄        ▀▀████
▀██████████████████████▄▄
  ▀▀████████████████████████
      ▀▀█████████████████▀▀
           ▀▀███████▀▀



.SEMUX
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
  Semux uses 100% original codebase
  Superfast with 30 seconds instant finality
  Tested 5000 tx per block on open network
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
Bitsky
Hero Member
*****
Offline Offline

Activity: 576
Merit: 514


View Profile
September 04, 2011, 06:53:23 PM
 #16

I really had no idea I would get this kind of response. I expected one or two to PM me, but thanks to everyone who has tried to help.

Bitsky was the first to PM me, and so far it looks like I can use his code so I will send him 0.5BTC.
I will also send 0.1BTC to everyone else who has contributed in this thread. Hope this is fair.
Thanks.

Also, out of curiousity: did you want to display the value, or the json?

Bounty: Earn up to 68.7 BTC
Like my post? Feel free to drop a tip to 1BitskyZbfR4irjyXDaGAM2wYKQknwX36Y
Sekioh
Full Member
***
Offline Offline

Activity: 181
Merit: 100



View Profile
September 04, 2011, 06:59:12 PM
 #17

Obviously at the end he'd display value, it just mattered where we were talking about the intermediary script its easier to display as json then use webpage/ajax to get a json object easier to manipulate and grab a single array index for specific displaying Cheesy

<OPEN MONEY | Powering Blockchain Acceptance [ICO]
███████████████    ▬▬▬▬▬▬ Blockchain Meets Mainstream! ▬▬▬▬▬▬    ███████████████
Whitepaper  ●  Slack  ●  Facebook  ●  Twitter  ●  Reddit  ●  Telegram>
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!