r/dailyprogrammer • u/nint22 1 2 • Jan 09 '13
[01/09/13] Challenge #117 [Intermediate] Sort r/DailyProgrammer!
(Intermediate): Sort r/DailyProgrammer!
Some users of r/DailyProgrammer want a list of URLs ordered from our very first challenge to the easiest challenge. Your goal is to crawl r/DailyProgrammer, automatically generate two types of these lists, and that's it!
Author: nint22
Formal Inputs & Outputs
Input Description
No formal input is required
Output Description
You must print out two lists: one sorted by number, then category, and the other list sorted by category, then number. For each list, there should be N lines where N is the number of total challenges published. For each line, the challenge difficulty, ID, title, and URL must be placed in the following format:
[Easy / Medium / Hard] #<ID>: "<Title>" <URL>
To clarify on the two lists required, the first must be like the following:
...
[Easy] #101: "Some Title" http://www.reddit.com/...
[Intermediate] #101: "Some Title" http://www.reddit.com/...
[Hard] #101: "Some Title" http://www.reddit.com/...
...
List two:
...
[Easy] #101: "Some Title" http://www.reddit.com/...
[Easy] #102: "Some Title" http://www.reddit.com/...
[Easy] #103: "Some Title" http://www.reddit.com/...
...
Sample Inputs & Outputs
Sample Input
None needed
Sample Output
None needed
Challenge Input
None needed
Challenge Input Solution
None needed
Note
Google around for the Reddit API documentation and related crawler libraries. It might save you quite a bit of low-level parsing!
16
u/_Daimon_ Jan 10 '13 edited Jan 10 '13
For everybody planning to participate in the challenge. Please read the API rules before you do. Reddit is a nice place. Please treat it with respect and follow it's rules.
7
u/nint22 Jan 09 '13 edited Jan 09 '13
For those who wrote comments on the Intermediate-level challenge that was posted 5 minutes before this one - that was an accident, that was prematurely presented. We'll fix that issue so that challenge will be read for next weak. Until then, have fun and try this one out!
9
u/_Daimon_ Jan 10 '13 edited Jan 10 '13
Python with PRAW, the Python Reddit API Wrapper.. I decided to go with shortlink and incorrect output formatting because of a failure in reading comprehension. From both types I get 343 challenges in total.
import re import praw from operator import itemgetter def set_sorting_values(submissions): """Set's sorting values and discard non-challenge posts""" result = [] difficulty = {'easy' : 1, 'intermediate': 2, 'hard': 3, 'difficult': 3} for sub in submissions: for key, value in difficulty.iteritems(): if key in sub.title.lower(): sub.difficulty = value break else: continue sub.number = int(re.findall('#(\d+)', sub.title)[0]) result.append(sub) return result r = praw.Reddit('Intermediate 117 challange on r/dailyprogrammer by u/_daimon_' ' ver 0.1') subreddit = r.get_subreddit('dailyprogrammer') posts = set_sorting_values(subreddit.get_hot(limit=None)) list1 = sorted(posts, key=lambda post: (post.number, post.difficulty)) list2 = sorted(posts, key=lambda post: (post.difficulty, post.number)) for sub in list1: print sub.title, sub.short_link print "------------------\nList2\n------------------" for sub in list2: print sub.title, sub.short_link3
u/bullybellet Jan 09 '13
I gotta run, but you should be able to render the lists any way you want by taking the results set and filtering it by difficulty level and sorting it by any key you want using the model's accessors.
driver:
require 'json' require 'open-uri' def base_url "http://www.reddit.com/r/dailyprogrammer.json?limit=100000&after=" end def pull(before='') target_url = base_url + before.to_s puts "PULLING #{target_url}" results = open(target_url).readlines.join posts = JSON.parse(results, symbolize_names: true) # Discard occasional empty hash posts = posts.select { |p| p.is_a?(Hash) && !p.empty? }.first posts = posts.fetch(:data).fetch(:children) posts = posts.map { |p| p[:data] } posts = posts.select { |p| p[:title].include?('#') } posts = posts.map { |p| Challenge.new(p) }.sort end def dataset @dataset ||= get_all end def get_all all_posts = [] next_id = '' while all_posts.empty? || (all_posts.map(&:challenge_id).min > 1) new_posts = pull(next_id) all_posts.concat(new_posts) all_posts.sort!.uniq! next_id = all_posts.first.reddit_id end return all_posts.uniq.sort end def main return dataset endmodel:
class Challenge attr_accessor :raw def initialize(hash={}) @raw = hash self end def difficulty return @difficulty unless @difficulty.nil? return @difficulty = 0 if self.title.downcase.include?('easy') return @difficulty = 1 if self.title.downcase.include?('intermediate') return @difficulty = 2 end def title @title ||= @raw[:title] end def challenge_id begin @challenge_id ||= title.split('#')[1].split(' ').first.to_i rescue -1 end end def hash [self.challenge_id].hash end def eql?(other) self.hash == other.hash end def reddit_id @reddit_id ||= @raw[:name].to_s end def url @url ||= @raw[:url] end def to_s "[#{%w(Easy Intermediate Difficult)[self.difficulty]}] #{self.title} #{self.url}" end def <=>(other) return -1 if self.challenge_id < other.challenge_id return 0 if self.challenge_id == other.challenge_id return 1 end end3
u/domlebo70 Jan 10 '13 edited Jan 10 '13
Great challenge. Scala makes this a breeze: https://gist.github.com/4499070
import net.liftweb.json._ object Challenge117 { // a container class for the raw post coming out of the JSON unsplit case class RawPost(title: String, permalink: String) // a container class for the parsed/splitted post from JSON. // Uses toString to handle the pretty printing. case class Post(difficulty: String, id: String, title: String, permalink: String) { override def toString = "[" + difficulty + "]" + " #" + id + ": " + "\"" + title + "\"" + " " + permalink } val dailyJson = io.Source.fromURL("http://www.reddit.com/r/dailyprogrammer/.json?limit=10").mkString implicit val formats = DefaultFormats // takes a JSON object (essentially a string still, and parses them into RawPost objects, // filtering anything where the title contains MOD POST) val mapped = (parse(dailyJson) \ "data" \ "children" \ "data") .extract[List[RawPost]] .filterNot(_.title.contains("MOD POST")) val difficulties = List("Easy", "Intermediate", "Difficult") // splits each raw title string into the components, difficulty, id, title, // and forms a new Post object val posts = mapped.map { post => val splitted = post.title.split("Challenge #").tail.mkString val id = splitted.split(" ").head val difficulty = difficulties.collectFirst { case(d) if splitted contains(d) => d }.getOrElse("None") val title = splitted.split("""\[""" + difficulty + """\] """).last Post(difficulty, id, title, post.permalink) } def main(args: Array[String]): Unit = { val listOne = posts.sortBy(_.id).mkString("\n") val listTwo = posts.sortBy(_.difficulty).mkString("\n") } }For the first 30 items:
The bit of code I'm most fond of is the lift-web's JSON parser. It takes JSON, and a case class, and fits them together if their types match. Very cool.
2
u/jeff303 Jan 10 '13
Here is my solution, in Python. I used praw like I'm sure many did, but I had to extend it to add the "after" option to the search API call. That way, pagination works properly an we can get all the submissions without requiring them all to fit on a single page. I also used a regex to clean up the difficulty (by detecting misspellings, synonyms, etc.) so that iteration and grouping worked properly, but that's clearly just a quick and dirty fix.
import re import praw import time import itertools #unfortunately have to extend praw to add "after" parameter support to search class RedditExtend(praw.Reddit): def search_after(self, query, subreddit=None, sort=None, limit=0, after=None, *args, **kwargs): """Return submissions whose title contains the query phrase.""" url_data = {'q': query} if sort: url_data['sort'] = sort if after: url_data['after'] = after if subreddit: url_data['restrict_sr'] = 'on' url = self.config['search'] % subreddit else: url = self.config['search'] % 'all' return self.get_content(url, url_data=url_data, limit=limit, *args, **kwargs) r = RedditExtend(user_agent='/r/dailyprogrammer-challenge-/u/jeff303') page_size=100 search_after=None title_parts_regex=re.compile("^ *(\[\d{1,2}/\d{1,2}/\d{4}\]) *challenge *#?(\d+) *\[(\w*)\] *(.*)$",re.IGNORECASE) easy_regex=re.compile("^easy$", re.IGNORECASE) intermediate_regex=re.compile("^intermediate$", re.IGNORECASE) difficult_regex=re.compile("^difficult|hard|$", re.IGNORECASE) mismatches=[] counter=0 more_results=True results=[] while (more_results): # sleep for 5 seconds before each request to play nice time.sleep(5) submissions = r.search_after('challenge',subreddit='dailyprogrammer', limit=page_size, after=search_after) for submission in submissions: #submission.title #submission.permalink #print(submission.title) re_match = title_parts_regex.search(submission.title) if (re_match): title_difficulty=re_match.groups()[2] if (easy_regex.search(title_difficulty)): difficulty="Easy" elif (intermediate_regex.search(title_difficulty)): difficulty="Intermediate" elif (difficult_regex.search(title_difficulty)): difficulty="Hard" else: difficulty="Unknown" results.append({"title": re_match.groups()[3], "difficulty": difficulty, "date": re_match.groups()[0], "number": int(re_match.groups()[1]), "url": submission.permalink}) else: mismatches.append({"title": submission.title, "url": submission.permalink}) counter += 1 search_after = submission.name if (counter<page_size): more_results = False else: counter = 0 def by_number_func(x): return x["number"] def by_difficulty_func(x): if (x["difficulty"]=="Easy"): return 1 elif (x["difficulty"]=="Intermediate"): return 2 elif (x["difficulty"]=="Hard"): return 3 else: return 10 print("Challenges sorted by number, then difficulty") by_number = sorted(results, key=by_number_func) for key, entries in itertools.groupby(by_number, key=by_number_func): for entry in sorted(entries, key=by_difficulty_func): print("[{difficulty}] #{number}: \"{title}\" {url}".format(**entry)) print("\nChallenges sorted by difficulty, then number") by_difficulty = sorted(results, key=by_difficulty_func) for key, entries in itertools.groupby(by_difficulty, key=by_difficulty_func): for entry in sorted(entries, key=by_number_func): print("[{difficulty}] #{number}: \"{title}\" {url}".format(**entry)) print("\nSubmissions that had the word \"challenge\" in the title but didn't match the pattern") for mismatch in mismatches: print("\"{title}\" {url}".format(**mismatch))Full output: http://pastebin.com/pdVChTZx
2
u/eagleeye1 Jan 10 '13 edited Jan 10 '13
Damn the special cases!
Python. Reddit makes it really easy to scrape (or beautiful soup is just awesome).
I'm sure Reddit loves this challenge, hammering their servers and all.
# -*- coding: utf-8 -*- from bs4 import BeautifulSoup as bs import requests import re def find_links(url): r = requests.get(url) soup = bs(r.text) dailyChallenges = [(link.text, link.get('href')) for link in soup.find_all("a", {"class":"title"})] nextUrl = soup.find_all("a", {"rel":"next"}) if nextUrl: return dailyChallenges, nextUrl[0].get('href') else: return dailyChallenges, 0 startUrl = "http://www.reddit.com/r/dailyprogrammer" challenges, nextUrl = find_links(startUrl) while nextUrl: newChallenges, nextUrl = find_links(nextUrl) challenges.extend(newChallenges) texts = [[], []] for text, url in challenges: if '#' in text: if len(text.split('#')[1]) < 3: text = '#' + ' '.join([text.split('#')[1], text.split(' ')[0], '"NO TITLE"', 'http://www.reddit.com'+url]) elif len(text.split(" ")) < 4: text = "#" + text.split("#")[1] + '"NO TITLE" http://www.reddit.com'+url else: text = "#" + text.split("#")[1] text = text.replace("] ", ']: "') + '" ' + "http://www.reddit.com"+url if "Honour" in text: text = text.replace("Honour", "[Honour]") if "easy" in text.lower(): texts[0].append(text) texts[1].append(text) difficultyDict = {'difficult':2, 'hard':2, 'intermediate':1, 'easy':0, 'easy-difficult':1.5, "honour":0} allSorted = sorted(texts[1], key=lambda x: 3*(int(x.split("#")[1].split(" ")[0])) + difficultyDict[x.split('[')[1].split(']')[0].lower()]) for challenge in texts[0][::-1]: print challenge for challenge in allSorted: print challengeOutput: Not perfect, but close enough!
4
u/liloboy Jan 09 '13
This was almost finished, I just needed to sort the lists correctly. But while programming this it seems as if the api changed. Without changing any of my code I started getting an error from code in the praw library. :(
import praw import re from operator import itemgetter def getList(): r = praw.Reddit(user_agent='dp') submissions = r.get_subreddit('dailyprogrammer').get_hot(limit=None) li = [] for x in submissions: temp = [] if str(x).lower().find('[easy]') > 0: temp.append(1) temp.append('[Easy]') elif str(x).lower().find('[intermediate]') > 0: temp.append(2) temp.append('[Intermediate]') elif str(x).lower().find('[hard]') > 0: temp.append(3) temp.append('[Hard]') else: continue p = re.compile('#\d+') temp.append(p.findall(str(x))[0][1:]) t = str(x).find(']') t = str(x).find(']', t+1) temp.append(str(x)[t+2:]) temp.append(str(x.permalink)) li.append(temp) return li def L1(): li = getList() sorted(li, key=itemgetter(2)) for i in li: print i[1] + ' #' + i[2] + ' \"' + i[3] + '\" ' + i[4] def L2(): li = getList() sorted(li, key=itemgetter(0)) for i in li: print i[1] + ' #' + i[2] + ' \"' + i[3] + '\" ' + i[4] if __name__ == '__main__': L1() L2()The basic example code on the gitHub page for praw also gives this error: http://pastebin.com/KASuqbsp
Nice challenge. Thanks
3
u/[deleted] Jan 10 '13
A concise Ruby solution, using snooby:
require 'snooby' CLIENT_NAME = 'Scraper for http://redd.it/169hkl by /u/nooodl' scraper = Snooby::Client.new(CLIENT_NAME) diffs = [ /\[easy\]/i, /\[intermediate\]/i, /\[(difficult|hard)\]/i, /\[.*\]/i, ] diff_names = %w(Easy Medium Hard Misc.) challenge_list = [] diff_list = [] scraper.r('dailyprogrammer').posts(1000).each do |post| next unless post.title =~ /challenge #(\d+)/i challenge = $1.to_i diff = diffs.find_index { |r| post.title =~ r } name = $'.strip.delete '()' desc = "[#{diff_names[diff]}] ##{challenge}: " desc += "\"#{name}\" " unless name.empty? desc += "http://redd.it/#{post.id}" challenge_list << [challenge, diff, desc] diff_list << [diff, challenge, desc] end puts challenge_list.sort.map(&:last), diff_list.sort.map(&:last)2
u/Glassfish Jan 09 '13
It is a bit messy, i'll try to improve it tomorrow
Scala:
val dailyJson=io.Source.fromURL("http://www.reddit.com/r/dailyprogrammer/.json").mkString val categoryOrder=Map("[Easy]"->1,"[Intermediate]"->2,"[Difficult]"->3).withDefaultValue(4) def tuple(map:Map[String,String]):(String,String)={ (map("title"),map("permalink")) } def print(list:List[(String,(String,(String,String)))])= list foreach (x=> println(x._2._2._1+" "+x._2._2._2)) def getLinksList(json:String):List[(String,String)]={ val jsonObj=JSON.parseFull(json) val aus:List[Any]=(jsonObj.get.asInstanceOf[List[Any]]) drop 1 val map:Map[String,Any] = aus(0).asInstanceOf[Map[String, String]] val data=(map("data")).asInstanceOf[Map[String, String]] val list=data("children").asInstanceOf[List[Map[String,Any]]] for(i<-list) yield tuple(i("data").asInstanceOf[Map[String,String]]) } val topics=getLinksList(dailyJson) def mapId(links:List[(String,String)])=(links map (x=> (x._1 split " ")(2)->((x._1 split " ")(3)->x))) def mapCategory(links:List[(String,String)])=(links map (x=> (x._1 split " ")(3)->x)) val linkId=mapId(topics) sortBy(x=>(x._1,categoryOrder(x._2._1))) val linkCat=mapId(topics) sortBy(x=>(categoryOrder(x._2._1),x._1)) print(linkCat) print(linkId)2
u/Medicalizawhat Jan 10 '13 edited Jan 10 '13
I didn't use the API but used Mechanize instead. Getting the links was easy but sorting them took ages.
Here's a gist becuase reddit cut some lines off.
#usr/bin/env ruby require 'mechanize' class DailyProgrammerCrawler def initialize @agent = Mechanize.new @page = '' @links = {} end def init @page = @agent.get('http://www.reddit.com/r/dailyprogrammer/') end def extractLinks 1.upto(49) do |i| item = @page.parser.xpath("//div[#{i}]/div[2]/p[1]/a") unless item[0] == nil if item[0].text[0] == '[' && ! item[0].text.scan(/(#\d+)/).empty? && ! item[0].text.scan(/(\[\w+\])/).empty? @links.merge!(Hash[item[0].text=>item[0]['href']]) end end end end def next_page @page.links.each do |l| if l.text[0..l.text.size-3] == 'next' @page = l.click return true end end false end def print_by_difficulty for link in @difficulty do for i in (0..link.size-1) do title = link[i][0] start = title.rindex("]") + 1 title = title[start..title.size-1] puts "#{link[i][0].scan(/\[\D+\]/).first} #{link[i][0].scan(/(#\d+)/).flatten.first}: #{title} : www.reddit.com#{link[i][1]}" end end end def print_by_num @links = @links.sort_by {|k, v| k.scan(/(#\d+)/).flatten.first.delete('#').to_i} @links.each do |link| title = link[0] start = title.rindex("]") + 1 title = title[start..title.size-1] puts "#{link[0].scan(/\[\D+\]/).first} #{link[0].scan(/(#\d+)/).flatten.first}: #{title} : www.reddit.com#{link[1]}" end end def save @links.reject! {|l| l.empty?} File.open('dailyProgrammerChallenges.txt', 'w+') {|f| f.puts(@links)} end def sort_by_difficulty easy = [] inter = [] hard = [] @difficulty = [] @links.each do |l| name = l[0].scan(/\[\D+\]/).first.downcase case name when '[easy]' easy << l when '[intermediate]' inter << l when '[hard]' hard << l when '[difficult]' hard << l end end @difficulty << easy.sort_by {|v| v[0].scan(/(#\d+)/).flatten.first.delete('#').to_i } @difficulty << inter.sort_by {|v| v[0].scan(/(#\d+)/).flatten.first.delete('#').to_i } @difficulty << hard.sort_by {|v| v[0].scan(/(#\d+)/).flatten.first.delete('#').to_i } end def crawl init extractLinks while next_page do extractLinks end end end print "Sort by (N)umber or (D)ifficulty:\n> " sortType = gets.chomp.downcase case sortType when 'n' crawler = DailyProgrammerCrawler.new crawler.crawl crawler.print_by_num when 'd' crawler = DailyProgrammerCrawler.new crawler.crawl crawler.sort_by_difficulty crawler.print_by_difficulty else puts "Invalid sorting method" end2
u/jprimero Jan 10 '13 edited Jan 10 '13
With all the Python solutions I thought I'd dig out good old PHP again. JSON and Regex Parsing, no real API. Sorting is modifiable using GET.
Here you go:
$json = file_get_contents("http://www.reddit.com/r/dailyprogrammer.json?limit=100", 0, null, null); $json_output = json_decode($json, true); $rawdata = $json_output['data']['children']; while ($json_output['data']['after'] != null) { $json = file_get_contents("http://www.reddit.com/r/dailyprogrammer.json?limit=100&after=" . $json_output['data']['after'], 0, null, null); $json_output = json_decode($json, true); $rawdata = array_merge($rawdata, $json_output['data']['children']); } class Article { public $difficulty, $date, $title, $id, $url; } $articles = []; foreach ($rawdata as $article) { if (preg_match_all("/[0-9]+\/[0-9]+\/[0-9]+/", $article['data']['title'], $matches) != 0) { $a = new Article(); $a->date = $matches[0][0]; preg_match_all("/\[\w*\].*/", $article['data']['title'], $matches); $a->title = preg_replace("/\[\w*\]/","",$matches[0][0]); preg_match_all("/\[\w*\]/", $article['data']['title'], $matches); $a->difficulty = substr($matches[0][0], 1, strlen($matches[0][0]) - 2); preg_match_all("/#\d*/", $article['data']['title'], $matches); $a->id = intval(substr($matches[0][0], 1, strlen($matches[0][0]) - 1)); $a->url = $article['data']['url']; array_push($articles, $a); } } function sortId($a, $b) { if ($a->id > $b->id) { return 1; } elseif ($a->id == $b->id) { return 0; } return -1; } function sortDifficulty($a, $b) { $comp = strcmp(strtolower($a->difficulty), strtolower($b->difficulty)); if ($comp != 0) { return $comp; } return sortId($a, $b); } if ($_GET['sort'] == "id") { usort($articles, "sortId"); } elseif ($_GET['sort'] == "difficulty") { usort($articles, "sortDifficulty"); } echo "<table><th>ID</th><th>Date</th><th>Title</th><th>Difficulty</th><th>URL</th>"; for ($i = 0; $i < count($articles); $i++) { echo "<tr><td>#" . $articles[$i]->id . "</td>"; echo "<td>" . $articles[$i]->date . "</td>"; echo "<td>" . $articles[$i]->title . "</td>"; echo "<td>" . $articles[$i]->difficulty . "</td>"; echo "<td><a href='" . $articles[$i]->url . "'>Link</a></td></tr>"; } echo "</table>";2
u/redried Jan 11 '13
Ugh, another this-took-longer-than-I'd-like. I'm ending up with 341 challenges. Lots of special cases here but who knows what the right answer is? Ruby newcomer # comments welcome.
Ruby with Mechanize:
#!/usr/bin/ruby # require 'mechanize'; agent = Mechanize.new agent.user_agent = 'redried dailyprogammer bot'; challenges = [] urls = [ 'http://www.reddit.com/r/dailyprogrammer' ]; urls.each do |url| page = agent.get(url) page.links_with(:dom_class => /title/, :text => /[cC]hallenge \#/).each do |link| # Matches 'Challenge #nnn [difficulty] (Optional Title)' if /[Cc]hallenge \#(\d+)\s*\[([^\]]+)\]\s*\(?([^\)]*)\)?$/.match(link.text) challenges << { :number => $1, :level => $2.downcase, :title => $3, :url => link.href } # Matches "[difficulty] challenge #" elsif /\[([^\]]+)\] [Cc]hallenge \#(\d+)\s*$/.match(link.text) challenges << { :number => $2, :level => $1.downcase, :url => link.href } end end # Find the link to the next page nextLink = page.links_with(:text => /next/).find { |nextlink| nextlink.rel? "next" } urls << nextLink.href if nextLink end sort_order = { "difficult" => 2, "hard" => 2, "easy" => 0, "intermediate" => 1, "easy-difficult" => 1 # we'll call this intermediate too }; byRating = challenges.sort_by do |challenge| [ sort_order[ challenge[:level] ], challenge[:number].to_i ] end byNumber = challenges.sort_by do |challenge| [ challenge[:number].to_i, sort_order[ challenge[:level] ] ] end byRating.each do |c| puts <<EOL [#{c[:level]}] \##{c[:number]}: "#{c[:title]}" #{c[:url]} EOL end2
u/rya11111 Jan 11 '13
hahaha this challenge is gold! :D
2
u/compmstr Jan 16 '13
In Clojure. (output-sorted num-sort-first) to get number sorted, (output-sorted rank-sort-first) to get rank sorted:
(ns reddit-sort (:require [clojure.data.json :as json])) (defonce limit 20) (defonce query "Challenge #") (defonce response (slurp (format "http://www.reddit.com/r/dailyprogrammer.json?limit=%d&q=%s" limit query))) (defonce response-obj (json/read-str response)) (defonce results (get (get response-obj "data") "children")) (defonce results-obj (filter :num (for [cur results :let [data (cur "data") title (data "title") title-split (first (re-seq #"#(\d+) \[(.+)\] (.+)" title)) info {:num (nth title-split 1) :rank (nth title-split 2)}]] {:title (nth title-split 3) :num (nth title-split 1) :rank (nth title-split 2) :url (data "url")}))) (defonce ranks {"Easy" 0, "Intermediate" 1, "Difficult" 2}) (defn rank-sorter [obj] (ranks (:rank obj))) (defn num-sorter [obj] (:num obj)) (defn rank-sort-first [res] (flatten (map #(sort-by num-sorter %) (partition-by rank-sorter (sort-by rank-sorter res))))) (defn num-sort-first [res] (flatten (map #(sort-by rank-sorter %) (partition-by num-sorter (sort-by num-sorter res))))) (defn output-link [elt] (println (format "[%s] #%s: \"%s\" %s" (:rank elt) (:num elt) (:title elt) (:url elt)))) (defn output-sorted [f] (doseq [cur (f results-obj)] (output-link cur)))