This repository has been archived by the owner on Jun 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
/
Rakefile
101 lines (88 loc) · 3.02 KB
/
Rakefile
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# encoding: utf-8
require 'rubygems'
require 'bundler'
begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts "Run `bundle install` to install missing gems"
exit e.status_code
end
require 'rake'
require 'jeweler'
Jeweler::Tasks.new do |gem|
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference for more options
gem.name = 'swot'
gem.homepage = 'https://github.com/leereilly/swot'
gem.license = 'MIT'
gem.summary = 'Identify email addresses or domains names that belong to colleges or universities.'
gem.description = 'Identify email addresses or domains names that belong to colleges or universities. Help automate the process of approving or rejecting academic discounts.'
gem.email = 'lee@leereilly.net'
gem.authors = ['Lee Reilly']
gem.required_ruby_version = Gem::Requirement.new('>= 2.0')
gem.files.exclude *%w(.gitignore .travis.yml .ruby-version)
gem.test_files = gem.files.grep(/^test/)
# dependencies defined in Gemfile
end
Jeweler::RubygemsDotOrgTasks.new
require 'rake/testtask'
Rake::TestTask.new(:test) do |test|
test.libs << 'lib' << 'test'
test.pattern = 'test/**/test_*.rb'
test.verbose = true
end
task :default => :test
require 'rdoc/task'
Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
rdoc.rdoc_dir = 'rdoc'
rdoc.title = "swot #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
task :add, :sld, :tld, :name do |t, args|
file_path = "#{File.expand_path(__FILE__+'/..')}/lib/domains/#{args.tld}/#{args.sld}"
if File.exists?(file_path)
puts "already exists"
elsif
begin
FileUtils.mkdir_p(File.dirname(file_path))
File.open( file_path, "w" ) do |contents|
contents.print args.name
end
`git add #{file_path}`
`git commit -m "Add #{args.name}"`
puts "commit successful"
rescue
puts "commit failed"
end
end
end
task :quackit_import do
require 'nokogiri'
require 'open-uri'
require_relative File.join('lib', 'swot', 'academic_tlds')
new_domains = Set.new
doc = Nokogiri::HTML(open('http://www.quackit.com/domain-names/country_domain_extensions.cfm'))
doc.css('#content li').each do |li|
desc = li.content.split(/\s+-\s+/, 2)[1]
if desc =~ /academic|education|school/i
domain_el = li.at_css('b')
# some lines have more than one domain listed
domains = domain_el.content.split(/\s*\/\s*/)
domains.each do |domain|
# remove leading space
domain = domain.strip.sub(/\A\./, '')
unless Swot::ACADEMIC_TLDS.include?(domain)
# print out for manual review
puts "#{domain} - #{desc.strip.gsub(/\s+/, ' ')}"
new_domains << domain
end
end
end
end
puts "\nNEW DOMAINS (#{new_domains.size}):\n\n"
new_domains.each do |domain|
puts domain
end
end