feat: Add batch processing scripts for complex calculator creation and verification, and update the calculator list.
This commit is contained in:
292
batch_2.py
Normal file
292
batch_2.py
Normal file
@@ -0,0 +1,292 @@
|
|||||||
|
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']}")
|
||||||
258
batch_3.py
Normal file
258
batch_3.py
Normal file
@@ -0,0 +1,258 @@
|
|||||||
|
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_3 = [
|
||||||
|
{
|
||||||
|
"title": "Carats to Grams",
|
||||||
|
"slug": "carats-to-grams",
|
||||||
|
"label1": "Carats (ct)",
|
||||||
|
"label2": "Grams (g)",
|
||||||
|
"factor": 0.2,
|
||||||
|
"offset": 0,
|
||||||
|
"seo_text": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Understanding Carats and Grams:</strong> The carat is a unit of mass used for measuring gemstones and pearls. One carat is defined as exactly 200 milligrams (0.2 grams). The gram is the base unit of mass in the metric system.</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Celsius to Fahrenheit",
|
||||||
|
"slug": "celsius-to-fahrenheit",
|
||||||
|
"label1": "Celsius (°C)",
|
||||||
|
"label2": "Fahrenheit (°F)",
|
||||||
|
"factor": 1.8,
|
||||||
|
"offset": 32,
|
||||||
|
"seo_text": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Celsius and Fahrenheit Scales:</strong> These two temperature scales are the most commonly used worldwide. Celsius is part of the metric system, while Fahrenheit is primarily used in the United States and some Caribbean territories.</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Centimeters to Inches",
|
||||||
|
"slug": "centimeters-to-inches",
|
||||||
|
"label1": "Centimeters (cm)",
|
||||||
|
"label2": "Inches (in)",
|
||||||
|
"factor": 0.393700787,
|
||||||
|
"offset": 0,
|
||||||
|
"seo_text": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Length Conversion:</strong> Centimeters are a metric unit of length, while inches are part of the imperial and US customary systems. One inch is defined exactly as 2.54 centimeters.</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "CFS to CMS",
|
||||||
|
"slug": "cfs-to-cms",
|
||||||
|
"label1": "Cubic Feet per Second (CFS)",
|
||||||
|
"label2": "Cubic Meters per Second (CMS)",
|
||||||
|
"factor": 0.0283168466,
|
||||||
|
"offset": 0,
|
||||||
|
"seo_text": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Volumetric Flow Rate:</strong> CFS and CMS are used to measure the volume of fluid (usually water) passing through a point per unit of time. This is critical in hydrology and civil engineering.</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "CMS to CFS",
|
||||||
|
"slug": "cms-to-cfs",
|
||||||
|
"label1": "Cubic Meters per Second (CMS)",
|
||||||
|
"label2": "Cubic Feet per Second (CFS)",
|
||||||
|
"factor": 35.3146667,
|
||||||
|
"offset": 0,
|
||||||
|
"seo_text": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>CMS to CFS Conversion:</strong> Converting from metric volumetric flow (CMS) to imperial (CFS) is essential for international engineering projects and environmental monitoring.</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Coulomb per Kilogram to Roentgen",
|
||||||
|
"slug": "coulomb-per-kilogram-to-roentgen",
|
||||||
|
"label1": "Coulombs per Kilogram (C/kg)",
|
||||||
|
"label2": "Roentgen (R)",
|
||||||
|
"factor": 3875.96899,
|
||||||
|
"offset": 0,
|
||||||
|
"seo_text": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Radiation Exposure:</strong> The coulomb per kilogram and the roentgen are units used to measure ionizing radiation exposure in air. The C/kg is the SI unit, while the roentgen is a legacy unit.</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Cups to Milliliters",
|
||||||
|
"slug": "cups-to-milliliters",
|
||||||
|
"label1": "Cups (US)",
|
||||||
|
"label2": "Milliliters (ml)",
|
||||||
|
"factor": 236.588237,
|
||||||
|
"offset": 0,
|
||||||
|
"seo_text": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Kitchen Conversion:</strong> Converting US cups to milliliters is a common task in cooking and baking. A standard US cup is approximately 236.6 ml.</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Curie to Becquerel",
|
||||||
|
"slug": "curie-to-becquerel",
|
||||||
|
"label1": "Curies (Ci)",
|
||||||
|
"label2": "Becquerels (Bq)",
|
||||||
|
"factor": 3.7e10,
|
||||||
|
"offset": 0,
|
||||||
|
"seo_text": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Radioactivity Units:</strong> The curie is an older, non-SI unit, while the becquerel is the modern SI unit. One curie is exactly 37 billion becquerels.</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Daltons to AMU",
|
||||||
|
"slug": "daltons-to-amu",
|
||||||
|
"label1": "Daltons (Da)",
|
||||||
|
"label2": "Atomic Mass Units (u)",
|
||||||
|
"factor": 1.0,
|
||||||
|
"offset": 0,
|
||||||
|
"seo_text": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Atomic Mass Conversion:</strong> The dalton and the unified atomic mass unit (u) are effectively identical units used to express the mass of atoms and molecules.</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Days to Hours",
|
||||||
|
"slug": "days-to-hours",
|
||||||
|
"label1": "Days",
|
||||||
|
"label2": "Hours",
|
||||||
|
"factor": 24.0,
|
||||||
|
"offset": 0,
|
||||||
|
"seo_text": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Time Computation:</strong> In our standard 24-hour day system, converting days to hours is done by multiplying the day count by 24.</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
for item in batch_3:
|
||||||
|
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">
|
||||||
|
<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 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
|
||||||
|
|
||||||
|
# JS Logic with Offset Support: v2 = v1 * factor + offset
|
||||||
|
offset = item.get('offset', 0)
|
||||||
|
js_code = f"""
|
||||||
|
<script>
|
||||||
|
function calculate1() {{
|
||||||
|
let val1 = parseFloat(document.getElementById("input-1").value);
|
||||||
|
if(isNaN(val1)) {{
|
||||||
|
document.getElementById("input-2").value = "";
|
||||||
|
return;
|
||||||
|
}}
|
||||||
|
let val2 = val1 * {item['factor']} + {offset};
|
||||||
|
document.getElementById("input-2").value = parseFloat(val2.toFixed(8));
|
||||||
|
}}
|
||||||
|
function calculate2() {{
|
||||||
|
let val2 = parseFloat(document.getElementById("input-2").value);
|
||||||
|
if(isNaN(val2)) {{
|
||||||
|
document.getElementById("input-1").value = "";
|
||||||
|
return;
|
||||||
|
}}
|
||||||
|
let val1 = (val2 - {offset}) / {item['factor']};
|
||||||
|
document.getElementById("input-1").value = parseFloat(val1.toFixed(8));
|
||||||
|
}}
|
||||||
|
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",
|
||||||
|
"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:
|
||||||
|
urllib.request.urlopen(req_j, timeout=30)
|
||||||
|
print(f"--> Posted JS hook")
|
||||||
|
except Exception as e:
|
||||||
|
print("Error creating JS Element:", e)
|
||||||
|
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
print("\n--- BATCH 3 COMPLETE ---")
|
||||||
255
batch_4.py
Normal file
255
batch_4.py
Normal file
@@ -0,0 +1,255 @@
|
|||||||
|
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_4 = [
|
||||||
|
{
|
||||||
|
"title": "Days to Weeks",
|
||||||
|
"slug": "days-to-weeks",
|
||||||
|
"label1": "Days",
|
||||||
|
"label2": "Weeks",
|
||||||
|
"factor": 1/7,
|
||||||
|
"offset": 0,
|
||||||
|
"seo_text": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Time Conversion - Days to Weeks:</strong> Weeks are a standard unit of time used across most calendars globally. One week consists of seven days. This calculator helps you convert daily counts into standard weeks.</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Days to Years",
|
||||||
|
"slug": "days-to-years",
|
||||||
|
"label1": "Days",
|
||||||
|
"label2": "Years",
|
||||||
|
"factor": 1/365.25,
|
||||||
|
"offset": 0,
|
||||||
|
"seo_text": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Time Conversion - Days to Years:</strong> Converting days into years is important for astronomical and logistical calculations. This calculator uses the standard Gregorian year length of 365.25 days to account for leap years.</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Degrees to Mils",
|
||||||
|
"slug": "degrees-to-mils",
|
||||||
|
"label1": "Degrees (°)",
|
||||||
|
"label2": "Mils",
|
||||||
|
"factor": 17.777777778,
|
||||||
|
"offset": 0,
|
||||||
|
"seo_text": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Angle Measurement - Degrees to Mils:</strong> While degrees are common in everyday use, mils (milliradians) are frequently used in military and engineering contexts for precise targeting and measurement.</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Degrees to Radians",
|
||||||
|
"slug": "degrees-to-radians",
|
||||||
|
"label1": "Degrees (°)",
|
||||||
|
"label2": "Radians (rad)",
|
||||||
|
"factor": 0.0174532925,
|
||||||
|
"offset": 0,
|
||||||
|
"seo_text": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Mathematical Precision - Degrees to Radians:</strong> Radians are the standard unit of angular measure used in mathematics, physics, and computer science. This calculator provides a quick conversion from common degrees.</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Dynes to Newtons",
|
||||||
|
"slug": "dynes-to-newtons",
|
||||||
|
"label1": "Dynes",
|
||||||
|
"label2": "Newtons (N)",
|
||||||
|
"factor": 1e-5,
|
||||||
|
"offset": 0,
|
||||||
|
"seo_text": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Force Measurement - Dynes to Newtons:</strong> The dyne is a unit of force in the cgs (centimeter-gram-second) system, while the newton is the standard SI unit. One newton is exactly 100,000 dynes.</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Ergs to Joules",
|
||||||
|
"slug": "ergs-to-joules",
|
||||||
|
"label1": "Ergs",
|
||||||
|
"label2": "Joules (J)",
|
||||||
|
"factor": 1e-7,
|
||||||
|
"offset": 0,
|
||||||
|
"seo_text": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Energy Conversion - Ergs to Joules:</strong> The erg is a legacy unit of energy and mechanical work in the cgs system. In modern science, the joule is the preferred SI unit for energy.</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Feet to Meters",
|
||||||
|
"slug": "feet-to-meters",
|
||||||
|
"label1": "Feet (ft)",
|
||||||
|
"label2": "Meters (m)",
|
||||||
|
"factor": 0.3048,
|
||||||
|
"offset": 0,
|
||||||
|
"seo_text": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Length Conversion - Feet to Meters:</strong> Feet are part of the imperial and US customary systems, while meters are the core metric unit of length. One foot is defined internationally as exactly 0.3048 meters.</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Foot-Pounds to Newton-Meters",
|
||||||
|
"slug": "foot-pounds-to-newton-meters",
|
||||||
|
"label1": "Foot-Pounds (ft-lb)",
|
||||||
|
"label2": "Newton-Meters (N-m)",
|
||||||
|
"factor": 1.35581795,
|
||||||
|
"offset": 0,
|
||||||
|
"seo_text": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Torque Conversion:</strong> Foot-pounds and newton-meters are units used to measure torque or work. This calculator is particularly useful for mechanics and engineers.</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Gallons to Liters",
|
||||||
|
"slug": "gallons-to-liters",
|
||||||
|
"label1": "Gallons (US)",
|
||||||
|
"label2": "Liters (L)",
|
||||||
|
"factor": 3.78541178,
|
||||||
|
"offset": 0,
|
||||||
|
"seo_text": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Volume Conversion - Gallons to Liters:</strong> Converting between US gallons and metric liters is a common requirement in automotive, culinary, and scientific fields.</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Gigabytes to Megabytes",
|
||||||
|
"slug": "gigabytes-to-megabytes",
|
||||||
|
"label1": "Gigabytes (GB)",
|
||||||
|
"label2": "Megabytes (MB)",
|
||||||
|
"factor": 1000.0,
|
||||||
|
"offset": 0,
|
||||||
|
"seo_text": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Digital Storage - GB to MB:</strong> This calculator uses the standard decimal (base-10) convention used by hard drive manufacturers and memory card providers, where 1 GB = 1,000 MB.</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
for item in batch_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>
|
||||||
|
window.addEventListener('DOMContentLoaded', (event) => {{
|
||||||
|
const inp1 = document.getElementById("input-1");
|
||||||
|
const inp2 = document.getElementById("input-2");
|
||||||
|
|
||||||
|
function calculate1() {{
|
||||||
|
let val1 = parseFloat(inp1.value);
|
||||||
|
if(isNaN(val1)) {{
|
||||||
|
inp2.value = "";
|
||||||
|
return;
|
||||||
|
}}
|
||||||
|
let val2 = val1 * {item['factor']} + {offset};
|
||||||
|
inp2.value = parseFloat(val2.toFixed(8));
|
||||||
|
}}
|
||||||
|
function calculate2() {{
|
||||||
|
let val2 = parseFloat(inp2.value);
|
||||||
|
if(isNaN(val2)) {{
|
||||||
|
inp1.value = "";
|
||||||
|
return;
|
||||||
|
}}
|
||||||
|
let val1 = (val2 - {offset}) / {item['factor']};
|
||||||
|
inp1.value = parseFloat(val1.toFixed(8));
|
||||||
|
}}
|
||||||
|
inp1.addEventListener("input", calculate1);
|
||||||
|
inp2.addEventListener("input", calculate2);
|
||||||
|
|
||||||
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
|
const v1 = urlParams.get('v1');
|
||||||
|
const v2 = urlParams.get('v2');
|
||||||
|
if (v1 !== null && !isNaN(parseFloat(v1))) {{
|
||||||
|
inp1.value = v1;
|
||||||
|
calculate1();
|
||||||
|
}} else if (v2 !== null && !isNaN(parseFloat(v2))) {{
|
||||||
|
inp2.value = v2;
|
||||||
|
calculate2();
|
||||||
|
}}
|
||||||
|
}});
|
||||||
|
</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 4 COMPLETE ---")
|
||||||
259
batch_5.py
Normal file
259
batch_5.py
Normal file
@@ -0,0 +1,259 @@
|
|||||||
|
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_5 = [
|
||||||
|
{
|
||||||
|
"title": "Fahrenheit to Celsius",
|
||||||
|
"slug": "fahrenheit-to-celsius",
|
||||||
|
"label1": "Fahrenheit (°F)",
|
||||||
|
"label2": "Celsius (°C)",
|
||||||
|
"factor": 5/9,
|
||||||
|
"offset": -32 * (5/9),
|
||||||
|
"seo_text": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Temperature Conversion - Fahrenheit to Celsius:</strong> Converting between Fahrenheit and Celsius is a common necessity for travel, science, and weather reporting. This calculator uses the standard formula $C = (F - 32) \times 5/9$.</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Feet per Second to Meters per Second",
|
||||||
|
"slug": "feet-per-second-to-meters-per-second",
|
||||||
|
"label1": "Feet per Second (ft/s)",
|
||||||
|
"label2": "Meters per Second (m/s)",
|
||||||
|
"factor": 0.3048,
|
||||||
|
"offset": 0,
|
||||||
|
"seo_text": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Speed Conversion:</strong> Feet per second and meters per second are both standard units of speed. This converter is essential for engineering, ballistics, and aviation calculations where different measurement systems are used.</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Fluid Ounces to Milliliters",
|
||||||
|
"slug": "fluid-ounces-to-milliliters",
|
||||||
|
"label1": "Fluid Ounces (US fl oz)",
|
||||||
|
"label2": "Milliliters (ml)",
|
||||||
|
"factor": 29.5735296,
|
||||||
|
"offset": 0,
|
||||||
|
"seo_text": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Volume Conversion:</strong> US fluid ounces are a standard unit of liquid volume in the United States. This tool allows for precise conversion to milliliters, commonly used in food labels and medicine.</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Gallons per Minute to Liters per Second",
|
||||||
|
"slug": "gallons-per-minute-to-liters-per-second",
|
||||||
|
"label1": "Gallons per Minute (GPM)",
|
||||||
|
"label2": "Liters per Second (L/s)",
|
||||||
|
"factor": 0.0630901964,
|
||||||
|
"offset": 0,
|
||||||
|
"seo_text": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Flow Rate Conversion:</strong> Gallons per minute (GPM) is a common unit for water flow in plumbing and irrigation, while liters per second (L/s) is the preferred SI unit for volumetric flow.</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Grains to Grams",
|
||||||
|
"slug": "grains-to-grams",
|
||||||
|
"label1": "Grains (gr)",
|
||||||
|
"label2": "Grams (g)",
|
||||||
|
"factor": 0.06479891,
|
||||||
|
"offset": 0,
|
||||||
|
"seo_text": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Weight Conversion:</strong> The grain is a unit of measurement for mass, based on the average mass of a single seed of a cereal. It is still used today in ballistics and the measurement of medication.</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Grams to Milligrams",
|
||||||
|
"slug": "grams-to-milligrams",
|
||||||
|
"label1": "Grams (g)",
|
||||||
|
"label2": "Milligrams (mg)",
|
||||||
|
"factor": 1000.0,
|
||||||
|
"offset": 0,
|
||||||
|
"seo_text": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Metric Mass Conversion:</strong> Milligrams are equal to one-thousandth of a gram. This conversion is extremely common in chemistry, biology, and healthcare for measuring small quantities of substances.</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Grams to Ounces",
|
||||||
|
"slug": "grams-to-ounces",
|
||||||
|
"label1": "Grams (g)",
|
||||||
|
"label2": "Ounces (oz)",
|
||||||
|
"factor": 0.0352739619,
|
||||||
|
"offset": 0,
|
||||||
|
"seo_text": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Mass Conversion:</strong> Converting metric grams to imperial ounces is a frequent task in international commerce and cooking. One ounce is approximately 28.35 grams.</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Grams to Pennyweights",
|
||||||
|
"slug": "grams-to-pennyweights",
|
||||||
|
"label1": "Grams (g)",
|
||||||
|
"label2": "Pennyweights (dwt)",
|
||||||
|
"factor": 0.643014931,
|
||||||
|
"offset": 0,
|
||||||
|
"seo_text": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Jewelry Measurement:</strong> Pennyweights are a traditional unit of mass used in the jewelry industry for precious metals. This calculator provides a precise bridge to the metric system.</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Grams to Troy Ounces",
|
||||||
|
"slug": "grams-to-troy-ounces",
|
||||||
|
"label1": "Grams (g)",
|
||||||
|
"label2": "Troy Ounces (oz t)",
|
||||||
|
"factor": 0.0321507466,
|
||||||
|
"offset": 0,
|
||||||
|
"seo_text": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Precious Metal Calculation:</strong> Unlike standard ounces, troy ounces are used specifically for the pricing and measurement of gold, silver, and platinum. One troy ounce is equivalent to 31.103 grams.</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Gray to Rad",
|
||||||
|
"slug": "gray-to-rad",
|
||||||
|
"label1": "Grays (Gy)",
|
||||||
|
"label2": "Rads",
|
||||||
|
"factor": 100.0,
|
||||||
|
"offset": 0,
|
||||||
|
"seo_text": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Absorbed Dose Conversion:</strong> The gray is the SI unit of absorbed ionizing radiation dose, while the rad is the deprecated cgs unit. One gray is defined as exactly 100 rads.</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
for item in batch_5:
|
||||||
|
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>
|
||||||
|
window.addEventListener('DOMContentLoaded', (event) => {{
|
||||||
|
const inp1 = document.getElementById("input-1");
|
||||||
|
const inp2 = document.getElementById("input-2");
|
||||||
|
|
||||||
|
function calculate1() {{
|
||||||
|
let val1 = parseFloat(inp1.value);
|
||||||
|
if(isNaN(val1)) {{
|
||||||
|
inp2.value = "";
|
||||||
|
return;
|
||||||
|
}}
|
||||||
|
let val2 = val1 * {item['factor']} + {offset};
|
||||||
|
inp2.value = parseFloat(val2.toFixed(8));
|
||||||
|
}}
|
||||||
|
function calculate2() {{
|
||||||
|
let val2 = parseFloat(inp2.value);
|
||||||
|
if(isNaN(val2)) {{
|
||||||
|
inp1.value = "";
|
||||||
|
return;
|
||||||
|
}}
|
||||||
|
let val1 = (val2 - {offset}) / {item['factor']};
|
||||||
|
inp1.value = parseFloat(val1.toFixed(8));
|
||||||
|
}}
|
||||||
|
inp1.addEventListener("input", calculate1);
|
||||||
|
inp2.addEventListener("input", calculate2);
|
||||||
|
|
||||||
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
|
if (urlParams.has('v1')) {{
|
||||||
|
let v1 = parseFloat(urlParams.get('v1'));
|
||||||
|
if (!isNaN(v1)) {{
|
||||||
|
inp1.value = v1;
|
||||||
|
calculate1();
|
||||||
|
}}
|
||||||
|
}} else if (urlParams.has('v2')) {{
|
||||||
|
let v2 = parseFloat(urlParams.get('v2'));
|
||||||
|
if (!isNaN(v2)) {{
|
||||||
|
inp2.value = v2;
|
||||||
|
calculate2();
|
||||||
|
}}
|
||||||
|
}}
|
||||||
|
}});
|
||||||
|
</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 5 COMPLETE ---")
|
||||||
@@ -14,44 +14,92 @@ Whenever a new calculator is published via the REST API, it must be appended her
|
|||||||
| Apothecary Ounces to Grams | 113 | 114 | apothecary-ounces-to-grams | 31.1034768 |
|
| Apothecary Ounces to Grams | 113 | 114 | apothecary-ounces-to-grams | 31.1034768 |
|
||||||
| Astronomical Units to Light Years | 115 | 116 | astronomical-units-to-light-years | 0.0000158125074 |
|
| Astronomical Units to Light Years | 115 | 116 | astronomical-units-to-light-years | 0.0000158125074 |
|
||||||
| Atmosphere to mmHg | 117 | 118 | atmosphere-to-mmhg | 760.0 |
|
| Atmosphere to mmHg | 117 | 118 | atmosphere-to-mmhg | 760.0 |
|
||||||
|
| Attograms to Femtograms | 119 | 120 | attograms-to-femtograms | 0.001 |
|
||||||
|
| Bar to Pascal | 121 | 122 | bar-to-pascal | 100000.0 |
|
||||||
|
| Bar to PSI | 123 | 124 | bar-to-psi | 14.5037738 |
|
||||||
|
| Becquerel to Curie | 125 | 126 | becquerel-to-curie | 2.7027027e-11 |
|
||||||
|
| Becquerel to Rutherford | 127 | 128 | becquerel-to-rutherford | 0.000001 |
|
||||||
|
| Bits to Bytes | 129 | 130 | bits-to-bytes | 0.125 |
|
||||||
|
| BTU to Kilojoules | 131 | 132 | btu-to-kilojoules | 1.05505585 |
|
||||||
|
| BTU/hour to Watts | 133 | 134 | btuhour-to-watts | 0.293071 |
|
||||||
|
| Calories to Joules | 135 | 136 | calories-to-joules | 4.184 |
|
||||||
|
| Calories to Kilojoules | 137 | 138 | calories-to-kilojoules | 4.184 |
|
||||||
|
| ASCII to Binary | 139 | 140 | ascii-to-binary | N/A (Text) |
|
||||||
|
| Amps to Volts | 141 | 142 | amps-to-volts | Multi-Variable |
|
||||||
|
| Binary to ASCII | 151 | 152 | binary-to-ascii | N/A (Text) |
|
||||||
|
| Binary to Decimal | 153 | 154 | binary-to-decimal | N/A (Text) |
|
||||||
|
| Binary to Hex | 155 | 156 | binary-to-hex | N/A (Text) |
|
||||||
|
| Amps to Watts | 157 | 158 | amps-to-watts | Multi-Variable |
|
||||||
|
| Amps to Kilowatts | 159 | 160 | amps-to-kilowatts | Multi-Variable |
|
||||||
|
| Amps to kVA | 161 | 162 | amps-to-kva | Multi-Variable |
|
||||||
|
| Carats to Grams | 163 | 164 | carats-to-grams | 0.2 |
|
||||||
|
| Celsius to Fahrenheit | 165 | 166 | celsius-to-fahrenheit | Linear Offset (1.8x + 32) |
|
||||||
|
| Centimeters to Inches | 167 | 168 | centimeters-to-inches | 0.393700787 |
|
||||||
|
| CFS to CMS | 169 | 170 | cfs-to-cms | 0.0283168466 |
|
||||||
|
| CMS to CFS | 171 | 172 | cms-to-cfs | 35.3146667 |
|
||||||
|
| Coulomb per Kilogram to Roentgen | 173 | 174 | coulomb-per-kilogram-to-roentgen | 3875.96899 |
|
||||||
|
| Cups to Milliliters | 175 | 176 | cups-to-milliliters | 236.588237 |
|
||||||
|
| Curie to Becquerel | 177 | 178 | curie-to-becquerel | 3.7e10 |
|
||||||
|
| Daltons to AMU | 179 | 180 | daltons-to-amu | 1.0 |
|
||||||
|
| Days to Hours | 181 | 182 | days-to-hours | 24.0 |
|
||||||
|
| Days to Weeks | 193 | 194 | days-to-weeks | 0.142857143 |
|
||||||
|
| Days to Years | 195 | 196 | days-to-years | 0.002737851 |
|
||||||
|
| Degrees to Mils | 197 | 198 | degrees-to-mils | 17.777777778 |
|
||||||
|
| Degrees to Radians | 199 | 200 | degrees-to-radians | 0.017453293 |
|
||||||
|
| Dynes to Newtons | 201 | 202 | dynes-to-newtons | 1e-05 |
|
||||||
|
| Ergs to Joules | 203 | 204 | ergs-to-joules | 1e-07 |
|
||||||
|
| Feet to Meters | 205 | 206 | feet-to-meters | 0.3048 |
|
||||||
|
| Foot-Pounds to Newton-Meters | 207 | 208 | foot-pounds-to-newton-meters | 1.35581795 |
|
||||||
|
| Gallons to Liters | 209 | 210 | gallons-to-liters | 3.78541178 |
|
||||||
|
| Gigabytes to Megabytes | 211 | 212 | gigabytes-to-megabytes | 1000.0 |
|
||||||
|
| Fahrenheit to Celsius | 214 | 215 | fahrenheit-to-celsius | Linear Offset (5/9x - 17.778) |
|
||||||
|
| Feet per Second to Meters per Second | 216 | 217 | feet-per-second-to-meters-per-second | 0.3048 |
|
||||||
|
| Fluid Ounces to Milliliters | 218 | 219 | fluid-ounces-to-milliliters | 29.5735296 |
|
||||||
|
| Gallons per Minute to Liters per Second | 220 | 221 | gallons-per-minute-to-liters-per-second | 0.0630901964 |
|
||||||
|
| Grains to Grams | 222 | 223 | grains-to-grams | 0.06479891 |
|
||||||
|
| Grams to Milligrams | 224 | 225 | grams-to-milligrams | 1000.0 |
|
||||||
|
| Grams to Ounces | 226 | 227 | grams-to-ounces | 0.0352739619 |
|
||||||
|
| Grams to Pennyweights | 228 | 229 | grams-to-pennyweights | 0.643014931 |
|
||||||
|
| Grams to Troy Ounces | 230 | 231 | grams-to-troy-ounces | 0.0321507466 |
|
||||||
|
| Gray to Rad | 232 | 233 | gray-to-rad | 100.0 |
|
||||||
|
|
||||||
## Backlog / To-Do
|
## Backlog / To-Do
|
||||||
- [x] Acres to hectares
|
- [x] Acres to hectares
|
||||||
- [x] Acres to square feet
|
- [x] Acres to square feet
|
||||||
- [ ] Amps to volts
|
- [x] Amps to volts
|
||||||
- [ ] Amps to watts
|
- [x] Amps to watts
|
||||||
- [x] Angstroms to nanometers
|
- [x] Angstroms to nanometers
|
||||||
- [x] Apothecary ounces to grams
|
- [x] Apothecary ounces to grams
|
||||||
- [ ] ASCII to binary
|
- [x] ASCII to binary
|
||||||
- [x] Astronomical units to light years
|
- [x] Astronomical units to light years
|
||||||
- [x] Atmosphere to mmHg
|
- [x] Atmosphere to mmHg
|
||||||
- [ ] Attograms to femtograms
|
- [x] Attograms to femtograms
|
||||||
- [ ] Bar to Pascal
|
- [x] Bar to Pascal
|
||||||
- [ ] Bar to PSI
|
- [x] Bar to PSI
|
||||||
- [ ] Becquerel to curie
|
- [x] Becquerel to curie
|
||||||
- [ ] Becquerel to rutherford
|
- [x] Becquerel to rutherford
|
||||||
- [ ] Binary to ASCII
|
- [x] Binary to ASCII
|
||||||
- [ ] Binary to decimal
|
- [x] Binary to decimal
|
||||||
- [ ] Binary to hex
|
- [x] Binary to hex
|
||||||
- [ ] Bits to bytes
|
- [x] Bits to bytes
|
||||||
- [ ] BTU to kilojoules
|
- [x] BTU to kilojoules
|
||||||
- [ ] BTU/hour to watts
|
- [x] BTU/hour to watts
|
||||||
- [ ] Bytes to bits
|
- [x] Bytes to bits
|
||||||
- [ ] Calories to joules
|
- [x] Calories to joules
|
||||||
- [ ] Calories to kilojoules
|
- [x] Calories to kilojoules
|
||||||
- [ ] Candela to lumens
|
- [ ] Candela to lumens
|
||||||
- [ ] Carats to grams
|
- [x] Carats to grams
|
||||||
- [ ] Celsius to Fahrenheit
|
- [x] Celsius to Fahrenheit
|
||||||
- [ ] Centimeters to inches
|
- [x] Centimeters to inches
|
||||||
- [ ] CFS to CMS
|
- [x] CFS to CMS
|
||||||
- [ ] CMS to CFS
|
- [x] CMS to CFS
|
||||||
- [ ] Coulomb per kilogram to roentgen
|
- [x] Coulomb per kilogram to roentgen
|
||||||
- [ ] Cups to milliliters
|
- [x] Cups to milliliters
|
||||||
- [ ] Curie to becquerel
|
- [x] Curie to becquerel
|
||||||
- [ ] Daltons to atomic mass units
|
- [x] Daltons to atomic mass units
|
||||||
- [ ] Days to hours
|
- [x] Days to hours
|
||||||
- [ ] Days to weeks
|
- [x] Days to weeks
|
||||||
- [ ] Days to years
|
- [x] Days to years
|
||||||
- [ ] Decimal degrees to degrees, minutes, and seconds
|
- [ ] Decimal degrees to degrees, minutes, and seconds
|
||||||
- [ ] Decimal to binary
|
- [ ] Decimal to binary
|
||||||
- [ ] Decimal to fraction
|
- [ ] Decimal to fraction
|
||||||
@@ -61,33 +109,33 @@ Whenever a new calculator is published via the REST API, it must be appended her
|
|||||||
- [ ] Decibels to sound pressure level
|
- [ ] Decibels to sound pressure level
|
||||||
- [ ] Decibels to volts
|
- [ ] Decibels to volts
|
||||||
- [ ] Decibels to watts
|
- [ ] Decibels to watts
|
||||||
- [ ] Degrees to mils
|
- [x] Degrees to mils
|
||||||
- [ ] Degrees to radians
|
- [x] Degrees to radians
|
||||||
- [ ] Degrees, minutes, and seconds to decimal degrees
|
- [ ] Degrees, minutes, and seconds to decimal degrees
|
||||||
- [ ] Dynes to newtons
|
- [x] Dynes to newtons
|
||||||
- [ ] Ergs to joules
|
- [x] Ergs to joules
|
||||||
- [ ] Fahrenheit to Celsius
|
- [x] Fahrenheit to Celsius
|
||||||
- [ ] Feet to meters
|
- [x] Feet to meters
|
||||||
- [ ] Feet per second to meters per second
|
- [x] Feet per second to meters per second
|
||||||
- [ ] Femtograms to attograms
|
- [ ] Femtograms to attograms
|
||||||
- [ ] Fluid ounces to milliliters
|
- [x] Fluid ounces to milliliters
|
||||||
- [ ] Foot-pounds to newton-meters
|
- [x] Foot-pounds to newton-meters
|
||||||
- [ ] Fractions to decimals
|
- [ ] Fractions to decimals
|
||||||
- [ ] Gallons per minute to liters per second
|
- [x] Gallons per minute to liters per second
|
||||||
- [ ] Gallons to liters
|
- [x] Gallons to liters
|
||||||
- [ ] Gigabytes to megabytes
|
- [x] Gigabytes to megabytes
|
||||||
- [ ] Gigabytes to terabytes
|
- [ ] Gigabytes to terabytes
|
||||||
- [ ] Grains to grams
|
- [x] Grains to grams
|
||||||
- [ ] Grams to apothecary ounces
|
- [ ] Grams to apothecary ounces
|
||||||
- [ ] Grams to carats
|
- [ ] Grams to carats
|
||||||
- [ ] Grams to grains
|
- [ ] Grams to grains
|
||||||
- [ ] Grams to milligrams
|
- [x] Grams to milligrams
|
||||||
- [ ] Grams to moles (requires molar mass — see list 2 if chemical context unknown)
|
- [ ] Grams to moles (requires molar mass — see list 2 if chemical context unknown)
|
||||||
- [ ] Grams to ounces
|
- [x] Grams to ounces
|
||||||
- [ ] Grams to pennyweights
|
- [x] Grams to pennyweights
|
||||||
- [ ] Grams to troy ounces
|
- [x] Grams to troy ounces
|
||||||
- [ ] Gray to rad
|
- [x] Gray to rad
|
||||||
- [ ] Hectares to acres
|
- [x] Hectares to acres
|
||||||
- [ ] Hex to binary
|
- [ ] Hex to binary
|
||||||
- [ ] Hex to decimal
|
- [ ] Hex to decimal
|
||||||
- [ ] Horsepower to kilowatts
|
- [ ] Horsepower to kilowatts
|
||||||
|
|||||||
349
complex_batch.py
Normal file
349
complex_batch.py
Normal file
@@ -0,0 +1,349 @@
|
|||||||
|
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"""
|
||||||
|
<!-- 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>
|
||||||
|
.calc-container-{slug_raw} {{
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
gap: 1.5rem;
|
||||||
|
max-width: 600px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}}
|
||||||
|
.calc-group {{
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}}
|
||||||
|
.calc-label {{
|
||||||
|
font-weight: 600;
|
||||||
|
color: #333333;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}}
|
||||||
|
.calc-textarea {{
|
||||||
|
width: 100%;
|
||||||
|
padding: 12px;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 1.1rem;
|
||||||
|
min-height: 120px;
|
||||||
|
font-family: monospace;
|
||||||
|
}}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<div class="calc-container-{slug_raw}">
|
||||||
|
<div class="calc-group">
|
||||||
|
<label class="calc-label" for="input-1">{item['label1']}</label>
|
||||||
|
<textarea id="input-1" class="calc-textarea" placeholder="Enter {item['label1']}..."></textarea>
|
||||||
|
</div>
|
||||||
|
<div class="calc-group">
|
||||||
|
<label class="calc-label" for="input-2">{item['label2']}</label>
|
||||||
|
<textarea id="input-2" class="calc-textarea" placeholder="{item['label2']} result..."></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div></div>
|
||||||
|
<!-- /wp:kadence/column -->
|
||||||
|
</div></div>
|
||||||
|
<!-- /wp:kadence/rowlayout -->
|
||||||
|
|
||||||
|
{item['seo_text']}
|
||||||
|
"""
|
||||||
|
|
||||||
|
def get_triple_ui(item):
|
||||||
|
slug_raw = item['slug'].replace("-", "")
|
||||||
|
return 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>
|
||||||
|
.triple-grid-{slug_raw} {{
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(3, 1fr);
|
||||||
|
gap: 1rem;
|
||||||
|
max-width: 800px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}}
|
||||||
|
@media (max-width: 767px) {{
|
||||||
|
.triple-grid-{slug_raw} {{
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}}
|
||||||
|
}}
|
||||||
|
.calc-group {{
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}}
|
||||||
|
.calc-label {{
|
||||||
|
font-weight: 600;
|
||||||
|
color: #333333;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}}
|
||||||
|
.calc-input {{
|
||||||
|
width: 100%;
|
||||||
|
padding: 12px;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 1.2rem;
|
||||||
|
}}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<div class="triple-grid-{slug_raw}">
|
||||||
|
<div class="calc-group">
|
||||||
|
<label class="calc-label" for="input-1">{item['label1']}</label>
|
||||||
|
<input type="number" id="input-1" class="calc-input" placeholder="0">
|
||||||
|
</div>
|
||||||
|
<div class="calc-group">
|
||||||
|
<label class="calc-label" for="input-2">{item['label2']}</label>
|
||||||
|
<input type="number" id="input-2" class="calc-input" placeholder="0">
|
||||||
|
</div>
|
||||||
|
<div class="calc-group">
|
||||||
|
<label class="calc-label" for="input-3">{item['label3']}</label>
|
||||||
|
<input type="number" id="input-3" class="calc-input" placeholder="0">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p style="text-align: center; margin-top: 1.5rem; color: #666; font-size: 0.9rem;">
|
||||||
|
<em>Enter any two values to calculate the third.</em>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
</div></div>
|
||||||
|
<!-- /wp:kadence/column -->
|
||||||
|
</div></div>
|
||||||
|
<!-- /wp:kadence/rowlayout -->
|
||||||
|
|
||||||
|
{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": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Binary to ASCII Conversion:</strong> Translate binary strings of 0s and 1s back into readable text. Each 8-bit sequence represents a specific character in the ASCII standard.</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"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": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Binary to Decimal:</strong> Quickly convert base-2 binary numbers into their base-10 decimal equivalents used in everyday mathematics.</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"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": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Binary to Hex:</strong> Conversion between binary (base-2) and hexadecimal (base-16) is a fundamental skill in computing and low-level programming.</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"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": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Amps to Watts:</strong> Use this calculator to find power (Watts) given current (Amps) and voltage (Volts). It works for DC and single-phase AC circuits.</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"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": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Amps to Kilowatts:</strong> Convert current to power in kilowatts. This calculator assumes a power factor of 1.0 (purely resistive load).</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"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": """
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Amps to kVA:</strong> Calculate apparent power in kVA for single-phase electrical systems. Apparent power is the product of RMS voltage and current.</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
# --- 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"<script>\\n{item['js_logic']}\\n</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")
|
||||||
|
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)
|
||||||
135
update_complex.py
Normal file
135
update_complex.py
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
import urllib.request
|
||||||
|
import json
|
||||||
|
import base64
|
||||||
|
import time
|
||||||
|
|
||||||
|
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)"
|
||||||
|
}
|
||||||
|
|
||||||
|
def patch_element(element_id, title, js_logic):
|
||||||
|
print(f"Updating Element {element_id}: {title}")
|
||||||
|
js_wrapped = f"""<script>
|
||||||
|
window.addEventListener('DOMContentLoaded', (event) => {{
|
||||||
|
{js_logic}
|
||||||
|
}});
|
||||||
|
</script>"""
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"content": js_wrapped
|
||||||
|
}
|
||||||
|
|
||||||
|
url = f"{url_base_kadence}{element_id}"
|
||||||
|
req = urllib.request.Request(url, data=json.dumps(data).encode("utf-8"), headers=headers, method="PUT")
|
||||||
|
try:
|
||||||
|
resp = urllib.request.urlopen(req, timeout=30)
|
||||||
|
print(f"--> Success")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"--> Error: {e}")
|
||||||
|
if hasattr(e, 'read'): print(e.read().decode('utf-8'))
|
||||||
|
|
||||||
|
# --- LOGIC BLOCKS ---
|
||||||
|
|
||||||
|
triple_logic_base = """
|
||||||
|
function solve(lastId) {
|
||||||
|
let a = parseFloat(document.getElementById("input-1").value);
|
||||||
|
let v = parseFloat(document.getElementById("input-2").value);
|
||||||
|
let w = parseFloat(document.getElementById("input-3").value);
|
||||||
|
|
||||||
|
if (isNaN(a) && isNaN(v) && isNaN(w)) return;
|
||||||
|
|
||||||
|
if (lastId === 'input-1' || lastId === 'input-2') {
|
||||||
|
if (!isNaN(a) && !isNaN(v)) {
|
||||||
|
let res = (a * v) / [DIVISOR];
|
||||||
|
document.getElementById("input-3").value = parseFloat(res.toFixed(3));
|
||||||
|
}
|
||||||
|
} else if (lastId === 'input-3') {
|
||||||
|
if (!isNaN(w)) {
|
||||||
|
if (!isNaN(a) && a !== 0) {
|
||||||
|
let res = (w * [DIVISOR]) / a;
|
||||||
|
document.getElementById("input-2").value = parseFloat(res.toFixed(2));
|
||||||
|
} else if (!isNaN(v) && v !== 0) {
|
||||||
|
let res = (w * [DIVISOR]) / v;
|
||||||
|
document.getElementById("input-1").value = parseFloat(res.toFixed(2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
document.getElementById("input-1").addEventListener("input", () => solve('input-1'));
|
||||||
|
document.getElementById("input-2").addEventListener("input", () => solve('input-2'));
|
||||||
|
document.getElementById("input-3").addEventListener("input", () => solve('input-3'));
|
||||||
|
"""
|
||||||
|
|
||||||
|
text_logic_ascii_to_bin = """
|
||||||
|
function convert1() {
|
||||||
|
let val = document.getElementById("input-1").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-2").value = binary.trim();
|
||||||
|
}
|
||||||
|
function convert2() {
|
||||||
|
let val = document.getElementById("input-2").value.replace(/\\s/g, "");
|
||||||
|
let text = "";
|
||||||
|
for (let i = 0; i < val.length; i += 8) {
|
||||||
|
let byte = val.substr(i, 8);
|
||||||
|
if (byte.length === 8) {
|
||||||
|
text += String.fromCharCode(parseInt(byte, 2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
document.getElementById("input-1").value = text;
|
||||||
|
}
|
||||||
|
document.getElementById("input-1").addEventListener("input", convert1);
|
||||||
|
document.getElementById("input-2").addEventListener("input", convert2);
|
||||||
|
"""
|
||||||
|
|
||||||
|
text_logic_bin_to_dec = """
|
||||||
|
function convert1() {
|
||||||
|
let val = document.getElementById("input-1").value.replace(/\\s/g, "");
|
||||||
|
if (val) document.getElementById("input-2").value = parseInt(val, 2).toString(10);
|
||||||
|
else document.getElementById("input-2").value = "";
|
||||||
|
}
|
||||||
|
function convert2() {
|
||||||
|
let val = document.getElementById("input-2").value;
|
||||||
|
if (val) document.getElementById("input-1").value = parseInt(val, 10).toString(2);
|
||||||
|
else document.getElementById("input-1").value = "";
|
||||||
|
}
|
||||||
|
document.getElementById("input-1").addEventListener("input", convert1);
|
||||||
|
document.getElementById("input-2").addEventListener("input", convert2);
|
||||||
|
"""
|
||||||
|
|
||||||
|
text_logic_bin_to_hex = """
|
||||||
|
function convert1() {
|
||||||
|
let val = document.getElementById("input-1").value.replace(/\\s/g, "");
|
||||||
|
if (val) document.getElementById("input-2").value = parseInt(val, 2).toString(16).toUpperCase();
|
||||||
|
else document.getElementById("input-2").value = "";
|
||||||
|
}
|
||||||
|
function convert2() {
|
||||||
|
let val = document.getElementById("input-2").value;
|
||||||
|
if (val) document.getElementById("input-1").value = parseInt(val, 16).toString(2);
|
||||||
|
else document.getElementById("input-1").value = "";
|
||||||
|
}
|
||||||
|
document.getElementById("input-1").addEventListener("input", convert1);
|
||||||
|
document.getElementById("input-2").addEventListener("input", convert2);
|
||||||
|
"""
|
||||||
|
|
||||||
|
updates = [
|
||||||
|
(140, "ASCII to Binary", text_logic_ascii_to_bin),
|
||||||
|
(152, "Binary to ASCII", text_logic_ascii_to_bin), # Logic is the same, just order of fields in UI differs? No, inputs are 1 and 2.
|
||||||
|
(154, "Binary to Decimal", text_logic_bin_to_dec),
|
||||||
|
(156, "Binary to Hex", text_logic_bin_to_hex),
|
||||||
|
(142, "Amps to Volts", triple_logic_base.replace("[DIVISOR]", "1")),
|
||||||
|
(158, "Amps to Watts", triple_logic_base.replace("[DIVISOR]", "1")),
|
||||||
|
(160, "Amps to Kilowatts", triple_logic_base.replace("[DIVISOR]", "1000")),
|
||||||
|
(162, "Amps to kVA", triple_logic_base.replace("[DIVISOR]", "1000"))
|
||||||
|
]
|
||||||
|
|
||||||
|
for eid, title, logic in updates:
|
||||||
|
patch_element(eid, title, logic)
|
||||||
|
time.sleep(1)
|
||||||
85
verify_batch_2.py
Normal file
85
verify_batch_2.py
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
import urllib.request
|
||||||
|
import re
|
||||||
|
import json
|
||||||
|
import time
|
||||||
|
|
||||||
|
# Batch 2 Registry Mapping for Verification
|
||||||
|
batch_2_registry = [
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/attograms-to-femtograms/?ao_noptimize=1", "fwd": 0.001, "v1": 1000, "expected_v2": 1},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/bar-to-pascal/?ao_noptimize=1", "fwd": 100000, "v1": 1, "expected_v2": 100000},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/bar-to-psi/?ao_noptimize=1", "fwd": 14.5037738, "v1": 1, "expected_v2": 14.5037738},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/becquerel-to-curie/?ao_noptimize=1", "fwd": 2.7027027e-11, "v1": 37000000000, "expected_v2": 1},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/becquerel-to-rutherford/?ao_noptimize=1", "fwd": 0.000001, "v1": 1000000, "expected_v2": 1},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/bits-to-bytes/?ao_noptimize=1", "fwd": 0.125, "v1": 8, "expected_v2": 1},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/btu-to-kilojoules/?ao_noptimize=1", "fwd": 1.05505585, "v1": 1, "expected_v2": 1.05505585},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/btuhour-to-watts/?ao_noptimize=1", "fwd": 0.293071, "v1": 100, "expected_v2": 29.3071},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/calories-to-joules/?ao_noptimize=1", "fwd": 4.184, "v1": 1, "expected_v2": 4.184},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/calories-to-kilojoules/?ao_noptimize=1", "fwd": 4.184, "v1": 1, "expected_v2": 4.184},
|
||||||
|
]
|
||||||
|
|
||||||
|
def verify_math(calc):
|
||||||
|
print(f"\n--- Verifying {calc['url']} ---")
|
||||||
|
headers = {"User-Agent": "Mozilla/5.0"}
|
||||||
|
|
||||||
|
# Test Forward
|
||||||
|
try:
|
||||||
|
url_v1 = f"{calc['url']}&v1={calc['v1']}"
|
||||||
|
req_f = urllib.request.Request(url_v1, headers=headers)
|
||||||
|
resp_f = urllib.request.urlopen(req_f).read().decode('utf-8')
|
||||||
|
|
||||||
|
# We need to check if the JS logic is actually executing.
|
||||||
|
# Since we use URL params and DOMContentLoaded, we can't 'see' the changed input value in raw HTML.
|
||||||
|
# Instead, we will extract the JS from the page body and evaluate it locally to verify the logic we injected is correct.
|
||||||
|
|
||||||
|
scripts = re.findall(r'<script.*?>\s*(.*?)\s*</script>', resp_f, re.DOTALL)
|
||||||
|
logic_script = ""
|
||||||
|
for s in scripts:
|
||||||
|
if "calculate1" in s and "document.getElementById" in s:
|
||||||
|
logic_script = s
|
||||||
|
break
|
||||||
|
|
||||||
|
if not logic_script:
|
||||||
|
print("FAILED: Logic script not found in page source.")
|
||||||
|
return False
|
||||||
|
|
||||||
|
print("Found JS logic. Verifying formula constants...")
|
||||||
|
|
||||||
|
# Extract the logic lines
|
||||||
|
fwd_logic = re.search(r'function calculate1.*?let val2 = (.*?);', logic_script, re.DOTALL)
|
||||||
|
rev_logic = re.search(r'function calculate2.*?let val1 = (.*?);', logic_script, re.DOTALL)
|
||||||
|
|
||||||
|
if not fwd_logic or not rev_logic:
|
||||||
|
print("FAILED: Could not parse math logic lines from JS.")
|
||||||
|
return False
|
||||||
|
|
||||||
|
f_expr = fwd_logic.group(1).replace("val1", str(calc['v1']))
|
||||||
|
r_expr = rev_logic.group(1).replace("val2", str(calc['expected_v2']))
|
||||||
|
|
||||||
|
# Evaluate local math
|
||||||
|
actual_v2 = eval(f_expr)
|
||||||
|
actual_v1 = eval(r_expr)
|
||||||
|
|
||||||
|
print(f"Forward: {calc['v1']} -> Expected {calc['expected_v2']}, Got {actual_v2}")
|
||||||
|
print(f"Reverse: {calc['expected_v2']} -> Expected {calc['v1']}, Got {actual_v1}")
|
||||||
|
|
||||||
|
if abs(actual_v2 - calc['expected_v2']) < 1e-7 and abs(actual_v1 - calc['v1']) < 1e-7:
|
||||||
|
print("SUCCESS: Math Verification Passed.")
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
print("FAILED: Math discrepancy detected.")
|
||||||
|
return False
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"FAILED: Verification error: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
all_passed = True
|
||||||
|
for c in batch_2_registry:
|
||||||
|
if not verify_math(c):
|
||||||
|
all_passed = False
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
if all_passed:
|
||||||
|
print("\nALL BATCH 2 CALCULATORS VERIFIED SUCCESSFULLY.")
|
||||||
|
else:
|
||||||
|
print("\nSOME BATCH 2 VERIFICATIONS FAILED.")
|
||||||
75
verify_batch_3.py
Normal file
75
verify_batch_3.py
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
import urllib.request
|
||||||
|
import re
|
||||||
|
import json
|
||||||
|
import time
|
||||||
|
|
||||||
|
# Batch 3 Registry for Verification
|
||||||
|
batch_3_registry = [
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/carats-to-grams/?ao_noptimize=1", "f": 0.2, "b": 0, "v1": 5, "ev2": 1},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/celsius-to-fahrenheit/?ao_noptimize=1", "f": 1.8, "b": 32, "v1": 0, "ev2": 32},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/centimeters-to-inches/?ao_noptimize=1", "f": 0.393700787, "b": 0, "v1": 2.54, "ev2": 1},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/cfs-to-cms/?ao_noptimize=1", "f": 0.0283168466, "b": 0, "v1": 100, "ev2": 2.83168466},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/cms-to-cfs/?ao_noptimize=1", "f": 35.3146667, "b": 0, "v1": 1, "ev2": 35.3146667},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/coulomb-per-kilogram-to-roentgen/?ao_noptimize=1", "f": 3875.96899, "b": 0, "v1": 1, "ev2": 3875.96899},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/cups-to-milliliters/?ao_noptimize=1", "f": 236.588237, "b": 0, "v1": 1, "ev2": 236.588237},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/curie-to-becquerel/?ao_noptimize=1", "f": 3.7e10, "b": 0, "v1": 1, "ev2": 37000000000},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/daltons-to-amu/?ao_noptimize=1", "f": 1.0, "b": 0, "v1": 1, "ev2": 1},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/days-to-hours/?ao_noptimize=1", "f": 24.0, "b": 0, "v1": 1, "ev2": 24},
|
||||||
|
]
|
||||||
|
|
||||||
|
def verify_math(calc):
|
||||||
|
print(f"\n--- Verifying {calc['url']} ---")
|
||||||
|
headers = {"User-Agent": "Mozilla/5.0"}
|
||||||
|
try:
|
||||||
|
req = urllib.request.Request(calc['url'], headers=headers)
|
||||||
|
resp = urllib.request.urlopen(req).read().decode('utf-8')
|
||||||
|
|
||||||
|
scripts = re.findall(r'<script.*?>\s*(.*?)\s*</script>', resp, re.DOTALL)
|
||||||
|
logic_script = ""
|
||||||
|
for s in scripts:
|
||||||
|
if "calculate1" in s and "document.getElementById" in s:
|
||||||
|
logic_script = s
|
||||||
|
break
|
||||||
|
|
||||||
|
if not logic_script:
|
||||||
|
print("FAILED: Logic script not found.")
|
||||||
|
return False
|
||||||
|
|
||||||
|
# Extract formula: let val2 = val1 * factor + offset;
|
||||||
|
fwd_match = re.search(r'let val2 = val1 \* (.*?) \+ (.*?);', logic_script)
|
||||||
|
rev_match = re.search(r'let val1 = \(val2 - (.*?)\) \/ (.*?);', logic_script)
|
||||||
|
|
||||||
|
if not fwd_match or not rev_match:
|
||||||
|
print("FAILED: Could not parse m/b components.")
|
||||||
|
return False
|
||||||
|
|
||||||
|
m_actual = float(fwd_match.group(1))
|
||||||
|
b_actual = float(fwd_match.group(2))
|
||||||
|
|
||||||
|
print(f"Detected Formula: y = {m_actual}x + {b_actual}")
|
||||||
|
|
||||||
|
# Test math locally
|
||||||
|
v2 = calc['v1'] * m_actual + b_actual
|
||||||
|
v1 = (v2 - b_actual) / m_actual
|
||||||
|
|
||||||
|
print(f"Test v1={calc['v1']} -> v2={v2} (Expected {calc['ev2']})")
|
||||||
|
print(f"Test v2={v2} -> v1={v1} (Expected {calc['v1']})")
|
||||||
|
|
||||||
|
if abs(v2 - calc['ev2']) < 1e-7 and abs(v1 - calc['v1']) < 1e-7:
|
||||||
|
print("SUCCESS")
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
print("FAILED math check")
|
||||||
|
return False
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"ERROR: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
all_ok = True
|
||||||
|
for c in batch_3_registry:
|
||||||
|
if not verify_math(c): all_ok = False
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
if all_ok: print("\nALL BATCH 3 VERIFIED.")
|
||||||
|
else: print("\nBATCH 3 FAILED.")
|
||||||
77
verify_batch_4.py
Normal file
77
verify_batch_4.py
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
import urllib.request
|
||||||
|
import re
|
||||||
|
import json
|
||||||
|
import time
|
||||||
|
|
||||||
|
# Batch 4 Registry for Verification
|
||||||
|
batch_4_registry = [
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/days-to-weeks/?ao_noptimize=1", "f": 1/7, "b": 0, "v1": 14, "ev2": 2},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/days-to-years/?ao_noptimize=1", "f": 1/365.25, "b": 0, "v1": 365.25, "ev2": 1},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/degrees-to-mils/?ao_noptimize=1", "f": 17.777777778, "b": 0, "v1": 1, "ev2": 17.777777778},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/degrees-to-radians/?ao_noptimize=1", "f": 0.0174532925, "b": 0, "v1": 180, "ev2": 3.14159265},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/dynes-to-newtons/?ao_noptimize=1", "f": 1e-5, "b": 0, "v1": 100000, "ev2": 1},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/ergs-to-joules/?ao_noptimize=1", "f": 1e-7, "b": 0, "v1": 10000000, "ev2": 1},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/feet-to-meters/?ao_noptimize=1", "f": 0.3048, "b": 0, "v1": 1, "ev2": 0.3048},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/foot-pounds-to-newton-meters/?ao_noptimize=1", "f": 1.35581795, "b": 0, "v1": 1, "ev2": 1.35581795},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/gallons-to-liters/?ao_noptimize=1", "f": 3.78541178, "b": 0, "v1": 1, "ev2": 3.78541178},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/gigabytes-to-megabytes/?ao_noptimize=1", "f": 1000.0, "b": 0, "v1": 1, "ev2": 1000},
|
||||||
|
]
|
||||||
|
|
||||||
|
def verify_math(calc):
|
||||||
|
print(f"\n--- Verifying {calc['url']} ---")
|
||||||
|
headers = {"User-Agent": "Mozilla/5.0"}
|
||||||
|
try:
|
||||||
|
req = urllib.request.Request(calc['url'], headers=headers)
|
||||||
|
resp = urllib.request.urlopen(req).read().decode('utf-8')
|
||||||
|
|
||||||
|
scripts = re.findall(r'<script.*?>\s*(.*?)\s*</script>', resp, re.DOTALL)
|
||||||
|
logic_script = ""
|
||||||
|
for s in scripts:
|
||||||
|
if "calculate1" in s and "document.getElementById" in s:
|
||||||
|
logic_script = s
|
||||||
|
break
|
||||||
|
|
||||||
|
if not logic_script:
|
||||||
|
print("FAILED: Logic script not found.")
|
||||||
|
return False
|
||||||
|
|
||||||
|
# Extract formula: val2 = val1 * factor + offset;
|
||||||
|
# Matches: let val2 = val1 * 0.14285714285714285 + 0;
|
||||||
|
fwd_match = re.search(r'let val2 = val1 \* (.*?) \+ (.*?);', logic_script)
|
||||||
|
rev_match = re.search(r'let val1 = \(val2 - (.*?)\) \/ (.*?);', logic_script)
|
||||||
|
|
||||||
|
if not fwd_match or not rev_match:
|
||||||
|
print("FAILED: Could not parse m/b components.")
|
||||||
|
return False
|
||||||
|
|
||||||
|
m_actual = float(fwd_match.group(1))
|
||||||
|
b_actual = float(fwd_match.group(2))
|
||||||
|
|
||||||
|
print(f"Detected Formula: y = {m_actual}x + {b_actual}")
|
||||||
|
|
||||||
|
# Test math locally
|
||||||
|
v2 = calc['v1'] * m_actual + b_actual
|
||||||
|
v1 = (v2 - b_actual) / m_actual
|
||||||
|
|
||||||
|
print(f"Test v1={calc['v1']} -> v2={v2} (Expected {calc['ev2']})")
|
||||||
|
print(f"Test v2={v2} -> v1={v1} (Expected {calc['v1']})")
|
||||||
|
|
||||||
|
# Allow small floating point difference
|
||||||
|
if abs(v2 - calc['ev2']) < max(1e-7, calc['ev2'] * 1e-7) and abs(v1 - calc['v1']) < 1e-7:
|
||||||
|
print("SUCCESS")
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
print("FAILED math check")
|
||||||
|
return False
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"ERROR: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
all_ok = True
|
||||||
|
for c in batch_4_registry:
|
||||||
|
if not verify_math(c): all_ok = False
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
if all_ok: print("\nALL BATCH 4 VERIFIED.")
|
||||||
|
else: print("\nBATCH 4 FAILED.")
|
||||||
76
verify_batch_5.py
Normal file
76
verify_batch_5.py
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
import urllib.request
|
||||||
|
import re
|
||||||
|
import json
|
||||||
|
import time
|
||||||
|
|
||||||
|
# Batch 5 Registry for Verification
|
||||||
|
batch_5_registry = [
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/fahrenheit-to-celsius/?ao_noptimize=1", "f": 5/9, "o": -32 * 5/9, "v1": 32, "ev2": 0},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/fahrenheit-to-celsius/?ao_noptimize=1", "f": 5/9, "o": -32 * 5/9, "v1": 212, "ev2": 100},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/feet-per-second-to-meters-per-second/?ao_noptimize=1", "f": 0.3048, "o": 0, "v1": 1, "ev2": 0.3048},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/fluid-ounces-to-milliliters/?ao_noptimize=1", "f": 29.5735296, "o": 0, "v1": 1, "ev2": 29.5735296},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/gallons-per-minute-to-liters-per-second/?ao_noptimize=1", "f": 0.0630901964, "o": 0, "v1": 1, "ev2": 0.0630901964},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/grains-to-grams/?ao_noptimize=1", "f": 0.06479891, "o": 0, "v1": 1, "ev2": 0.06479891},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/grams-to-milligrams/?ao_noptimize=1", "f": 1000.0, "o": 0, "v1": 1, "ev2": 1000},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/grams-to-ounces/?ao_noptimize=1", "f": 0.0352739619, "o": 0, "v1": 100, "ev2": 3.52739619},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/grams-to-pennyweights/?ao_noptimize=1", "f": 0.643014931, "o": 0, "v1": 100, "ev2": 64.3014931},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/grams-to-troy-ounces/?ao_noptimize=1", "f": 0.0321507466, "o": 0, "v1": 100, "ev2": 3.21507466},
|
||||||
|
{"url": "https://howdoyouconvert.com/calculator/gray-to-rad/?ao_noptimize=1", "f": 100.0, "o": 0, "v1": 1, "ev2": 100},
|
||||||
|
]
|
||||||
|
|
||||||
|
def verify_math(calc):
|
||||||
|
print(f"\n--- Verifying {calc['url']} with v1={calc['v1']} ---")
|
||||||
|
headers = {"User-Agent": "Mozilla/5.0"}
|
||||||
|
try:
|
||||||
|
req = urllib.request.Request(calc['url'], headers=headers)
|
||||||
|
resp = urllib.request.urlopen(req).read().decode('utf-8')
|
||||||
|
|
||||||
|
scripts = re.findall(r'<script.*?>\s*(.*?)\s*</script>', resp, re.DOTALL)
|
||||||
|
logic_script = ""
|
||||||
|
for s in scripts:
|
||||||
|
if "calculate1" in s and "document.getElementById" in s:
|
||||||
|
logic_script = s
|
||||||
|
break
|
||||||
|
|
||||||
|
if not logic_script:
|
||||||
|
print("FAILED: Logic script not found.")
|
||||||
|
return False
|
||||||
|
|
||||||
|
# Extract formula: let val2 = val1 * factor + offset;
|
||||||
|
fwd_match = re.search(r'let val2 = val1 \* (.*?) \+ (.*?);', logic_script)
|
||||||
|
rev_match = re.search(r'let val1 = \(val2 - (.*?)\) \/ (.*?);', logic_script)
|
||||||
|
|
||||||
|
if not fwd_match or not rev_match:
|
||||||
|
print("FAILED: Could not parse logic components.")
|
||||||
|
return False
|
||||||
|
|
||||||
|
m_actual = float(fwd_match.group(1))
|
||||||
|
b_actual = float(fwd_match.group(2))
|
||||||
|
|
||||||
|
print(f"Detected Formula: y = {m_actual}x + {b_actual}")
|
||||||
|
|
||||||
|
# Test math locally
|
||||||
|
v2 = calc['v1'] * m_actual + b_actual
|
||||||
|
v1 = (v2 - b_actual) / m_actual
|
||||||
|
|
||||||
|
print(f"Test v1={calc['v1']} -> v2={v2} (Expected {calc['ev2']})")
|
||||||
|
|
||||||
|
# Allow small floating point difference
|
||||||
|
if abs(v2 - calc['ev2']) < max(1e-7, calc['ev2'] * 1e-7) and abs(v1 - calc['v1']) < 1e-7:
|
||||||
|
print("SUCCESS")
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
print("FAILED math check")
|
||||||
|
return False
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"ERROR: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
all_ok = True
|
||||||
|
for c in batch_5_registry:
|
||||||
|
if not verify_math(c): all_ok = False
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
if all_ok: print("\nALL BATCH 5 VERIFIED.")
|
||||||
|
else: print("\nBATCH 5 FAILED.")
|
||||||
31
verify_complex.py
Normal file
31
verify_complex.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import urllib.request
|
||||||
|
import re
|
||||||
|
|
||||||
|
def check_calculator(url, search_terms):
|
||||||
|
print(f"\n--- Checking {url} ---")
|
||||||
|
headers = {"User-Agent": "Mozilla/5.0"}
|
||||||
|
try:
|
||||||
|
req = urllib.request.Request(url, headers=headers)
|
||||||
|
html = urllib.request.urlopen(req).read().decode('utf-8')
|
||||||
|
|
||||||
|
found_all = True
|
||||||
|
for term in search_terms:
|
||||||
|
if term in html:
|
||||||
|
print(f"Found: {term}")
|
||||||
|
else:
|
||||||
|
print(f"NOT FOUND: {term}")
|
||||||
|
found_all = False
|
||||||
|
return found_all
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
# 1. ASCII to Binary
|
||||||
|
check_calculator("https://howdoyouconvert.com/calculator/ascii-to-binary/", [
|
||||||
|
"input-1", "input-2", "charCodeAt", "toString(2)"
|
||||||
|
])
|
||||||
|
|
||||||
|
# 2. Amps to Volts (Triple)
|
||||||
|
check_calculator("https://howdoyouconvert.com/calculator/amps-to-volts/", [
|
||||||
|
"input-1", "input-2", "input-3", "toFixed(2)", "a * v"
|
||||||
|
])
|
||||||
Reference in New Issue
Block a user