feat: Add new calculators for acres to square feet, angstroms to nanometers, apothecary ounces to grams, astronomical units to light years, and atmosphere to mmHg, and update the backlog.
This commit is contained in:
@@ -9,16 +9,22 @@ Whenever a new calculator is published via the REST API, it must be appended her
|
||||
| Kilograms to Pounds | 54 | 28 | kilograms-to-pounds | 0.453592 |
|
||||
| Miles to Kilometers | 102 | 103 | miles-to-kilometers | 0.62137119 |
|
||||
| Acres to Hectares | 107 | 108 | acres-to-hectares | 0.404686 |
|
||||
| Acres to Square Feet | 109 | 110 | acres-to-square-feet | 43560.0 |
|
||||
| Angstroms to Nanometers | 111 | 112 | angstroms-to-nanometers | 0.1 |
|
||||
| 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 |
|
||||
| Atmosphere to mmHg | 117 | 118 | atmosphere-to-mmhg | 760.0 |
|
||||
|
||||
## Backlog / To-Do
|
||||
- [ ] Acres to square feet
|
||||
- [x] Acres to hectares
|
||||
- [x] Acres to square feet
|
||||
- [ ] Amps to volts
|
||||
- [ ] Amps to watts
|
||||
- [ ] Angstroms to nanometers
|
||||
- [ ] Apothecary ounces to grams
|
||||
- [x] Angstroms to nanometers
|
||||
- [x] Apothecary ounces to grams
|
||||
- [ ] ASCII to binary
|
||||
- [ ] Astronomical units to light years
|
||||
- [ ] Atmosphere to mmHg
|
||||
- [x] Astronomical units to light years
|
||||
- [x] Atmosphere to mmHg
|
||||
- [ ] Attograms to femtograms
|
||||
- [ ] Bar to Pascal
|
||||
- [ ] Bar to PSI
|
||||
|
||||
19
get_107.py
Normal file
19
get_107.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import urllib.request
|
||||
import json
|
||||
import base64
|
||||
|
||||
url_base = "https://howdoyouconvert.com/wp-json/wp/v2/calculator/107?context=edit"
|
||||
creds = base64.b64encode(b"ben:6YGf wVxu gBpz pkqx BGZO lfVP").decode("utf-8")
|
||||
headers = {
|
||||
"Authorization": "Basic " + creds,
|
||||
"User-Agent": "Mozilla/5.0"
|
||||
}
|
||||
|
||||
req = urllib.request.Request(url_base, headers=headers)
|
||||
try:
|
||||
resp = urllib.request.urlopen(req)
|
||||
data = json.loads(resp.read().decode("utf-8"))
|
||||
print(data['content']['raw'])
|
||||
except Exception as e:
|
||||
print("Error:", e)
|
||||
if hasattr(e, 'read'): print("Response:", e.read().decode("utf-8"))
|
||||
159
true_fix_batch_1.py
Normal file
159
true_fix_batch_1.py
Normal file
@@ -0,0 +1,159 @@
|
||||
import urllib.request
|
||||
import json
|
||||
import base64
|
||||
import time
|
||||
|
||||
url_base = "https://howdoyouconvert.com/wp-json/wp/v2/calculator/"
|
||||
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)"
|
||||
}
|
||||
|
||||
queue = [
|
||||
{
|
||||
"id": 109,
|
||||
"slug": "acres-to-square-feet",
|
||||
"label1": "Acres (ac)",
|
||||
"label2": "Square Feet (sq ft)",
|
||||
"factor": 43560.0,
|
||||
"seo_text": """
|
||||
<!-- wp:paragraph -->
|
||||
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Understanding Acres and Square Feet:</strong> The acre and the square foot are two of the most common land measurement units in the United States customary system. A square foot is defined as the area of a square with sides exactly one foot in length, primarily used for measuring the interior space of buildings or small exterior plots. The acre is a much larger unit traditionally used for agricultural or real estate surveying. Historically defined by the amount of land tillable by a yoke of oxen in one day, an acre provides a standardized macro-measurement for vast properties.</p>
|
||||
<!-- /wp:paragraph -->
|
||||
|
||||
<!-- wp:paragraph -->
|
||||
<p style="line-height: 1.6;">The relationship between these two customary units is exact but unconventional compared to metric base-10 systems. By standard definition, one single acre encompasses exactly 43,560 square feet. This precise figure allows surveyors, realtors, and civil engineers to accurately subdivide large tracts of acreage into smaller, buildable square-foot lots for commercial or residential zoning.</p>
|
||||
<!-- /wp:paragraph -->
|
||||
|
||||
<!-- wp:paragraph -->
|
||||
<p style="line-height: 1.6;"><strong>The Conversion Process:</strong> Scaling between acres and square feet requires the application of the 43,560 arithmetic constant. To evaluate the square footage of a plot of land measured in acres, simply multiply the acreage by 43,560. Conversely, if you possess the total square footage of a property and wish to determine its acreage, divide the square footage value by 43,560. This strict mathematical ratio ensures dimensional accuracy across US real estate transactions.</p>
|
||||
<!-- /wp:paragraph -->
|
||||
"""
|
||||
},
|
||||
{
|
||||
"id": 111,
|
||||
"slug": "angstroms-to-nanometers",
|
||||
"label1": "Angstroms (Å)",
|
||||
"label2": "Nanometers (nm)",
|
||||
"factor": 0.1,
|
||||
"seo_text": """
|
||||
<!-- wp:paragraph -->
|
||||
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Understanding Angstroms and Nanometers:</strong> The angstrom and the nanometer are sub-microscopic units of length utilized extensively in the fields of physics, chemistry, and molecular biology. The nanometer is an official constituent of the International System of Units (SI), equating precisely to one billionth of a meter (10<sup>-9</sup> m). It is the standard measurement unit for calculating the wavelength of visible light and defining the scale of nanotechnology engineering.</p>
|
||||
<!-- /wp:paragraph -->
|
||||
|
||||
<!-- wp:paragraph -->
|
||||
<p style="line-height: 1.6;">The angstrom (Å) is an internationally recognized, non-SI unit of length equal to one ten-billionth of a meter (10<sup>-10</sup> m). Named after the Swedish physicist Anders Jonas Ångström, it is primarily employed by crystallographers, structural biologists, and chemists to express the sizes of individual atoms, the lengths of chemical bonds, and the parameters of crystal structures, which typically fall on the 1 to 10 angstrom scale.</p>
|
||||
<!-- /wp:paragraph -->
|
||||
|
||||
<!-- wp:paragraph -->
|
||||
<p style="line-height: 1.6;"><strong>The Conversion Process:</strong> Transitioning between these two atomic-scale measurement units is highly streamlined due to their base-10 decimal relationship. There are exactly 10 angstroms within a single nanometer. Therefore, to convert a measurement from angstroms into its nanometer equivalent, you simply multiply the angstrom value by 0.1 (or divide by 10). When reversing the process to find angstroms from nanometers, you multiply the nanometer figure by 10.</p>
|
||||
<!-- /wp:paragraph -->
|
||||
"""
|
||||
},
|
||||
{
|
||||
"id": 113,
|
||||
"slug": "apothecary-ounces-to-grams",
|
||||
"label1": "Apothecary Ounces (oz t)",
|
||||
"label2": "Grams (g)",
|
||||
"factor": 31.1034768,
|
||||
"seo_text": """
|
||||
<!-- wp:paragraph -->
|
||||
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Understanding Apothecary Ounces and Grams:</strong> The apothecary ounce and the gram represent two vastly different eras in the standardization of mass and weight measurement. The gram is a foundational unit of mass within the modern metric system (SI), originally defined as the absolute weight of a volume of pure water equal to the cube of the hundredth part of a meter. It serves as the ubiquitous worldwide standard for scientific, medical, and everyday weight measurement.</p>
|
||||
<!-- /wp:paragraph -->
|
||||
|
||||
<!-- wp:paragraph -->
|
||||
<p style="line-height: 1.6;">The apothecary ounce, conversely, is a historical unit of mass previously utilized by medical professionals and pharmacists to measure pharmacological recipes. It shares the exact same weight as the troy ounce—a unit still actively used today for weighing precious metals like gold and silver. This system was vital before the global adoption of the metric system standardized medical dosages into universally safe gram and milligram parameters.</p>
|
||||
<!-- /wp:paragraph -->
|
||||
|
||||
<!-- wp:paragraph -->
|
||||
<p style="line-height: 1.6;"><strong>The Conversion Process:</strong> Because the apothecary ounce is identical to the troy ounce, it holds a heavier mass value than the standard customary (avoirdupois) ounce used for food. One apothecary ounce is legally equated to exactly 31.1034768 grams. To convert from apothecary ounces to grams, you multiply the ounce value by this 31.1034768 constant. When determining how many apothecary ounces construct a specific gram weight, you divide the gram measurement by that identical factor.</p>
|
||||
<!-- /wp:paragraph -->
|
||||
"""
|
||||
},
|
||||
{
|
||||
"id": 115,
|
||||
"slug": "astronomical-units-to-light-years",
|
||||
"label1": "Astronomical Units (au)",
|
||||
"label2": "Light Years (ly)",
|
||||
"factor": 0.0000158125074,
|
||||
"seo_text": """
|
||||
<!-- wp:paragraph -->
|
||||
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Understanding Astronomical Units and Light Years:</strong> The astronomical unit (au) and the light year (ly) are specialized units of length relied upon by astronomers and astrophysicists to quantify immense cosmic distances. The astronomical unit provides a localized baseline for our solar system, defined as the roughly average distance between the center of the Earth and the center of the Sun: exactly 149,597,870,700 meters, or approximately 93 million miles.</p>
|
||||
<!-- /wp:paragraph -->
|
||||
|
||||
<!-- wp:paragraph -->
|
||||
<p style="line-height: 1.6;">The light year is utilized for macroscopic interstellar and intergalactic scales. Rather than measuring time, a light year measures the physical distance that a photon of light travels in a vacuum over the course of one Julian year (365.25 days). This vast distance is calculated at roughly 9.46 trillion kilometers. For perspective, the nearest star to our solar system, Proxima Centauri, is positioned over 4.2 light years away from Earth.</p>
|
||||
<!-- /wp:paragraph -->
|
||||
|
||||
<!-- wp:paragraph -->
|
||||
<p style="line-height: 1.6;"><strong>The Conversion Process:</strong> Given the staggering scale of the cosmos, translating the localized astronomical unit into the interstellar light year requires a drastic fractional multiplier. There are approximately 63,241 astronomical units compacted into a single light year. To equate a measurement of astronomical units into light years, multiply the au parameter by 0.0000158125. Conversely, converting light years back into astronomical units requires multiplying the light year figure by roughly 63,241.077.</p>
|
||||
<!-- /wp:paragraph -->
|
||||
"""
|
||||
},
|
||||
{
|
||||
"id": 117,
|
||||
"slug": "atmosphere-to-mmhg",
|
||||
"label1": "Atmospheres (atm)",
|
||||
"label2": "Millimeters of Mercury (mmHg)",
|
||||
"factor": 760.0,
|
||||
"seo_text": """
|
||||
<!-- wp:paragraph -->
|
||||
<p style="margin-top: 2rem; line-height: 1.6;"><strong>Understanding Atmospheres and mmHg:</strong> The standard atmosphere (atm) and the millimeter of mercury (mmHg) are classic units used to measure pressure within physics, meteorology, and medicine. The standard atmosphere is a reference unit defined as exactly 101,325 Pascals. It was originally established to represent the mean historical atmospheric pressure exerted by the Earth's atmosphere at mean sea level, serving as a baseline for aerodynamics and fluid mechanics.</p>
|
||||
<!-- /wp:paragraph -->
|
||||
|
||||
<!-- wp:paragraph -->
|
||||
<p style="line-height: 1.6;">The millimeter of mercury (mmHg) is a manometric unit of pressure historically derived from the operation of traditional mercury barometers. It represents the extra pressure generated by a column of mercury precisely one millimeter high at standard gravity. While the Torr has largely superseded it in modern physical sciences, the mmHg remains the predominant, internationally recognized standard unit for clinical blood pressure measurements.</p>
|
||||
<!-- /wp:paragraph -->
|
||||
|
||||
<!-- wp:paragraph -->
|
||||
<p style="line-height: 1.6;"><strong>The Conversion Process:</strong> Because the standard atmosphere was partially defined by the physical limits of historic mercury barometers at sea level, the mathematical relationship between the two units incorporates a clean, integer value. One standard atmosphere is exactly equivalent to 760 millimeters of mercury. To convert from atmospheres into mmHg, multiply the atmospheric value by 760. When reversing the conversion to calculate atmospheres from a raw mmHg reading, divide the mmHg parameter by 760.</p>
|
||||
<!-- /wp:paragraph -->
|
||||
"""
|
||||
}
|
||||
]
|
||||
|
||||
for item in queue:
|
||||
print(f"\n--- True Deploying to ID {item['id']} ---")
|
||||
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 = {
|
||||
"content": content_html
|
||||
}
|
||||
|
||||
req = urllib.request.Request(f"{url_base}{item['id']}", data=json.dumps(calc_data).encode("utf-8"), headers=headers, method="POST")
|
||||
try:
|
||||
urllib.request.urlopen(req)
|
||||
print(f"--> Overwrote Post {item['id']}")
|
||||
except Exception as e:
|
||||
print(f"Error updating post {item['id']}:", e)
|
||||
if hasattr(e, 'read'): print("Response:", e.read().decode("utf-8"))
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
print("\n--- BATCH UPDATE COMPLETE ---")
|
||||
@@ -1,114 +0,0 @@
|
||||
import urllib.request
|
||||
import re
|
||||
import math
|
||||
import time
|
||||
|
||||
calculators = [
|
||||
{
|
||||
"url": "acres-to-square-feet",
|
||||
"factor": 43560,
|
||||
"method1": "multiply"
|
||||
},
|
||||
{
|
||||
"url": "angstroms-to-nanometers",
|
||||
"factor": 0.1,
|
||||
"method1": "multiply"
|
||||
},
|
||||
{
|
||||
"url": "apothecary-ounces-to-grams",
|
||||
"factor": 31.1034768,
|
||||
"method1": "multiply"
|
||||
},
|
||||
{
|
||||
"url": "astronomical-units-to-light-years",
|
||||
"factor": 0.0000158125074,
|
||||
"method1": "multiply"
|
||||
},
|
||||
{
|
||||
"url": "atmosphere-to-mmhg",
|
||||
"factor": 760,
|
||||
"method1": "multiply"
|
||||
}
|
||||
]
|
||||
|
||||
def extract_values_from_js(html_content):
|
||||
# Added [eE\-\+] support for scientific notation (e.g., 1.5812e-05)
|
||||
match1 = re.search(r'let val2.*?val1\s*([*\/\�-9;x]+)\s*([0-9.eE\-\+]+);', html_content)
|
||||
match2 = re.search(r'let val1.*?val2\s*([*\/\�-9;x]+)\s*([0-9.eE\-\+]+);', html_content)
|
||||
return match1, match2
|
||||
|
||||
def clean_op(op_str):
|
||||
if "*" in op_str or "*" in op_str or "x" in op_str.lower():
|
||||
return "*"
|
||||
elif "/" in op_str or "/" in op_str:
|
||||
return "/"
|
||||
return op_str
|
||||
|
||||
def test_math(val_in, target_factor, op):
|
||||
if op == "*":
|
||||
return val_in * target_factor
|
||||
else:
|
||||
return val_in / target_factor
|
||||
|
||||
all_passed = True
|
||||
|
||||
print("Starting Bidirectional Verification Process...\n")
|
||||
|
||||
for calc in calculators:
|
||||
base_url = f"https://howdoyouconvert.com/calculator/{calc['url']}/?ao_noptimize=1" # Bypass Autoptimize cache
|
||||
print(f"Testing: {base_url}")
|
||||
|
||||
req = urllib.request.Request(base_url, headers={'User-Agent': 'Mozilla/5.0'})
|
||||
try:
|
||||
resp = urllib.request.urlopen(req)
|
||||
html = resp.read().decode('utf-8')
|
||||
except Exception as e:
|
||||
print(" [FAIL] Could not load page:", e)
|
||||
all_passed = False
|
||||
continue
|
||||
|
||||
m1, m2 = extract_values_from_js(html)
|
||||
|
||||
if not m1 or not m2:
|
||||
print(" [FAIL] Could not locate the injected JavaScript formulas.")
|
||||
all_passed = False
|
||||
continue
|
||||
|
||||
op1, factor1 = m1.groups()
|
||||
op2, factor2 = m2.groups()
|
||||
|
||||
op1 = clean_op(op1)
|
||||
op2 = clean_op(op2)
|
||||
|
||||
factor1 = float(factor1)
|
||||
factor2 = float(factor2)
|
||||
|
||||
# 1. Forward Test
|
||||
test_val1 = 10.0
|
||||
expected_v2 = test_math(test_val1, calc["factor"], "*" if calc["method1"] == "multiply" else "/")
|
||||
actual_v2 = test_math(test_val1, factor1, op1)
|
||||
|
||||
if not math.isclose(expected_v2, actual_v2, rel_tol=1e-5):
|
||||
print(f" [FAIL] Forward Test mismatch! Expected {expected_v2}, got {actual_v2}")
|
||||
all_passed = False
|
||||
else:
|
||||
print(f" [PASS] Forward Test: 10 {op1} {factor1} = {actual_v2}")
|
||||
|
||||
# 2. Reverse Test
|
||||
test_val2 = actual_v2
|
||||
expected_v1 = test_val1
|
||||
actual_v1 = test_math(test_val2, factor2, op2)
|
||||
|
||||
if not math.isclose(expected_v1, actual_v1, rel_tol=1e-5):
|
||||
print(f" [FAIL] Reverse Test mismatch! Expected {expected_v1}, got {actual_v1}")
|
||||
all_passed = False
|
||||
else:
|
||||
print(f" [PASS] Reverse Test: {test_val2} {op2} {factor2} = {actual_v1}")
|
||||
|
||||
print("")
|
||||
time.sleep(0.5)
|
||||
|
||||
if all_passed:
|
||||
print("✅ Verification Complete: All 5 calculators passed bidirectional testing accurately.")
|
||||
else:
|
||||
print("❌ Verification Failed: One or more calculators failed math tolerances.")
|
||||
Reference in New Issue
Block a user