-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nikita Chernyi
committed
Mar 26, 2019
0 parents
commit c0777c5
Showing
6 changed files
with
141 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.gem |
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,7 @@ | ||
build: | ||
rm -f ./*.gem | ||
gem build jekyll-wowdaily.gemspec | ||
|
||
push: | ||
gem push ./*.gem | ||
|
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,28 @@ | ||
# Warcraft daily data parser for Jekyll | ||
|
||
[![Gem Version](https://badge.fury.io/rb/jekyll-wowdaily.svg)](https://badge.fury.io/rb/jekyll-wowdaily) | ||
|
||
[Live Example](https://forestguild.club/) (Russian) - plugin built specially for this website | ||
|
||
Data parsed from [Wowhead](https://wowhead.com) block "Today in WoW" | ||
|
||
## Configuration | ||
|
||
Add following block to your jekyll config (`_config.yml`) | ||
|
||
```yml | ||
wowdaily: | ||
region: eu # Region code | ||
lang: ru # Wowhead language code | ||
``` | ||
## Usage | ||
```bash | ||
# If you set all configs in site config file: | ||
jekyll wowdaily # check _data/attendance_lang_region.json | ||
|
||
# If you want to set custom config | ||
jekyll wowdaily --help | ||
``` | ||
|
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,23 @@ | ||
Gem::Specification.new do |s| | ||
s.name = 'jekyll-wowdaily' | ||
s.version = '1.0.0' | ||
s.date = '2018-11-29' | ||
s.summary = "WoW Daily from wowhead" | ||
s.description = "Parse 'Today in WoW' data from Wowhead to jekyll's data file" | ||
s.authors = ["Nikita Chernyi"] | ||
s.email = '[email protected]' | ||
s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR).grep(%r!^lib/!) | ||
s.require_paths = %w(lib) | ||
s.homepage = 'https://github.com/rakshazi/jekyll-wowdaily' | ||
s.license = 'MIT' | ||
s.metadata = { | ||
"bug_tracker_uri" => "https://github.com/rakshazi/jekyll-wowdaily", | ||
"changelog_uri" => "https://github.com/rakshazi/jekyll-wowdaily/releases", | ||
"documentation_uri" => "https://github.com/rakshazi/jekyll-wowdaily/blob/master/README.md", | ||
"homepage_uri" => "https://github.com/rakshazi/jekyll-wowdaily", | ||
"source_code_uri" => "https://github.com/rakshazi/jekyll-wowdaily", | ||
} | ||
s.required_ruby_version = '>=2.0.0' | ||
s.add_runtime_dependency 'jekyll', '~> 3.8.5', '>=3.0.0' | ||
s.add_runtime_dependency 'nokogiri', '~> 1.10.1', '>=1.0.0' | ||
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
require File.expand_path('jekyll/commands/wowdaily.rb', __dir__) |
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,81 @@ | ||
require "nokogiri" | ||
require "open-uri" | ||
require "yaml" | ||
module Jekyll | ||
module Commands | ||
class Wowdaily < Command | ||
class << self | ||
def getFactionByCss(css_class) | ||
case css_class | ||
when "icon-horde" | ||
return "horde" | ||
when "icon-alliance" | ||
return "alliance" | ||
else | ||
return "horde-alliance" | ||
end | ||
end | ||
def init_with_program(prog) | ||
prog.command(:wowdaily) do |c| | ||
c.syntax "wowdaily [options]" | ||
c.option "region", "--region REGION", "Region code, eg: eu" | ||
c.option "lang", "--lang LANG", "Language code, eg: ru, en" | ||
c.description "Grab WoW Daily info from wowhead" | ||
c.action do |args, options| | ||
# Options | ||
options = getConfig(options) | ||
# Init empty | ||
worldboss = {} | ||
wowtoken = 0 | ||
holidays = [] | ||
islandexpeditions = [] | ||
emissares = [] | ||
|
||
# Grab data | ||
Jekyll.logger.info 'Grabbing data in ' + options['lang'] + ' language for ' + options['region'] + ' region...' | ||
doc = Nokogiri::HTML(open("https://" + options['lang'] + ".wowhead.com/")).css(".tiw-region-" + options['region'].upcase) | ||
|
||
# Parse it | ||
Jekyll.logger.info "Parsing..." | ||
doc.css(".tiw-group-epiceliteworldbfa").css("span").css("a").each do |a| | ||
worldboss = {"name": a.text,"url": "https://" + options['lang'] + ".wowhead.com" + a.get_attribute("href")} | ||
end | ||
doc.css(".tiw-group-wowtoken").css(".moneygold").each do |gold| | ||
wowtoken = gold.text.gsub(",","").to_i | ||
end | ||
doc.css(".tiw-group-holiday").css("span").css("a").each do |a| | ||
holiday = {"name" => a.text, | ||
"url" => "https://" + options['lang'] + ".wowhead.com" + a.get_attribute("href"), | ||
"fraction" => getFactionByCss(a.parent.get_attribute("class"))} | ||
holidays.push(holiday) | ||
end | ||
doc.css(".tiw-group-islandexpeditions").css("td.icon-both").css("a").each do |a| | ||
expedition = {"name" => a.text, "url" => "https://" + options['lang'] + ".wowhead.com" + a.get_attribute("href")} | ||
islandexpeditions.push(expedition) | ||
end | ||
doc.css(".tiw-group-emissary7").css("td").css("a").each do |a| | ||
emissar = {"name" => a.text, | ||
"url" => "https://" + options['lang'] + ".wowhead.com" + a.get_attribute("href"), | ||
"fraction" => getFactionByCss(a.parent.get_attribute("class"))} | ||
emissares.push(emissar) | ||
end | ||
data = {"worldboss": worldboss, "wowtoken": wowtoken,"holidays": holidays,"islandexpeditions":islandexpeditions,"emissares":emissares} | ||
|
||
File.write(options['data_dir'] + "/wowdaily_" + options['lang'] + "_" + options['region'] + ".json", data.to_json) | ||
end | ||
end | ||
end | ||
def getConfig(options) | ||
config = Jekyll.configuration({}) | ||
options['data_dir'] = File.expand_path(config['data_dir']) | ||
['lang', 'region'].each do |key| | ||
if (config['wowdaily'].key? key) === true | ||
options[key] = config['wowdaily'][key] | ||
end | ||
end | ||
options | ||
end | ||
end | ||
end | ||
end | ||
end |