Created
November 1, 2014 19:56
-
-
Save seanrankin/211d3fae3cb4ceee17f1 to your computer and use it in GitHub Desktop.
A ruby script to query the github search api that returns the most active public repos. Takes start and end dates, GH event name, and # of records.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "optparse" | |
options = {:after => nil, :before => nil, :event => nil, :count => nil} | |
parser = OptionParser.new do|opts| | |
opts.banner = "Usage: gh_repo_stats --after AFTER_DATE --before BEFORE_DATE --event EVENT_NAME --count NUMBER_OF_RECORDS" | |
opts.on('-a', '--after after', 'After') do |after| | |
options[:after] = after; | |
end | |
opts.on('-b', '--before before', 'Before') do |before| | |
options[:before] = before; | |
end | |
opts.on('-e', '--event event', 'Event') do |event| | |
options[:event] = event; | |
end | |
opts.on('-c', '--count count', 'Count') do |count| | |
options[:count] = count; | |
end | |
opts.on('-h', '--help', 'Displays Help') do | |
puts opts | |
exit | |
end | |
end | |
parser.parse! | |
if options[:after] == nil | |
print 'Enter start date in YYYY-MM-DD format: ' | |
options[:after] = gets.chomp | |
end | |
if options[:before] == nil | |
print 'Enter end date in YYYY-MM-DD format: ' | |
options[:before] = gets.chomp | |
end | |
if options[:event] == nil | |
print 'Enter an event (like push or c): ' | |
options[:before] = gets.chomp | |
end | |
if options[:count] == nil | |
print 'How many records do you want to return? ' | |
options[:before] = gets.chomp | |
end | |
puts `curl -G -s https://api.github.com/search/repositories \ | |
--data-urlencode 'q=created:#{options[:after]}..#{options[:before]}' \ | |
--data-urlencode 'per_page=#{options[:count]}' \ | |
--data-urlencode 'sort=stars' \ | |
--data-urlencode 'order=desc' \ | |
| jq '.items[] | .name' -r` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice! Have you ever played with Thor? It's a great gem for building command-line tools in Ruby. Would cut the size of this code in half at least.