Files
HowDoYouConvert/batch_2.py

293 lines
23 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_2_remaining = [
{
"title": "Becquerel to Curie",
"slug": "becquerel-to-curie",
"label1": "Becquerels (Bq)",
"label2": "Curies (Ci)",
"factor": 2.7027027e-11,
"method1": "multiply",
"seo_text": """
<!-- wp:paragraph -->
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Understanding Becquerel and Curie:</strong> The becquerel and the curie represent two vastly different historical epochs in the measurement of radioactive decay and ionizing particle emissions. Today, the becquerel (Bq) reigns as the supreme and undisputed SI derived unit of ionizing radioactivity. It is famously named for Henri Becquerel, the pioneer who shared a Nobel Prize with the Curies for his historic discovery of radioactivity. A becquerel defines an extraordinarily minute quantity of radiation; precisely one singular nucleus decaying per one absolute second.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p style="line-height: 1.6;">The curie (Ci) stands as one of the original, non-SI radiological units historically embraced by mid-century atomic scientists and early theoretical physicists. Developed directly as a tribute to Pierre Curie, the unit originally attempted to quantify the total number of radiological disintegrations occurring rapidly within one isolated gram of the element Radium-226. Due to the astonishingly high radioactive profile of Radium-226, an individual curie represents a shockingly macroscopic and dangerous cascade of radioactive decay compared to modern SI measurements.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p style="line-height: 1.6;"><strong>The Conversion Process:</strong> Linking the incredibly minuscule modern becquerel back to the massive, mid-century curie requires handling astronomical strings of exponential values. By modern standardized definition, exactly 37 billion becquerels are required to generate exactly one curie of radioactivity. Therefore, to translate from a becquerel baseline into the curie legacy standard, the becquerel value must be multiplied by 2.7027 x 10<sup>-11</sup> (or strictly divided by 37,000,000,000). Evaluating curies backwards into an SI becquerel count requires multiplying the curie parameter by 37,000,000,000.</p>
<!-- /wp:paragraph -->
"""
},
{
"title": "Becquerel to Rutherford",
"slug": "becquerel-to-rutherford",
"label1": "Becquerels (Bq)",
"label2": "Rutherfords (Rd)",
"factor": 0.000001,
"method1": "multiply",
"seo_text": """
<!-- wp:paragraph -->
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Understanding Becquerel and Rutherford:</strong> The becquerel and the rutherford are distinct units utilized to quantify the decay rate and disintegrations of radioactive isotopes. The becquerel (Bq) constitutes the universally accepted cornerstone of the modern SI metric system regarding radiological events. A single becquerel is defined strictly as the activity of a radioactive material in which exactly one nucleus visibly and energetically decays per measured second. Because this rate represents a microscopic snapshot, scientists frequently log environmental radioactive hazards in immense kilobecquerel aggregates.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p style="line-height: 1.6;">The rutherford (Rd), conversely, is a largely obsolete non-SI unit historically proposed in the mid-1940s to act as a more manageable bridge between the impractically small becquerel and the dangerously immense curie. Dedicated to the legendary atomic physicist Ernest Rutherford—credited with discovering both alpha and beta radioactive particles—the unit isolates a more noticeable swath of isotopic disintegration. Namely, one exact rutherford acts as a proxy measurement for a continuous one million nuclear decays per second.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p style="line-height: 1.6;"><strong>The Conversion Process:</strong> Transitioning between these two units is remarkably straightforward due to their shared base-10 numerical foundation surrounding atomic degradation timeframes. A single rutherford encompasses exactly one million becquerels. Because of this linear structure, scaling a microscopic becquerel measurement up into its macro rutherford equivalent requires you to multiply the becquerel value by exactly 0.000001 (or subsequently divide by 1,000,000). Resolving back down from rutherfords into a modern SI becquerel rating requires multiplying the rutherford by one million.</p>
<!-- /wp:paragraph -->
"""
},
{
"title": "Bits to Bytes",
"slug": "bits-to-bytes",
"label1": "Bits (b)",
"label2": "Bytes (B)",
"factor": 0.125,
"method1": "multiply",
"seo_text": """
<!-- wp:paragraph -->
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Understanding Bits and Bytes:</strong> The bit and the byte form the foundational digital alphabet powering all modern computing systems, telecommunications, and digital memory storage. A single bit—shorthand for a "binary digit"—is the absolute smallest possible increment of data a computer architecture can physically recognize. It represents a strict binary state of logical truth, existing explicitly as either a 0 or a 1, a true or false, or an on or off electrical signal.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p style="line-height: 1.6;">The byte, on the other hand, acts as the primary grouping mechanism for these disparate binary signals, bridging raw electrical states into manageable structural data like text or integers. Originally formulated to encompass the exact number of bits required to encode a single character of text on a mainframe computer, a byte eventually standardized cross-platform as an arbitrary string composed of exactly eight distinct bits, commonly referred to as an octet.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p style="line-height: 1.6;"><strong>The Conversion Process:</strong> Shifting computational measurements between base bits and structured bytes relies upon the rigid division of eight. Because telecom systems historically quantify bandwidth velocities in raw bits per second (Mbps), while hard-drive manufacturers tally aggregate mass storage exclusively in bytes (MB/GB), this calculation acts as a daily consumer necessity. To establish the byte structure of an underlying bit-stream, multiply the bit value by 0.125 (or simply divide by 8). Reversing course to find foundational bit requirements from a byte layout requires multiplying the bytes by exactly 8.</p>
<!-- /wp:paragraph -->
"""
},
{
"title": "BTU to Kilojoules",
"slug": "btu-to-kilojoules",
"label1": "British Thermal Units (BTU)",
"label2": "Kilojoules (kJ)",
"factor": 1.05505585,
"method1": "multiply",
"seo_text": """
<!-- wp:paragraph -->
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Understanding BTU and Kilojoules:</strong> The British thermal unit (BTU) and the kilojoule (kJ) are classic measurements bridging thermal engineering methodologies across the Atlantic. The BTU occupies a pivotal position within the United States customary system for measuring raw, sensible heat and ambient energy transfer. It was originally theorized as the exact volume of raw heat required to elevate the temperature of one singular pound of pure water by precisely one degree Fahrenheit at sea level.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p style="line-height: 1.6;">Conversely, the kilojoule acts as a direct, scaled multiplier of the international standard joule, anchoring all metric computations regarding thermal heating, kinetic velocity, and dietary metabolic energy. A single joule embodies the absolute energy forcibly transferred when applying one newton through the absolute distance of one meter. By aggregating this into a thousand, the kilojoule creates an immensely practical macro-measurement spanning everything from structural thermodynamics to the caloric evaluation of food rations.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p style="line-height: 1.6;"><strong>The Conversion Process:</strong> The mathematical bridge correlating legacy imperial HVAC systems and modern SI thermodynamics involves a highly specific, static ratio. The International Table definitively equates one British thermal unit to exactly 1,055.05585 joules, or roughly 1.055 kilojoules. To successfully port a BTU heat capacity specification into its SI kilojoule equivalent, one must invariably multiply the BTU figure by this 1.05505585 scalar. Formulating backwards to determine the underlying legacy BTU output demands the kilojoule metric be divided against that identical constant.</p>
<!-- /wp:paragraph -->
"""
},
{
"title": "BTU/hour to Watts",
"slug": "btuhour-to-watts",
"label1": "BTU per hour (BTU/hr)",
"label2": "Watts (W)",
"factor": 0.293071,
"method1": "multiply",
"seo_text": """
<!-- wp:paragraph -->
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Understanding BTU/hr and Watts:</strong> The BTU per hour and the watt constitute essential metrics for measuring the continuous rate of energy exertion, electrical power production, and industrial heat transferring. The BTU per hour establishes an imperial velocity for sensible heat. Representing the total amount of British thermal units generated or absorbed within an isolated 60-minute window, it serves as the ubiquitous power rating label adorning almost every single air conditioning condenser, furnace, and boiler operating within the United States.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p style="line-height: 1.6;">In stark contrast, the watt (W) serves as the supreme international standardized SI unit for active power scaling. Universally equivalent to the forceful exertion of one raw joule per one absolute second, the watt governs the international output capacity formulas for electric motors, lighting grids, audio amplification arrays, and all major European HVAC system diagnostics. It fundamentally defines how fast a system actively siphons or emits physical energy across the space-time continuum.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p style="line-height: 1.6;"><strong>The Conversion Process:</strong> Comparing the thermal cooling power of American HVAC components against standardized European electrical power draws necessitates locking these continuous output rates into a mathematical formula. Scientifically, generating a singular, steady Watt of active electrical power continuously outputs about 3.41214 BTUs of residual heat energy every hour. To extract a metric Watt equivalency from an American BTU/hr HVAC datasheet rating, multiply the hourly BTUs by a fractional 0.293071 multiplier. Returning an electrical Watt rating back down to an imperial hourly thermal estimate requires multiplying the Watts by exactly 3.41214.</p>
<!-- /wp:paragraph -->
"""
},
{
"title": "Calories to Joules",
"slug": "calories-to-joules",
"label1": "Calories (cal)",
"label2": "Joules (J)",
"factor": 4.184,
"method1": "multiply",
"seo_text": """
<!-- wp:paragraph -->
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Understanding Calories and Joules:</strong> The gram calorie and the joule serve as essential baseline metrics quantifying the production of energy, mechanical power transfers, and chemical heat reactions. The small calorie (often distinctly stylized with a lowercase 'c') traces its origins strictly back to historical physics laboratories. It reflects the finite, calculated volume of raw thermal energy necessary to actively elevate the ambient temperature of one singular gram of water by a single degree Celsius.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p style="line-height: 1.6;">The joule (J), however, eclipsed the small calorie upon the final codification of the modern SI metric system. Universally revered across all modern scientific disciplines as the gold standard of energy computation, the joule represents a remarkably specific mechanical event: the energy physically expended when applying a solitary newton of directional force against an object through exactly one longitudinal meter. It serves as the baseline variable for all higher-level formulas dictating velocity, tension, and kinetic impact.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p style="line-height: 1.6;"><strong>The Conversion Process:</strong> Linking the historical thermal parameters of the small gram calorie to the rigorously defined modern joule relies entirely on the established framework of the "thermochemical calorie" constant. International chemistry standards currently dictate that one single calorie comprises precisely 4.184 mechanical joules of underlying energy. Thus, scaling a small calorie readout into the universal joule standard demands a simple mathematical multiplication of the calorie count by 4.184. Transcribing joules back downward into antiquated thermal calories requires dividing the target joule figure by 4.184.</p>
<!-- /wp:paragraph -->
"""
},
{
"title": "Calories to Kilojoules",
"slug": "calories-to-kilojoules",
"label1": "Kilocalories / Large Calories (kcal)",
"label2": "Kilojoules (kJ)",
"factor": 4.184,
"method1": "multiply",
"seo_text": """
<!-- wp:paragraph -->
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Understanding Kilocalories and Kilojoules:</strong> The kilocalorie and the kilojoule act as the predominant global units dictating human dietary mathematics and mass-scale nutritional metabolic assessments. The kilocalorie (frequently mislabeled simply as a 'Calorie' with a legally mandated capital 'C' on nutritional labels) acts as a structural multiple containing exactly 1,000 small historical thermal calories. It technically quantifies the total biochemical heat expenditure required to raise a full kilogram of raw water by exactly one degree Celsius.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p style="line-height: 1.6;">Across the international community, however, the dietary food energy stored within chemical macromolecules like complex carbohydrates, synthetic fats, and raw proteins is uniformly labeled under the kilojoule (kJ) parameter. Functioning as a multiple containing 1,000 standard SI joules of mechanical energy, the kilojoule ensures human metabolic biology scales cleanly inline with broader universal standards dictating thermal heating outputs and heavy mechanical kinetic impacts.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p style="line-height: 1.6;"><strong>The Conversion Process:</strong> The mathematical relationship tightly binding the dietary kilocalorie logic of the Americas to the global kilojoule standard mirrors the ratio connecting their smaller foundational roots. Because a standard thermochemical kilocalorie is precisely recognized as 4,184 foundational joules, there are exactly 4.184 kilojoules bound inside a single dietary kilocalorie. To port a nutritional kilocalorie readout from an American product label into its metric kilojoule designation, multiply the kilocalories by 4.184. To resolve backwards against the formulation and find kilocalories, reliably divide the kilojoules value by 4.184.</p>
<!-- /wp:paragraph -->
"""
}
]
for item in batch_2_remaining:
print(f"\n--- Constructing UI Block for {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"><style>.kadence-column_{slug_raw}_col1 > .kt-inside-inner-col,.kadence-column_{slug_raw}_col1 > .kt-inside-inner-col:before{{border-top-left-radius:0px;border-top-right-radius:0px;border-bottom-right-radius:0px;border-bottom-left-radius:0px;}}.kadence-column_{slug_raw}_col1 > .kt-inside-inner-col{{column-gap:var(--global-kb-gap-sm, 1rem);flex-direction:column;}}.kadence-column_{slug_raw}_col1 > .kt-inside-inner-col > .aligncenter{{width:100%;}}.kadence-column_{slug_raw}_col1 > .kt-inside-inner-col:before{{opacity:0.3;}}.kadence-column_{slug_raw}_col1{{position:relative;}}</style>
<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 calc-field" onclick="clearPlaceholder('input-1')" placeholder="0" style="width:100%; padding: 12px; border: 1px solid #ccc; border-radius: 4px; font-size: 1.2rem;">
<input type="hidden" id="factor-1" name="factor-1" value="{item['factor']}"></div></div><style>.kadence-column_{slug_raw}_col2 > .kt-inside-inner-col,.kadence-column_{slug_raw}_col2 > .kt-inside-inner-col:before{{border-top-left-radius:0px;border-top-right-radius:0px;border-bottom-right-radius:0px;border-bottom-left-radius:0px;}}.kadence-column_{slug_raw}_col2 > .kt-inside-inner-col{{column-gap:var(--global-kb-gap-sm, 1rem);flex-direction:column;}}.kadence-column_{slug_raw}_col2 > .kt-inside-inner-col > .aligncenter{{width:100%;}}.kadence-column_{slug_raw}_col2 > .kt-inside-inner-col:before{{opacity:0.3;}}.kadence-column_{slug_raw}_col2{{position:relative;}}</style>
<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 calc-field" onclick="clearPlaceholder('input-2')" 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",
"comment_status": "closed",
"ping_status": "closed"
}
# Post the calculator
req_c = urllib.request.Request(url_base_calc, data=json.dumps(calc_data).encode("utf-8"), headers=headers, method="POST")
post_id = None
try:
resp_c = urllib.request.urlopen(req_c, timeout=30)
r_json = json.loads(resp_c.read().decode("utf-8"))
post_id = r_json['id']
print(f"--> Posted {item['title']} (ID: {post_id})")
except Exception as e:
print("Error creating calculator:", e)
if hasattr(e, 'read'): print(e.read().decode('utf-8'))
continue
# Setup the JavaScript Kadence Element hook for calculating logic + URL variables
if item['method1'] == "multiply":
math_1_line = f"let val2 = val1 * {item['factor']};"
math_2_line = f"let val1 = val2 / {item['factor']};"
else:
math_1_line = f"let val2 = val1 / {item['factor']};"
math_2_line = f"let val1 = val2 * {item['factor']};"
js_code = f"""
<script>
function calculate1() {{
let val1 = document.getElementById("input-1").value;
if(val1 === "") {{
document.getElementById("input-2").value = "";
return;
}}
{math_1_line}
document.getElementById("input-2").value = val2;
}}
function calculate2() {{
let val2 = document.getElementById("input-2").value;
if(val2 === "") {{
document.getElementById("input-1").value = "";
return;
}}
{math_2_line}
document.getElementById("input-1").value = val1;
}}
document.getElementById("input-1").addEventListener("input", calculate1);
document.getElementById("input-2").addEventListener("input", calculate2);
window.addEventListener('DOMContentLoaded', (event) => {{
const urlParams = new URLSearchParams(window.location.search);
const v1 = urlParams.get('v1');
const v2 = urlParams.get('v2');
if (v1 !== null && !isNaN(v1)) {{
document.getElementById("input-1").value = v1;
calculate1();
}} else if (v2 !== null && !isNaN(v2)) {{
document.getElementById("input-2").value = v2;
calculate2();
}}
}});
</script>
"""
kadence_data = {
"title": f"JS Logic: {item['title']}",
"status": "publish",
"slug": f"js-logic-{item['slug']}",
"content": js_code,
"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")
try:
resp_j = urllib.request.urlopen(req_j, timeout=30)
j_data = json.loads(resp_j.read().decode("utf-8"))
print(f"--> Posted JS hook (Element ID: {j_data['id']})")
item['element_id'] = j_data['id']
item['post_id'] = post_id
except Exception as e:
print("Error creating JS Element:", e)
if hasattr(e, 'read'): print(e.read().decode('utf-8'))
time.sleep(1)
print("\n--- BATCH 2 REMAINING COMPLETE SUMMARY ---")
for x in batch_2_remaining:
if "post_id" in x:
print(f"{x['title']} | Post: {x['post_id']} | JS: {x['element_id']} | Factor: {x['factor']}")