-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscript.rb
30 lines (22 loc) · 816 Bytes
/
script.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
require 'net/http'
require 'json'
require 'nokogiri'
old_shopify_stores = {}
(1..100).each do |shop_id|
url = URI.parse("https://checkout.shopify.com/#{shop_id}/sandbox/google_analytics_iframe")
response = Net::HTTP.get_response(url)
page_source = response.body
doc = Nokogiri::HTML(page_source)
allowlisted_urls = doc.css('#allowlistedUrls').attr('data-allowlistedurls')&.value
store_url = "Unavailable store"
if allowlisted_urls
urls = JSON.parse(allowlisted_urls)
store_url = urls.first
end
# Create an object with shopId as key and store URL as value
old_shopify_stores["#{shop_id}"] = store_url
end
# Convert the Ruby hash to JSON
old_shopify_stores_json = old_shopify_stores.to_json
puts "Old Shopify Stores (JSON):"
puts old_shopify_stores_json