This repository has been archived by the owner on Sep 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from seatshare/feature/league-parser
League parser
- Loading branch information
Showing
4 changed files
with
78 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'nokogiri' | ||
|
||
# Arguments | ||
file = "#{ARGV[0]}" || nil | ||
|
||
if file.nil? || file == '' | ||
puts 'Usage: soda-league-directory path-to-file.xml' | ||
Kernel.exit(false) | ||
end | ||
|
||
unless File.exist? file | ||
puts 'File does not exist.' | ||
Kernel.exit(false) | ||
end | ||
|
||
File.open("#{ARGV[0]}", 'r') do |io| | ||
|
||
document = Nokogiri::XML(io) | ||
|
||
fail 'Invalid XML league directory.' unless document.is_a? Nokogiri::XML::Document | ||
|
||
output = [] | ||
|
||
entity_type = '' | ||
document.css('sports-content-codes sports-content-code[code-type="league"]').each do |sportscontentcode| | ||
entity_type = sportscontentcode['code-key'] | ||
end | ||
|
||
document.css('team').each do |team| | ||
|
||
row = {} | ||
|
||
team.css('team-metadata').each do |teammeta| | ||
row[:team_key] = teammeta['team-key'] | ||
team.css('name').each do |namemeta| | ||
row[:name] = namemeta['full'] | ||
end | ||
end | ||
|
||
output << row | ||
end | ||
|
||
final_output = [] | ||
# Export a create statement | ||
output.each do |team| | ||
next if ['', 'TBA'].include? team[:name].strip | ||
next if team[:team_key].strip == '' | ||
object = { | ||
import_key: team[:team_key], | ||
entity_name: team[:name], | ||
status: 1, | ||
entity_type: entity_type | ||
} | ||
final_output << object | ||
end | ||
|
||
puts final_output.to_s | ||
|
||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
## | ||
# SODA XML Team module | ||
module SodaXmlTeam | ||
VERSION = '1.3.1' | ||
VERSION = '1.4.0' | ||
end |