248 lines
11 KiB
Python
248 lines
11 KiB
Python
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)"
|
|
}
|
|
|
|
batch_6 = [
|
|
{
|
|
"title": "Grams to Apothecary Ounces",
|
|
"slug": "grams-to-apothecary-ounces",
|
|
"label1": "Grams (g)",
|
|
"label2": "Apothecary Ounces (ap oz)",
|
|
"factor": 0.0321507466,
|
|
"offset": 0,
|
|
"seo_text": """
|
|
<!-- wp:paragraph -->
|
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Weight Conversion:</strong> Apothecary ounces were historically used by pharmacists and chemists to measure ingredients for medicine. This calculator provides a precise conversion to standard metric grams.</p>
|
|
<!-- /wp:paragraph -->
|
|
"""
|
|
},
|
|
{
|
|
"title": "Grams to Carats",
|
|
"slug": "grams-to-carats",
|
|
"label1": "Grams (g)",
|
|
"label2": "Carats (ct)",
|
|
"factor": 5.0,
|
|
"offset": 0,
|
|
"seo_text": """
|
|
<!-- wp:paragraph -->
|
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Jewelry Weight:</strong> The metric carat is defined as exactly 200 milligrams. Converting grams to carats is standard practice in the gemstone industry for pricing and weight measurement.</p>
|
|
<!-- /wp:paragraph -->
|
|
"""
|
|
},
|
|
{
|
|
"title": "Grams to Grains",
|
|
"slug": "grams-to-grains",
|
|
"label1": "Grams (g)",
|
|
"label2": "Grains (gr)",
|
|
"factor": 15.4323584,
|
|
"offset": 0,
|
|
"seo_text": """
|
|
<!-- wp:paragraph -->
|
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Fine Weight:</strong> One gram is equivalent to approximately 15.43 grains. Grains are used in various specialized fields, including the measurement of gunpowder and certain medications.</p>
|
|
<!-- /wp:paragraph -->
|
|
"""
|
|
},
|
|
{
|
|
"title": "Horsepower to Kilowatts",
|
|
"slug": "horsepower-to-kilowatts",
|
|
"label1": "Horsepower (hp)",
|
|
"label2": "Kilowatts (kW)",
|
|
"factor": 0.745699872,
|
|
"offset": 0,
|
|
"seo_text": """
|
|
<!-- wp:paragraph -->
|
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Power Measurement:</strong> Horsepower is a unit used to measure the power of engines and motors. Converting to kilowatts (the SI unit) allows for easier comparison across different engineering standards.</p>
|
|
<!-- /wp:paragraph -->
|
|
"""
|
|
},
|
|
{
|
|
"title": "Hours to Days",
|
|
"slug": "hours-to-days",
|
|
"label1": "Hours",
|
|
"label2": "Days",
|
|
"factor": 0.0416666667,
|
|
"offset": 0,
|
|
"seo_text": """
|
|
<!-- wp:paragraph -->
|
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Time Management:</strong> There are exactly 24 hours in one day. This tool facilitates the conversion of hourly task durations or logistical windows into full day equivalents.</p>
|
|
<!-- /wp:paragraph -->
|
|
"""
|
|
},
|
|
{
|
|
"title": "Hours to Minutes",
|
|
"slug": "hours-to-minutes",
|
|
"label1": "Hours",
|
|
"label2": "Minutes",
|
|
"factor": 60.0,
|
|
"offset": 0,
|
|
"seo_text": """
|
|
<!-- wp:paragraph -->
|
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Quick Time Math:</strong> Converting hours into minutes is one of the most common everyday calculations for scheduling, travel, and logistics.</p>
|
|
<!-- /wp:paragraph -->
|
|
"""
|
|
},
|
|
{
|
|
"title": "Inches of Mercury to Pascals",
|
|
"slug": "inches-of-mercury-to-pascals",
|
|
"label1": "Inches of Mercury (inHg)",
|
|
"label2": "Pascals (Pa)",
|
|
"factor": 3386.389,
|
|
"offset": 0,
|
|
"seo_text": """
|
|
<!-- wp:paragraph -->
|
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Pressure Conversion:</strong> Inches of mercury is a unit for pressure used in meteorology and aviation. Converting to pascals (the SI unit) is necessary for various scientific and atmospheric calculations.</p>
|
|
<!-- /wp:paragraph -->
|
|
"""
|
|
},
|
|
{
|
|
"title": "Inches of Water to Pascals",
|
|
"slug": "inches-of-water-to-pascals",
|
|
"label1": "Inches of Water (inH2O)",
|
|
"label2": "Pascals (Pa)",
|
|
"factor": 249.08891,
|
|
"offset": 0,
|
|
"seo_text": """
|
|
<!-- wp:paragraph -->
|
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>HVAC & Fluid Dynamics:</strong> Inches of water column (WC) is a unit commonly used in low-pressure applications like ventilation and plumbing systems. One inch of water is approximately 249 pascals.</p>
|
|
<!-- /wp:paragraph -->
|
|
"""
|
|
},
|
|
{
|
|
"title": "Inches to Centimeters",
|
|
"slug": "inches-to-centimeters",
|
|
"label1": "Inches (in)",
|
|
"label2": "Centimeters (cm)",
|
|
"factor": 2.54,
|
|
"offset": 0,
|
|
"seo_text": """
|
|
<!-- wp:paragraph -->
|
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Metric Precision:</strong> The international inch is defined as exactly 2.54 centimeters. This converter is used daily for manufacturing, design, and education worldwide.</p>
|
|
<!-- /wp:paragraph -->
|
|
"""
|
|
},
|
|
{
|
|
"title": "Inches to Millimeters",
|
|
"slug": "inches-to-millimeters",
|
|
"label1": "Inches (in)",
|
|
"label2": "Millimeters (mm)",
|
|
"factor": 25.4,
|
|
"offset": 0,
|
|
"seo_text": """
|
|
<!-- wp:paragraph -->
|
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Fine Precision:</strong> Millimeters offer a finer grain of measurement for technical drawings and engineering. One inch equals exactly 25.4 millimeters.</p>
|
|
<!-- /wp:paragraph -->
|
|
"""
|
|
}
|
|
]
|
|
|
|
for item in batch_6[4:]:
|
|
print(f"\\n--- Processing {item['title']} ---")
|
|
|
|
slug_raw = item['slug'].replace("-", "")
|
|
content_html = f"""
|
|
<!-- wp:kadence/rowlayout {{"uniqueID":"{item['slug']}_outer","bgColor":"#f5f7f9","padding":["2rem","2rem","2rem","2rem"],"borderRadius":["8px","8px","8px","8px"]}} -->
|
|
<div class="wp-block-kadence-rowlayout alignnone"><div class="kt-row-column-wrap kt-has-1-columns kt-row-layout-equal kt-tab-layout-inherit kt-mobile-layout-row kt-row-valign-top" style="background-color:#f5f7f9;border-radius:8px;padding:2rem;">
|
|
|
|
<!-- wp:kadence/column {{"uniqueID":"{item['slug']}_inner"}} -->
|
|
<div class="wp-block-kadence-column"><div class="kt-inside-inner-col">
|
|
|
|
<style>.kb-row-layout-id_{slug_raw}_row > .kt-row-column-wrap{{align-content:start;}}:where(.kb-row-layout-id_{slug_raw}_row > .kt-row-column-wrap) > .wp-block-kadence-column{{justify-content:start;}}.kb-row-layout-id_{slug_raw}_row > .kt-row-column-wrap{{column-gap:var(--global-kb-gap-md, 2rem);row-gap:var(--global-kb-gap-md, 2rem);max-width:600px;margin-left:auto;margin-right:auto;grid-template-columns:repeat(2, minmax(0, 1fr));}}.kb-row-layout-id_{slug_raw}_row > .kt-row-layout-overlay{{opacity:0.30;}}@media all and (max-width: 1024px){{.kb-row-layout-id_{slug_raw}_row > .kt-row-column-wrap{{grid-template-columns:repeat(2, minmax(0, 1fr));}}}}@media all and (max-width: 767px){{.kb-row-layout-id_{slug_raw}_row > .kt-row-column-wrap{{grid-template-columns:minmax(0, 1fr);}}}}</style><div class="kb-row-layout-wrap kb-row-layout-id_{slug_raw}_row aligncenter wp-block-kadence-rowlayout"><div class="kt-row-column-wrap kt-has-2-columns kt-row-layout-equal kt-tab-layout-inherit kt-mobile-layout-row kt-row-valign-top">
|
|
<div class="wp-block-kadence-column kadence-column_{slug_raw}_col1"><div class="kt-inside-inner-col">
|
|
<label for="input-1" style="font-weight: 600; color: #333333; margin-bottom: 8px; display: block;">{item['label1']}</label>
|
|
<input type="number" id="input-1" class="calc-input" placeholder="0" style="width:100%; padding: 12px; border: 1px solid #ccc; border-radius: 4px; font-size: 1.2rem;">
|
|
</div></div>
|
|
<div class="wp-block-kadence-column kadence-column_{slug_raw}_col2"><div class="kt-inside-inner-col">
|
|
<label for="input-2" style="font-weight: 600; color: #333333; margin-bottom: 8px; display: block;">{item['label2']}</label>
|
|
<input type="number" id="input-2" class="calc-input" placeholder="0" style="width:100%; padding: 12px; border: 1px solid #ccc; border-radius: 4px; font-size: 1.2rem;">
|
|
</div></div></div></div>
|
|
|
|
</div></div>
|
|
<!-- /wp:kadence/column -->
|
|
</div></div>
|
|
<!-- /wp:kadence/rowlayout -->
|
|
|
|
{item['seo_text']}
|
|
"""
|
|
|
|
calc_data = {
|
|
"title": item['title'],
|
|
"status": "publish",
|
|
"slug": item['slug'],
|
|
"content": content_html,
|
|
"format": "standard"
|
|
}
|
|
|
|
# Post Calculator
|
|
req_c = urllib.request.Request(url_base_calc, data=json.dumps(calc_data).encode("utf-8"), headers=headers, method="POST")
|
|
try:
|
|
resp_c = urllib.request.urlopen(req_c, timeout=30)
|
|
res_c = json.loads(resp_c.read().decode("utf-8"))
|
|
post_id = res_c['id']
|
|
print(f"--> Posted {item['title']} (ID: {post_id})")
|
|
|
|
# JS Logic with robust event handling
|
|
offset = item.get('offset', 0)
|
|
js_wrapped = f"""<script>
|
|
(function() {{
|
|
function init() {{
|
|
var i1 = document.getElementById("input-1");
|
|
var i2 = document.getElementById("input-2");
|
|
if (!i1 || !i2) {{
|
|
if (window.r < 50) {{
|
|
window.r++;
|
|
setTimeout(init, 100);
|
|
}}
|
|
return;
|
|
}}
|
|
i1.oninput = function() {{
|
|
var v = parseFloat(i1.value);
|
|
if (isNaN(v)) {{ i2.value = ""; return; }}
|
|
i2.value = parseFloat((v * {item['factor']} + {offset}).toFixed(8));
|
|
}};
|
|
i2.oninput = function() {{
|
|
var v = parseFloat(i2.value);
|
|
if (isNaN(v)) {{ i1.value = ""; return; }}
|
|
i1.value = parseFloat(((v - {offset}) / {item['factor']}).toFixed(8));
|
|
}};
|
|
var p = new URLSearchParams(window.location.search);
|
|
if (p.has('v1')) {{ i1.value = p.get('v1'); i1.oninput(); }}
|
|
else if (p.has('v2')) {{ i2.value = p.get('v2'); i2.oninput(); }}
|
|
}}
|
|
window.r = 0;
|
|
init();
|
|
}})();
|
|
</script>"""
|
|
|
|
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")
|
|
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)
|
|
|
|
print("\\n--- BATCH 6 COMPLETE ---")
|