Author

Topic: [WTB] Very small programming project (Read 1367 times)

full member
Activity: 181
Merit: 100
September 04, 2011, 02: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
hero member
Activity: 576
Merit: 514
September 04, 2011, 02: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?
sr. member
Activity: 465
Merit: 254
September 04, 2011, 02: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.
hero member
Activity: 576
Merit: 514
September 04, 2011, 02: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?
sr. member
Activity: 465
Merit: 254
September 04, 2011, 02: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.
hero member
Activity: 576
Merit: 514
September 04, 2011, 02: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
full member
Activity: 181
Merit: 100
September 04, 2011, 02: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.
newbie
Activity: 21
Merit: 0
September 04, 2011, 01:54:15 PM
#10
@fsvo:
googleapis for a refresh? Seriously?

Nobody likes small code anymore?
Code:



$data=json_decode(file_get_contents('http://bitclockers.com/api.json'), true);
$data['activeworkers']>500 ? print(100) : print(1000000);
?>




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.

hero member
Activity: 576
Merit: 514
September 04, 2011, 01: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:
$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));
?>

full member
Activity: 181
Merit: 100
September 04, 2011, 01: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.
hero member
Activity: 576
Merit: 514
September 04, 2011, 01: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:



$data=json_decode(file_get_contents('http://bitclockers.com/api.json'), true);
$data['activeworkers']>500 ? print(100) : print(1000000);
?>



full member
Activity: 181
Merit: 100
September 04, 2011, 01: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
newbie
Activity: 21
Merit: 0
September 04, 2011, 01:16:42 PM
#5
Where are your timers? Smiley

json.php
Code:
$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 '
'
;
} else echo 
'bad url';
?>


Webpage
Code:





Donation War: 12WN4ytHThj2XgPufRBrPgJaEgEYQysCL9 Cheesy
full member
Activity: 181
Merit: 100
September 04, 2011, 01:13:22 PM
#4
hero member
Activity: 560
Merit: 500
September 04, 2011, 12:51:11 PM
#3
Code:
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
full member
Activity: 168
Merit: 100
September 04, 2011, 12:32:44 PM
#2
How much are you paying?
sr. member
Activity: 465
Merit: 254
September 04, 2011, 11:04:13 AM
#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.

Jump to: