program-tv 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cdd826e88236e4397312508d2281c44dbfb4ce78
4
- data.tar.gz: 4369235cebee6af25943fe94ccd1cb7b4350d387
3
+ metadata.gz: 11ad4f25b58b9672f4774ca2521d46f01cf81f15
4
+ data.tar.gz: 6fb5c11984c2096528e30e2c2347226c0df554a9
5
5
  SHA512:
6
- metadata.gz: 415971534ac63f85bf06855d7b34b537f3d6d0978e210767ec63131c3eb10d740b09671a1baf61e60bfba919d8a3b1759c25e0db2e1ef3c66d65f68f4ceb86e7
7
- data.tar.gz: 7bc7c87c47261aad47ab497a83c30c42015fcf818a442e8199d352bd55d585079d59072d7631fc75384725c2875cd63784e5e04733b41a5c37baa81139babcef
6
+ metadata.gz: 7682ef5601e90399f4a30277b720bfd56d59dcb7aef2f298f6a279323d33d41b41d433218d6bc96539919ec1052c3a728b46171ae49e7bc22996bda20a597caf
7
+ data.tar.gz: d6d3cb6c68020b8a1f3d8864cca328ad79e8e69e0bd2c19191cb591e5a9b384675ecc141b9d6b3cba9d06b8536da260bc5c2a3072b4c379ac23a28f766e74ced
data/bin/program-tv CHANGED
@@ -5,7 +5,7 @@ $LOAD_PATH.push File.expand_path("../lib", File.dirname(__FILE__)) # add library
5
5
  require 'program-tv'
6
6
  require 'optparse'
7
7
 
8
- options = {}
8
+ options = { :destination => '/home/hosting/tvo/epg/' }
9
9
  OptionParser.new do |op|
10
10
  op.banner = <<-eos
11
11
  #{ProgramTV::DESCRIPTION}
@@ -27,6 +27,10 @@ OptionParser.new do |op|
27
27
  op.on("-c", "--channel-list PATH", "path to yml channel list") do |path|
28
28
  options[:channel_list] = path
29
29
  end
30
+
31
+ op.on("-d", "--destination PATH", "directory with EPG XML files") do |path|
32
+ options[:destination] = path
33
+ end
30
34
  end.parse!
31
35
 
32
36
  begin
data/channels.yml CHANGED
@@ -19,11 +19,11 @@ polsat-biznes : polsatbiznes
19
19
  jim-jam-polsat : polsatjimjam
20
20
  polsat-sport : polsatsport
21
21
  polsat-sport-news : polsatsportnews
22
- puls : puls
22
+ tv-puls : puls
23
23
  puls-2 : puls2
24
24
  rbl.tv : rbltv
25
25
  russia-today : russiatoday
26
- stars-tv : starstv
26
+ stars.tv : starstv
27
27
  tele-5 : tele5
28
28
  ttv : ttv
29
29
  tv-4 : tv4
@@ -10,7 +10,7 @@ module ProgramTV
10
10
  def run
11
11
  ProgramTV.selected_channels.map do |url_name, epg_name|
12
12
  schedule(epg_name, "http://www.cyfrowypolsat.pl/program-tv/#{url_name}")
13
- end
13
+ end.compact
14
14
  end
15
15
 
16
16
  private
@@ -24,6 +24,10 @@ module ProgramTV
24
24
  title: e.css('.name').text
25
25
  }
26
26
  end
27
+ if data.empty?
28
+ puts "Missing schedule for channel #{epg_name}"
29
+ return
30
+ end
27
31
  data[0..-2].each_with_index{ |element, i| element[:end] = data[i+1][:start] }
28
32
  data.pop
29
33
  data
@@ -1,24 +1,46 @@
1
1
  require 'builder'
2
+ require 'pry'
3
+ require_relative 'hash_helper'
2
4
 
3
5
  module ProgramTV
4
6
  class Writer
5
7
 
6
- def initialize(data)
8
+ def initialize(data, destination)
7
9
  @data = data
8
- @xml = Builder::XmlMarkup.new( :indent => 2 )
9
- @xml.instruct! :xml, :encoding => "UTF-8"
10
+ @destination = destination
10
11
  end
11
12
 
12
- # Runs dynamic-sprites command.
13
- #
14
13
  def run
15
- @xml.tv do |tv|
16
- @data.flatten.each do |element|
14
+ @data.each do |schedule|
15
+ today_schedule = []
16
+ if File.exist?(xml_path(schedule))
17
+ File.open(xml_path(schedule), "r+") do |file|
18
+ today_schedule = Hash.from_xml(file.read)[:tv][:programme]
19
+ end
20
+ end
21
+ File.open(xml_path(schedule), "w+") do |file|
22
+ file.write(build_xml(today_schedule + schedule))
23
+ end
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def xml_path(schedule)
30
+ File.join(@destination, "#{schedule.first[:channel]}.xml")
31
+ end
32
+
33
+ # Builds XML data from schedule Hash
34
+ def build_xml(schedule)
35
+ xml_builder = Builder::XmlMarkup.new( :indent => 2 )
36
+ xml_builder.instruct! :xml, :encoding => "UTF-8"
37
+ xml_builder.tv do |tv|
38
+ schedule.each do |program|
17
39
  tv.programme do |p|
18
- p.title element[:title]
19
- p.channel element[:channel]
20
- p.start element[:start]
21
- p.end element[:end]
40
+ p.title program[:title]
41
+ p.channel program[:channel]
42
+ p.start program[:start]
43
+ p.end program[:end]
22
44
  end
23
45
  end
24
46
  end
data/lib/program-tv.rb CHANGED
@@ -2,7 +2,7 @@ module ProgramTV
2
2
 
3
3
  #----------------------------------------------------------------------------
4
4
 
5
- VERSION = "0.0.3"
5
+ VERSION = "0.0.4"
6
6
  SUMMARY = "TV Channel parser"
7
7
  DESCRIPTION = "Downloads TV channel list in XML format"
8
8
 
@@ -18,7 +18,7 @@ module ProgramTV
18
18
  def self.run!(options = {})
19
19
  @@options = options
20
20
  data = Parser.new.run
21
- puts Writer.new(data).run
21
+ Writer.new(data, @@options[:destination]).run
22
22
  end
23
23
 
24
24
  private
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: program-tv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Walusiak