App-Open-Source-per-iPhone-.../.github/osia_update_github.rb

38 lines
758 B
Ruby
Raw Normal View History

2016-05-16 19:29:04 +02:00
require_relative 'osia_helper'
2016-05-12 19:17:28 +02:00
require 'octokit'
require 'netrc'
client = Octokit::Client.new(:netrc => true)
2016-05-16 19:29:04 +02:00
j = get_json
2016-05-12 19:17:28 +02:00
apps = j['projects']
updated = []
apps.each_with_index do |a, index|
2016-05-12 19:17:28 +02:00
s = a['source']
if s.nil?
updated.push a
elsif !(s.include? 'github')
updated.push a
else
print "#{index+1}/#{apps.count}\n"
2016-05-12 19:17:28 +02:00
begin
g = s.gsub('https://github.com/', '')
r = client.repo g
a['stars'] = r['stargazers_count']
a['updated'] = r['pushed_at']
2016-05-12 19:17:28 +02:00
updated.push a
rescue => e
puts "\nerror for #{s}: #{e}"
updated.push a
next
end
end
end
j['projects'] = updated
File.open(FILE, 'w') { |f| f.write JSON.pretty_generate(j) }
puts "\nUpdated #{FILE} ⭐️"