Skip to content

Instantly share code, notes, and snippets.

@C37H40O9
Last active August 29, 2015 14:05
Show Gist options
  • Save C37H40O9/0cd4135959e9f79aa05e to your computer and use it in GitHub Desktop.
Save C37H40O9/0cd4135959e9f79aa05e to your computer and use it in GitHub Desktop.
Finds interesting questions for some stackoverflow member
require 'httparty'
require 'json'
def take_questions(user_id)
def rewrite(str)
str.gsub(/[#+]/, '#' => '%23', '+' => '%2b')
end
questions={}
api_url = 'https://api.stackexchange.com/2.2/'
site = 'stackoverflow'
tags_response = HTTParty.get(api_url+'users/'+user_id+'/top-answer-tags?page=1&pagesize=5&site=' + site)
top_tags = JSON.parse(tags_response.body)
top_tags["items"].each do |t|
questions_responce = HTTParty.get(api_url+'questions?page=1&pagesize=2&order=desc&sort=activity&tagged='+rewrite(t["tag_name"])+'&site=' + site)
links=[]
top_questions = JSON.parse(questions_responce.body)
top_questions["items"].each { |q| links.push(q["link"]) }
questions[t["tag_name"]] = links
end
return questions
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment