Last active
August 29, 2015 14:09
-
-
Save sirkitree/100000979106639aef06 to your computer and use it in GitHub Desktop.
Generate a random room from the vrsites subreddit for janusvr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Generate a random link from vrsites subreddit. | |
| * Original author: http://www.reddit.com/user/MrM0bius | |
| */ | |
| $options = array('http' => array('user_agent' => 'JanusVR random site (v0.1)')); | |
| $context = stream_context_create($options); | |
| $rvrsites1 = file_get_contents('http://reddit.com/r/vrsites/.json?limit=100', false, $context); | |
| $rvrsites2 = file_get_contents('http://reddit.com/r/vrsites/.json?count=100&after=t3_2akppo&limit=100', false, $context); | |
| if ($rvrsites1 === false) { | |
| die(); | |
| } | |
| if ($rvrsites2 === false) { | |
| die(); | |
| } | |
| $set1 = json_decode($rvrsites1, true); | |
| $set2 = json_decode($rvrsites2, true); | |
| unset($rvrsites1); | |
| unset($rvrsites2); | |
| $rbool = rand(0, 1); | |
| if ($rbool == 1){ | |
| $selectedset = $set1; | |
| } | |
| else { | |
| $selectedset = $set2; | |
| } | |
| $rnum = rand(1, 100); | |
| echo '<html><head><title>Random Room from /r/vrsites</title></head><body><meta property="og:image" content="html://thevirtualarts.com/JanusVR/question.png">'; | |
| echo $selectedset["data"]["children"][$rnum]["data"]["url"]; | |
| echo '<!--<FireBoxRoom><AssetImage id="q" src="question.png" /><Room gravity="0" skybox_left_id="q" skybox_right_id="q" skybox_front_id="q" skybox_back_id="q" skybox_up_id="q" skybox_down_id="q"><Link pos="0 0 3.3" fwd="0 0 -1" url="'; | |
| echo $selectedset["data"]["children"][$rnum]["data"]["url"]; | |
| echo '" col="0.6 1 0.6" scale="2.8 3.5 1" auto_load="true" title="'; | |
| echo $selectedset["data"]["children"][$rnum]["data"]["title"]; | |
| echo '" /></Room></FireBoxRoom>--></body></html>'; |
Author
https://gist.github.com/MrM0bius/f4749a2f318cf889b103
Here's the newest version including the local caching and a few other tweaks.
(new to Github, not sure if this is the best way to show edits, etc)
Should also add that I'm totally new to php and there may be rookie mistakes littering the code, just let me know ;)
Author
Typically, you just need to 'fork' which copies it to your account and then you can modify it which saves revisions. In this case you are the originator anyways so it doesn't really matter. Php looks fine. There's some tricks to make the HTML text strings a bit easier to read, but this is fine.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could make this a bit faster by caching the
file_get_contentslocally.Would also be nice to pull sites from vrsites directory. Not sure if they provide a json feed of sites.