[GUIDE][Difficulty: Intermediate] Read a Random Top Voted Thread from Reddit

Search This thread

MishaalRahman

Editor in Chief
Nov 2, 2015
1,039
2,123
www.xda-developers.com
I'm sure many users here have heard of or currently use Reddit, the link aggregation website. If you use the website for news, to find funny jokes, to find awesome tips, etc. then you'll be happy to know that Reddit offers the ability to read data from its subreddits in the form of a JSON feed, and using Tasker we can process this feed to get the data that we want, in this case the titles of each thread. In my setup, I'm taking a random title among the top 3 posts of the day from /r/quotes.

Instructions

  1. Variables --> Variable Set. Name %subreddit to the name of a subreddit you would like to pull from.
  2. Variables --> Variable Set. Name %numposts to whatever number of posts you want to pull before randomizing which one is picked.
  3. Net --> HTTP Get. The Server:port you'll be grabbing is:
    Code:
    json.reddit.com/r/%subreddit/top/?sort=top&t=day
  4. Code --> Javascriptlet. Here is the Javascriptlet you'll need to put under Code.
    Code:
    var arr = JSON.parse(global("HTTPD"));
    var randomnumber = Math.floor((Math.random()*numposts)+1);
    var selftext = arr.data.children[randomnumber].data.selftext
    var title = arr.data.children[randomnumber].data.title
  5. Variables --> Variable Clear. Set Name to %HTTPD* and check Pattern Matching.
  6. Alert --> Say. For the text, you can say anything to preface what Tasker is about to put out. For instance, I've said it to "Your quote of the day is: %title." This should change depending on which subreddit you pull from.

That's it! Pretty simple to start with. You can change the Javascriptlet to pull N number of threads into an array and mess with that if you would like. Tasker's Javascriptlet user guide is a great resource for this.
 

suhel28

Senior Member
Oct 30, 2010
307
133
Did exactly as you said and it doesn't work.

Edit : Darn this is a pretty old thread

Sent from my Honor 6X using XDA Labs
 
Last edited:

Top Liked Posts

  • There are no posts matching your filters.
  • 9
    I'm sure many users here have heard of or currently use Reddit, the link aggregation website. If you use the website for news, to find funny jokes, to find awesome tips, etc. then you'll be happy to know that Reddit offers the ability to read data from its subreddits in the form of a JSON feed, and using Tasker we can process this feed to get the data that we want, in this case the titles of each thread. In my setup, I'm taking a random title among the top 3 posts of the day from /r/quotes.

    Instructions

    1. Variables --> Variable Set. Name %subreddit to the name of a subreddit you would like to pull from.
    2. Variables --> Variable Set. Name %numposts to whatever number of posts you want to pull before randomizing which one is picked.
    3. Net --> HTTP Get. The Server:port you'll be grabbing is:
      Code:
      json.reddit.com/r/%subreddit/top/?sort=top&t=day
    4. Code --> Javascriptlet. Here is the Javascriptlet you'll need to put under Code.
      Code:
      var arr = JSON.parse(global("HTTPD"));
      var randomnumber = Math.floor((Math.random()*numposts)+1);
      var selftext = arr.data.children[randomnumber].data.selftext
      var title = arr.data.children[randomnumber].data.title
    5. Variables --> Variable Clear. Set Name to %HTTPD* and check Pattern Matching.
    6. Alert --> Say. For the text, you can say anything to preface what Tasker is about to put out. For instance, I've said it to "Your quote of the day is: %title." This should change depending on which subreddit you pull from.

    That's it! Pretty simple to start with. You can change the Javascriptlet to pull N number of threads into an array and mess with that if you would like. Tasker's Javascriptlet user guide is a great resource for this.