import urllib.request import json import base64 import time url_base_calc = "https://howdoyouconvert.com/wp-json/wp/v2/calculator/" url_base_kadence = "https://howdoyouconvert.com/wp-json/wp/v2/kadence_element/" creds = base64.b64encode(b"ben:6YGf wVxu gBpz pkqx BGZO lfVP").decode("utf-8") headers = { "Content-Type": "application/json", "Authorization": "Basic " + creds, "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)" } # --- BLUEPRINTS --- def get_text_ui(item): slug_raw = item['slug'].replace("-", "") return f"""
{item['seo_text']} """ def get_triple_ui(item): slug_raw = item['slug'].replace("-", "") return f"""

Enter any two values to calculate the third.

{item['seo_text']} """ # --- COMPLEX CALCULATOR DATA --- complex_items = [ { "title": "Binary to ASCII", "slug": "binary-to-ascii", "type": "textual", "label1": "Binary", "label2": "Text (ASCII)", "js_logic": """ function convert1() { let val = document.getElementById("input-1").value.replace(/\\s/g, ""); let text = ""; for (let i = 0; i < val.length; i += 8) { let byte = val.substr(i, 8); text += String.fromCharCode(parseInt(byte, 2)); } document.getElementById("input-2").value = text; } function convert2() { let val = document.getElementById("input-2").value; let binary = ""; for (let i = 0; i < val.length; i++) { let bin = val[i].charCodeAt(0).toString(2); binary += ("00000000" + bin).slice(-8) + " "; } document.getElementById("input-1").value = binary.trim(); } document.getElementById("input-1").addEventListener("input", convert1); document.getElementById("input-2").addEventListener("input", convert2); """, "seo_text": """

Binary to ASCII Conversion: Translate binary strings of 0s and 1s back into readable text. Each 8-bit sequence represents a specific character in the ASCII standard.

""" }, { "title": "Binary to Decimal", "slug": "binary-to-decimal", "type": "textual", "label1": "Binary", "label2": "Decimal", "js_logic": """ function convert1() { let val = document.getElementById("input-1").value.replace(/\\s/g, ""); document.getElementById("input-2").value = parseInt(val, 2).toString(10); } function convert2() { let val = document.getElementById("input-2").value; document.getElementById("input-1").value = parseInt(val, 10).toString(2); } document.getElementById("input-1").addEventListener("input", convert1); document.getElementById("input-2").addEventListener("input", convert2); """, "seo_text": """

Binary to Decimal: Quickly convert base-2 binary numbers into their base-10 decimal equivalents used in everyday mathematics.

""" }, { "title": "Binary to Hex", "slug": "binary-to-hex", "type": "textual", "label1": "Binary", "label2": "Hexadecimal", "js_logic": """ function convert1() { let val = document.getElementById("input-1").value.replace(/\\s/g, ""); document.getElementById("input-2").value = parseInt(val, 2).toString(16).toUpperCase(); } function convert2() { let val = document.getElementById("input-2").value; document.getElementById("input-1").value = parseInt(val, 16).toString(2); } document.getElementById("input-1").addEventListener("input", convert1); document.getElementById("input-2").addEventListener("input", convert2); """, "seo_text": """

Binary to Hex: Conversion between binary (base-2) and hexadecimal (base-16) is a fundamental skill in computing and low-level programming.

""" }, { "title": "Amps to Watts", "slug": "amps-to-watts", "type": "triple", "label1": "Current (Amps)", "label2": "Voltage (Volts)", "label3": "Power (Watts)", "js_logic": """ function solve() { let a = document.getElementById("input-1").value; let v = document.getElementById("input-2").value; let w = document.getElementById("input-3").value; if (a && v && !w) document.getElementById("input-3").value = (a * v).toFixed(2); else if (a && w && !v) document.getElementById("input-2").value = (w / a).toFixed(2); else if (v && w && !a) document.getElementById("input-1").value = (w / v).toFixed(2); } document.getElementById("input-1").addEventListener("input", solve); document.getElementById("input-2").addEventListener("input", solve); document.getElementById("input-3").addEventListener("input", solve); """, "seo_text": """

Amps to Watts: Use this calculator to find power (Watts) given current (Amps) and voltage (Volts). It works for DC and single-phase AC circuits.

""" }, { "title": "Amps to Kilowatts", "slug": "amps-to-kilowatts", "type": "triple", "label1": "Current (Amps)", "label2": "Voltage (Volts)", "label3": "Power (Kilowatts)", "js_logic": """ function solve() { let a = document.getElementById("input-1").value; let v = document.getElementById("input-2").value; let kw = document.getElementById("input-3").value; if (a && v && !kw) document.getElementById("input-3").value = (a * v / 1000).toFixed(3); else if (a && kw && !v) document.getElementById("input-2").value = (kw * 1000 / a).toFixed(2); else if (v && kw && !a) document.getElementById("input-1").value = (kw * 1000 / v).toFixed(2); } document.getElementById("input-1").addEventListener("input", solve); document.getElementById("input-2").addEventListener("input", solve); document.getElementById("input-3").addEventListener("input", solve); """, "seo_text": """

Amps to Kilowatts: Convert current to power in kilowatts. This calculator assumes a power factor of 1.0 (purely resistive load).

""" }, { "title": "Amps to kVA", "slug": "amps-to-kva", "type": "triple", "label1": "Current (Amps)", "label2": "Voltage (Volts)", "label3": "Apparent Power (kVA)", "js_logic": """ function solve() { let a = document.getElementById("input-1").value; let v = document.getElementById("input-2").value; let kva = document.getElementById("input-3").value; if (a && v && !kva) document.getElementById("input-3").value = (a * v / 1000).toFixed(3); else if (a && kva && !v) document.getElementById("input-2").value = (kva * 1000 / a).toFixed(2); else if (v && kva && !a) document.getElementById("input-1").value = (kva * 1000 / v).toFixed(2); } document.getElementById("input-1").addEventListener("input", solve); document.getElementById("input-2").addEventListener("input", solve); document.getElementById("input-3").addEventListener("input", solve); """, "seo_text": """

Amps to kVA: Calculate apparent power in kVA for single-phase electrical systems. Apparent power is the product of RMS voltage and current.

""" } ] # --- EXECUTION LOOP --- for item in complex_items: print(f"\\n--- Processing {item['title']} ---") if item['type'] == "textual": content_html = get_text_ui(item) elif item['type'] == "triple": content_html = get_triple_ui(item) calc_data = { "title": item['title'], "status": "publish", "slug": item['slug'], "content": content_html } req = urllib.request.Request(url_base_calc, data=json.dumps(calc_data).encode("utf-8"), headers=headers, method="POST") try: resp = urllib.request.urlopen(req, timeout=30) res = json.loads(resp.read().decode("utf-8")) post_id = res['id'] print(f"--> Posted Calculator (ID: {post_id})") js_wrapped = f"" kadence_data = { "title": f"JS Logic: {item['title']}", "status": "publish", "content": js_wrapped, "meta": { "_kad_element_hook": "kadence_after_header", "_kad_element_show_conditionals": json.dumps([{"rule": "singular|calculator", "select": "ids", "ids": [post_id], "mustMatch": False}]) } } req_j = urllib.request.Request(url_base_kadence, data=json.dumps(kadence_data).encode("utf-8"), headers=headers, method="POST") resp_j = urllib.request.urlopen(req_j, timeout=30) print(f"--> Posted JS Hook") except Exception as e: print(f"Error: {e}") if hasattr(e, 'read'): print(e.read().decode('utf-8')) time.sleep(1)