-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rb
49 lines (40 loc) · 1.43 KB
/
main.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
require 'watir'
switches = %W[--user-data-dir=tmp/chrome-profile/]
b = Watir::Browser.new :chrome, switches: switches
NATION = ENV['NB_NATION']
EMAIL = ENV['NB_USER']
PASSWORD = ENV['NB_PASS']
TAG_PATTERNS_TO_DELETE = [
/temp/i
]
tag_ids = []
begin
b.goto "https://#{NATION}.nationbuilder.com/login"
b.text_field(label: 'Email Address').set(EMAIL)
b.text_field(label: 'Password').set(PASSWORD)
b.button(text: 'Sign in with email').click
sleep 2
# b.goto "https://#{NATION}.nationbuilder.com/admin/signup_tags/new"
# total_tags = b.div(class: 'total-found').text.match(/([\d,]+)$/)[1] rescue 1
# pages = (total_tags.gsub(/,/,'').to_i / 50.0).ceil # they show 50 tags per page
# tag_ids = []
# (1..pages).to_a.reverse.each do |page_number|
# b.goto "https://#{NATION}.nationbuilder.com/admin/signup_tags/new?page=#{page_number}"
# tags = b.links(href: /tag_id/, text: Regexp.union(TAG_PATTERNS_TO_DELETE))
# tag_ids << tags.map(&:href).map{|u| u.match(/=(\d+)/)[1] }
# end
# tag_ids.flatten!
# puts "about to delete #{tag_ids.length} tags"
# printf "=> press 'y' to continue: "
# prompt = STDIN.gets.chomp
# exit unless prompt == 'y'
tag_ids.each do |tag_id|
b.goto "https://#{NATION}.nationbuilder.com/admin/signup_tags/#{tag_id}/edit" rescue next
b.button(text: 'Delete tag').click rescue next
b.link(text: 'Delete tag').click rescue next
end
rescue Exception => e
puts e
ensure
b.quit
end