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_ 1 1 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 1 2 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_ 1 1 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.
3
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:
model:
3
u/domlebo70 1 2 Jan 10 '13 edited Jan 10 '13
Great challenge. Scala makes this a breeze: https://gist.github.com/4499070
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 0 2 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.
Full output: http://pastebin.com/pdVChTZx
2
u/eagleeye1 0 1 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.
Output: 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. :(
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:
2
u/Glassfish 0 0 Jan 09 '13
It is a bit messy, i'll try to improve it tomorrow
Scala:
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.
2
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:
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:
2
u/rya11111 3 1 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:
1
u/PoppySeedPlehzr 1 0 Jan 10 '13
Finally! I feel like this took me waaay too long. Sorry for the late submission, I ended up with 305 total challenges.
Python:
1
u/DangerousDuck Jan 12 '13
My solution in python. It gets most of them, but has some troubles with the first solutions because of different formats that didn't match my regexp. You could make a more forgiving solution if you'd match each part you needed seperatly.
1
u/beginners-mind 0 0 Jan 23 '13 edited Jan 23 '13
My solution in clojure. I am still in the early stages of learning clojure so if anyone more knowledgeable than myself runs across this and feels like commenting that would be appreciated. Here is my full output This was a fun puzzle, keep up the good work and keep them coming!
1
u/deds_the_scrub Mar 10 '13
Late to the party, but I just found this subreddit a few days ago. Here's my solution in python. Some of those early challenges made it a little tricky.
http://pastebin.com/9t6XiEWS
0
u/[deleted] Jan 09 '13
[deleted] — view deleted comment