-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata-update
executable file
·48 lines (39 loc) · 1.07 KB
/
data-update
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'rubygems'
require 'bundler/setup'
require 'fileutils'
require 'html2rss'
require 'html2rss/configs'
require 'uri'
require 'yaml'
file_names = Html2rss::Configs.file_names.sort
def valid_url(url)
!!URI(url)
rescue StandardError
false
end
def string_formatting_references(string)
string.to_s.scan(/%[{<](\w+)[>}](\w)?/).to_h.transform_values do |value|
case value
when 'i', 'd', 'u'
Numeric
else
String
end
end
end
output = file_names.map do |file_name|
config = YAML.safe_load(File.open(file_name), symbolize_names: false)
file_name_splits = file_name.split('/')
{
'domain' => file_name_splits[-2..-2].join,
'name' => File.basename(file_name_splits[-1..].join, '.*'),
'valid_channel_url' => valid_url(config['channel']['url']),
'url_parameters' => string_formatting_references(config['channel']['url']),
'channel' => config['channel']
}
end
config_file = File.join(__dir__, '..', '_data/configs.yml')
FileUtils.touch config_file
File.write(config_file, output.to_yaml)