public
Last active

  • Download Gist
ldb_ace_relate.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
#!/usr/bin/env ruby
 
 
############################################################################################
### For this script to work, you need to save your wowace api key into ~/.wowace_key ###
############################################################################################
 
 
require "net/http"
 
 
class WowAce
def initialize
@api_key = File.read(File.expand_path(File.join("~", ".wowace_key"))).gsub(/\n/, "")
@http = Net::HTTP.start("www.wowace.com")
end
 
def tokenize(path)
path + "?api-key=#{@api_key}"
end
 
def get(path)
@http.get(tokenize(path))
end
 
def urlencode(str)
str.gsub(/[^a-zA-Z0-9_\.\-]/n) {|s| sprintf('%%%02x', s[0]) }
end
 
def post_form(path, params)
req = Net::HTTP::Post.new(tokenize(path))
req.body = params.map {|k,v| "#{urlencode(k.to_s)}=#{urlencode(v.to_s)}" }.join('&')
req.content_type = 'application/x-www-form-urlencoded'
@http.request req
end
 
def update_relationships(path, relationship, name)
$stdout << "."
$stdout.flush
 
res = get(path)
return if res.body =~ /libdatabroker/
 
$stdout << "\nUpdating #{relationship} relationships on #{name}"
$stdout.flush
res = post_form(path, {
"form_type" => "add",
"repository" => "libdatabroker-1-1",
"type" => "e",
})
end
end
 
 
$stdout << "Checking LibDataBroker relationships"
$stdout.flush
 
ace = WowAce.new
 
Dir["*/.git"].map {|d| d.gsub("/.git", "")}.each do |repo|
config = File.read(File.join(repo, ".git", "config")) rescue nil
next if config.nil? || !(config =~ /(wowace|curseforge)/) || Dir[repo+"/**/LibDataBroker-1.1.lua"].empty?
 
ace.update_relationships("/addons/#{repo.downcase}/repositories/mainline/edit-default-relationships/", "default", repo)
 
res = ace.get("/addons/#{repo.downcase}/files/")
(full_match, first_file, file_name) = res.body.match(/<td class="col-file"><a href="(.*?)">(.*?)<\/a><\/td>/).to_a
next if full_match.nil?
ace.update_relationships(first_file+"edit-relationships/", "file", "#{repo} #{file_name}")
next if file_name =~ /Release/
 
(full_match, first_file, file_name) = res.body.match(/<td class="col-file"><a href="(.*?)">(.*?\-Release)<\/a><\/td>/).to_a
next if full_match.nil?
ace.update_relationships(first_file+"edit-relationships/", "file", "#{repo} #{file_name}")
end
 
puts ""

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.