Skip to content

@tekkub /ldb_ace_relate.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
#!/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 ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.