61 lines
1.8 KiB
Python
61 lines
1.8 KiB
Python
import urllib.request
|
|
import json
|
|
import base64
|
|
import time
|
|
import re
|
|
|
|
url_base_kadence = "https://howdoyouconvert.com/wp-json/wp/v2/kadence_element"
|
|
url_base_calc = "https://howdoyouconvert.com/wp-json/wp/v2/calculator"
|
|
creds = base64.b64encode(b"ben:6YGf wVxu gBpz pkqx BGZO lfVP").decode("utf-8")
|
|
headers = {
|
|
"Authorization": "Basic " + creds,
|
|
"User-Agent": "Mozilla/5.0"
|
|
}
|
|
|
|
def get_all(url):
|
|
results = []
|
|
page = 1
|
|
while True:
|
|
req = urllib.request.Request(f"{url}?per_page=100&page={page}", headers=headers)
|
|
try:
|
|
resp = urllib.request.urlopen(req, timeout=30)
|
|
data = json.loads(resp.read().decode("utf-8"))
|
|
if not data: break
|
|
results.extend(data)
|
|
page += 1
|
|
except:
|
|
break
|
|
return results
|
|
|
|
print("Fetching all calculators...")
|
|
calcs = get_all(url_base_calc)
|
|
calc_map = {c['id']: c['slug'] for c in calcs}
|
|
|
|
print("Fetching all elements...")
|
|
elements = get_all(url_base_kadence)
|
|
|
|
mapping = []
|
|
for e in elements:
|
|
meta = e.get('meta', {})
|
|
cond = meta.get('_kad_element_show_conditionals', '')
|
|
if cond:
|
|
try:
|
|
cond_data = json.loads(cond)
|
|
if isinstance(cond_data, list) and len(cond_data) > 0:
|
|
ids = cond_data[0].get('ids', [])
|
|
for pid in ids:
|
|
if pid in calc_map:
|
|
mapping.append({
|
|
'eid': e['id'],
|
|
'pid': pid,
|
|
'slug': calc_map[pid],
|
|
'title': e['title']['rendered']
|
|
})
|
|
except:
|
|
continue
|
|
|
|
with open("/tmp/element_mapping.json", "w") as f:
|
|
json.dump(mapping, f, indent=2)
|
|
|
|
print(f"Found {len(mapping)} mappings.")
|