Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Chernyi committed Mar 26, 2019
0 parents commit c0777c5
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.gem
7 changes: 7 additions & 0 deletions Makefile
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

28 changes: 28 additions & 0 deletions README.md
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
```

23 changes: 23 additions & 0 deletions jekyll-wowdaily.gemspec
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
1 change: 1 addition & 0 deletions lib/jekyll-wowdaily.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require File.expand_path('jekyll/commands/wowdaily.rb', __dir__)
81 changes: 81 additions & 0 deletions lib/jekyll/commands/wowdaily.rb
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

0 comments on commit c0777c5

Please sign in to comment.