• Facepunch API
    437 replies, posted
Ever?
Currently working on some sort of Ruby API/Library sort of thing for FP. [code] #!/usr/bin/env ruby require 'rubygems' require 'open-uri' require 'nokogiri' require 'json' Board = Class.new do def initialize(id) @id = id.to_s end def getThreads() doc = Nokogiri::HTML(open("http://facepunch.com/forumdisplay.php?f=" + @id)) threads = Array.new doc.css("//a[@class='title']").each do |thread| #Get ID (<3 Text2re.com) id = thread["href"] re1='.*?' re2='(\\d+)' re = re1 + re2 m=Regexp.new(re,Regexp::IGNORECASE); id=m.match(id)[1]; #Get thread title title = thread.content #Get replies count replies_element = doc.xpath('//*[@id="thread_' + id + '"]/td[4]/a')[0] replies = replies_element.content #Get view count views_element = doc.xpath('//*[@id="thread_' + id + '"]/td[5]/span')[0] views = views_element.content #Get OP op_element = doc.xpath('//*[@id="thread_' + id +'"]/td[2]/div/div[2]/div/a[1]')[0] op = op_element.content #Get thread icon name threadicon_element = doc.xpath('//*[@id="thread_' + id + '"]/td[1]/img')[0] threadicon = threadicon_element["alt"] #Check if is sticky is_sticky_element = doc.xpath('//*[@id="thread_' + id + '"]')[0]["class"] if is_sticky_element.include? 'nonsticky' is_sticky = false else is_sticky = true end #Add to array threads.push( :id=>id, :title=>title, :op=>op, :replies=>replies, :views=>views, :threadicon=>threadicon, :is_sticky=>is_sticky ) end return threads end end #Test b = Board.new(64) t = b.getThreads() json = t.to_json puts json [/code] returns [code] [{"id":"1058260","title":"The Rules: No Gore/Death/Fights/Cruelty/Porn AND how to properly post a video","op":"garry","replies":"1","views":"14,234","threadicon":"","is_sticky":true},{"id":"1317920","title":"Best Video Game Music (videogamedunkey)","op":"ProffesorAssHat","replies":"0","views":"1","threadicon":"games","is_sticky":false},{"id":"1317913","title":"Famous YouTuber (Joey Graceffa) gets towed, bitches about it. Guy who towed him makes hilarious response video","op":"FlandersNed","replies":"6","views":"216","threadicon":"Humor","is_sticky":false},{"id":"1311831","title":"Cinemassacre Monster Madness 2013 &#147;Sequel-A-Thon 2&#8243;","op":"Nintendo-Guy","replies":"70","views":"4,721","threadicon":"Movies","is_sticky":false},{"id":"1250111","title":"Two best friends play thread V2: The hypest thread on Facepunch","op":"kapin_krunch","replies":"3,749","views":"156,185","threadicon":"YouTUBE","is_sticky":false},{"id":"1317741","title":"Assassin's Creed IV: Black Flag Launch Trailer","op":"Gimme20dollaz","replies":"10","views":"316","threadicon":"games","is_sticky":false},{"id":"1317713","title":"Ladies and gentleman Meet...the ipad air!","op":"matty928","replies":"36","views":"1,219","threadicon":"News","is_sticky":false},{"id":"1317589","title":"Watch the video the New York Times didn't Want You to See","op":"Vasili","replies":"30","views":"1,303","threadicon":"Politics","is_sticky":false},{"id":"1257280","title":"Game Grumps - We Like Steam Train Now","op":"Gimme20dollaz","replies":"5,909","views":"337,439","threadicon":"games","is_sticky":false},{"id":"1317754","title":"\"Lick My Ass\" -- Mozart's Greatest Masterpiece","op":"PelPix123","replies":"11","views":"933","threadicon":"Humor","is_sticky":false},{"id":"1317870","title":"Porsche 911 sings Happy Birthday","op":"Spectre1406","replies":"4","views":"300","threadicon":"Music","is_sticky":false},{"id":"1317819","title":"Lucky Firefighters Take Bricks To The Head And Survive","op":"Zambies!","replies":"7","views":"422","threadicon":"Art","is_sticky":false},{"id":"1317615","title":"Battlefield 4: Single Player Story Trailer","op":"Gimme20dollaz","replies":"47","views":"1,482","threadicon":"games","is_sticky":false},{"id":"1317309","title":"2 N0SC0P3 A /\\/\\0CK1/\\/GB1RD [Rest in piece dog :(]","op":"Doritos-pope","replies":"43","views":"2,524","threadicon":"Humor","is_sticky":false},{"id":"1247782","title":"Retsupurae Thread","op":"latin_geek","replies":"576","views":"43,812","threadicon":"games","is_sticky":false},{"id":"1317732","title":"Remember that guy who took a bath in nettles?...well this time his trick didn't go to plan","op":"matty928","replies":"65","views":"2,661","threadicon":"Humor","is_sticky":false},{"id":"1317891","title":"Jeremy Kyle: How to be a good parent in 2009","op":"benbb","replies":"1","views":"211","threadicon":"Humor","is_sticky":false},{"id":"1317747","title":"Homeless Pizza Party","op":"zin908","replies":"13","views":"755","threadicon":"Love","is_sticky":false},{"id":"1317860","title":"Hardcore EDM Dance Band!","op":"Foxtrot200","replies":"1","views":"178","threadicon":"Art","is_sticky":false},{"id":"1317771","title":"L.A. BEAST vs 60 REESE'S PEANUT BUTTER CUPS","op":"angrykid8","replies":"24","views":"767","threadicon":"Gross","is_sticky":false},{"id":"1317329","title":"Sony Playstation - For The players Since 1995","op":"CubeManv2","replies":"152","views":"4,749","threadicon":"Art","is_sticky":false},{"id":"1316664","title":"H7N9 Avian influenza","op":"Djnova","replies":"6","views":"558","threadicon":"YouTUBE","is_sticky":false},{"id":"1317859","title":"Sneaky Cat's Curiosity Results In Startling Surprise Ending","op":"shian","replies":"0","views":"179","threadicon":"Humor","is_sticky":false},{"id":"1317837","title":"Gangsta Swimmin'","op":"I R A Pizza","replies":"3","views":"254","threadicon":"YouTUBE","is_sticky":false},{"id":"1317723","title":"Fallout: Nuka Break - Season 2 Trailer","op":"HazzaHardie","replies":"13","views":"523","threadicon":"YouTUBE","is_sticky":false},{"id":"1316794","title":"Best videoclip ever, \"so good you won't even notice you're listening to srillex\"","op":"Djessey","replies":"26","views":"2,347","threadicon":"Stupid","is_sticky":false},{"id":"1312022","title":"WTF Is... - Day One: Garry's Incident?","op":"VietRooster2","replies":"90","views":"7,861","threadicon":"Rant","is_sticky":false},{"id":"1317470","title":"Plugging a PS4 Controller into a PS3","op":"Sonic Fan","replies":"13","views":"1,263","threadicon":"ps3","is_sticky":false},{"id":"1317772","title":"Ylvis- Massachusetts","op":"Clovernoodle","replies":"6","views":"494","threadicon":"Humor","is_sticky":false},{"id":"1316622","title":"CoD: SammyClassicSonicFan Edition","op":"Vinyl Indent","replies":"33","views":"1,193","threadicon":"YouTUBE","is_sticky":false},{"id":"1317675","title":"Star Citizen Anvil Aerospace Hornet Commercial","op":"Ilwrath","replies":"19","views":"696","threadicon":"pc games","is_sticky":false},{"id":"1317827","title":"Oderus Urungus (GWAR) reads Good Night Moon","op":"MercZ","replies":"1","views":"140","threadicon":"Humor","is_sticky":false},{"id":"1317656","title":"How to Go Trick-or-Treating as an Adult","op":"Rammaster","replies":"3","views":"786","threadicon":"Humor","is_sticky":false},{"id":"1317739","title":"Parents Catch Son Smoking Weed Will On TEAMSPEAK!","op":"Operation115","replies":"95","views":"1,950","threadicon":"YouTUBE","is_sticky":false},{"id":"1317818","title":"Extreme Tree Hugger Rage!","op":"munchito696","replies":"0","views":"226","threadicon":"YouTUBE","is_sticky":false},{"id":"1317807","title":"Teenage Mutant Nigga Turtles - Episode 1","op":"Zenreon117","replies":"0","views":"198","threadicon":"beta","is_sticky":false},{"id":"1317794","title":"TEXAS Republican Judge Switches to Democratic Party","op":"Smug Bastard","replies":"2","views":"244","threadicon":"Love","is_sticky":false},{"id":"1314352","title":"360 No Scope Your Stuff","op":"Fish_poke","replies":"28","views":"2,545","threadicon":"Science","is_sticky":false},{"id":"1317758","title":"GHOST BURGER (Leehardcastle)","op":"THATCAKEISASPY","replies":"5","views":"337","threadicon":"Humor","is_sticky":false},{"id":"1317759","title":"Time Hates You","op":"Dacheet","replies":"4","views":"327","threadicon":"Rant","is_sticky":false},{"id":"1317360","title":"So it turns out in Portal 1 you can spawn in Half Life citizens and they automatically join your \"squad\", I decided to see how far I could take one through the test chambers","op":"Andaeeee","replies":"15","views":"2,718","threadicon":"games","is_sticky":false}] [/code]
Cool, I'm working on something similar for Java (mostly parsing), to be used in Android. It is slower than the API was though, but it'll do for now.
I'll write up the C++ alternative.
Sorry for the bump, but I thought I'd inform everybody that Facepunch now has (and has had for a while) it's own API used by [URL="http://lab.facepunch.com"]Labpunch.[/URL] Here's some stuff I found: Parameters can be GET or POST The API returns JSON. With [code]{"status":"ok",data:{}}[/code] if the request was successful and [code]{"status":"failure","message":"","varname":"","reason":""}[/code] if the request was unsuccessful. It uses [URL="https://github.com/garrynewman/katniss"]https://github.com/garrynewman/katniss[/URL], which is really great. If you want to explore it, here's some URLs I found. [B]Listing Boards In Categories[/B] [url]http://lab.facepunch.com/api/forum/list/?[/url] Parameters: None [B]Listing threads in a board[/B] [url]http://lab.facepunch.com/api/thread/list?forumid=394[/url] Parameters: forumid (required) + page [B]Listing posts in a thread[/B] [url]http://lab.facepunch.com/api/thread/list?[/url] Parameters: forumid (required) + page Example: [url]http://lab.facepunch.com/api/thread/list?forumid=394[/url] [B]Logging In[/B] [url]http://lab.facepunch.com/api/user/login[/url] Parameters: username + password [B]Posting a thread[/B] [url]http://lab.facepunch.com/api/author/thread[/url] Parameters: forumid, contents, title, _t _t is the user token returned when the user logs in with correct details. [B]Posting a post[/B] [url]http://lab.facepunch.com/api/author/post[/url] Parameters: threadid, contents, _t _t is the user token returned when the user logs in with correct details.
[QUOTE=Coffeee;44079613]Sorry for the bump, but I thought I'd inform everybody that Facepunch now has (and has had for a while) it's own API used by [URL="http://lab.facepunch.com"]Labpunch.[/URL][/QUOTE] Listing posts in a thread should be http://lab.facepunch.com/api/post/list?threadid={thread_number}&page={page_number} . Also bear in mind that Labpunch doesn't have ratings yet and the content of posts is returned as BBCode (which means you have to parse it yourself).
Something that would be extremely nice is some form of machine readable self-documentation. The uniform success/error mode is already great for consuming the API transparently, but if there was a way of listing the type info for requests and returned data then you could automatically get an updated native representation where supported or generate one. The parameter info is already available serverside through the katniss configuration, so it seems it would be relatively easy to make it available. I don't have much hopes for a full return value spec... It's good that there is the [code]"forum":{"forumid":240,"title":"Programming","numthreads":3982,"postsperpage":30,"threadsperpage":20}[/code] bit for example though, that means at least no numeric constants. There's also a live post feed: [code]http://lab.facepunch.com/api/feed/fetch/?time=[int?][/code] Calling it without a time or [URL="http://lab.facepunch.com/api/feed/fetch/?time=0&fmt=html"]time=0[/URL] gives you the 100 newest posts, if you specify a time I think it will only return posts made after that. The main page calls this about every 1.5 seconds to update the thread listing.
Well this is interesting, the labpunch api allows people to reply to topics in the refugee camp. Garry fix it!
Welp, now he can post in there legitimately.
Orkel banned ZombieWizzard for 7 Days in <3 with the reason “fp exploits (fixing ban length)” lol seriously
That exploit has been known for a good while now, they didn't need any more people exploiting it. It didn't help that he used it more than once.
Geel9's Facepunch app is looking really good. It's a shame he can't add many features due to the shortcomings in the labpunch api.
Sorry, you need to Log In to post a reply to this thread.