Bitcoin Forum

Economy => Services => Topic started by: Bitsinmyhead on September 04, 2011, 03:04:13 PM



Title: [WTB] Very small programming project
Post by: Bitsinmyhead on September 04, 2011, 03:04:13 PM
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.



Title: Re: [WTB] Very small programming project
Post by: SmokeAndMirrors on September 04, 2011, 04:32:44 PM
How much are you paying?


Title: Re: [WTB] Very small programming project
Post by: NothinG on September 04, 2011, 04:51:11 PM
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 :) 1ox8G5YzLxvo3hwvbtvA4oDzb1GX46big


Title: Re: [WTB] Very small programming project
Post by: Sekioh on September 04, 2011, 05:13:22 PM
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 :P


Title: Re: [WTB] Very small programming project
Post by: fsvo on September 04, 2011, 05:16:42 PM
Where are your timers? :)

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 :D


Title: Re: [WTB] Very small programming project
Post by: Sekioh on September 04, 2011, 05:22:44 PM
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 :P


Title: Re: [WTB] Very small programming project
Post by: Bitsky on September 04, 2011, 05:23:15 PM
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>


Title: Re: [WTB] Very small programming project
Post by: Sekioh on September 04, 2011, 05:29:19 PM
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.


Title: Re: [WTB] Very small programming project
Post by: Bitsky on September 04, 2011, 05:40:46 PM
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));
?>



Title: Re: [WTB] Very small programming project
Post by: fsvo on September 04, 2011, 05:54:15 PM
@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.



Title: Re: [WTB] Very small programming project
Post by: Sekioh on September 04, 2011, 06:06:51 PM
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.


Title: Re: [WTB] Very small programming project
Post by: Bitsky on September 04, 2011, 06:07:25 PM
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 ;)


Title: Re: [WTB] Very small programming project
Post by: Bitsinmyhead on September 04, 2011, 06:09:02 PM
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.


Title: Re: [WTB] Very small programming project
Post by: Bitsky on September 04, 2011, 06:31:14 PM
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. :(
There goes my hope. Is that one of those new blockchains which pop up at every corner?


Title: Re: [WTB] Very small programming project
Post by: Bitsinmyhead on September 04, 2011, 06:43:37 PM
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.


Title: Re: [WTB] Very small programming project
Post by: Bitsky on September 04, 2011, 06:53:23 PM
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?


Title: Re: [WTB] Very small programming project
Post by: Sekioh on September 04, 2011, 06:59:12 PM
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 :D