-
Notifications
You must be signed in to change notification settings - Fork 15
/
update.rb
executable file
·67 lines (50 loc) · 1.31 KB
/
update.rb
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env ruby -w
require 'open-uri'
def say(message)
puts message
message
end
def sh(*args)
command = args.join(' ')
debug("$ #{command}")
stdout = `#{command}`
debug(stdout)
stdout
end
def debug(message)
say message if DEBUG
end
TLDFILE = File.expand_path('../../.tmp/tlds.txt', __FILE__)
DEBUG = true
DATE = Time.now.strftime('%Y-%m-%d')
sh "git pull origin master"
File.open(TLDFILE, "w+") { |f| f.write(URI.open('https://data.iana.org/TLD/tlds-alpha-by-domain.txt').read) }
if File.read(TLDFILE).empty?
abort("TLD list is empty")
end
stored_tlds = Dir.glob("[A-Z0-9]*").to_a
active_tlds = File.read(TLDFILE).split("\n").select { |line| line =~ /^[A-Z0-9]+/ }
removed_tlds = stored_tlds - active_tlds
removed_tlds.each do |tld|
message = "Delete #{tld} (#{DATE})"
sh "git rm #{tld}"
sh "git add #{tld}"
sh "git commit -m '#{message}'"
end
active_tlds.each do |tld|
newtld = !File.exist?(tld)
message = newtld ? "Create #{tld} (#{DATE})" : "Update #{tld} (#{DATE})"
sh "touch #{tld}"
sh "whois -h whois.iana.org #{tld} > #{tld}"
# reset invalid updates
if File.size(tld) == 0
sh "git checkout #{tld}"
end
status = sh "git status -s"
unless status.empty?
sh "git add #{tld}"
sh "git commit -m '#{message}'"
end
sleep(3)
end
sh "git push origin master"