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": """

Time Conversion - Days to Weeks: 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.

""" }, { "title": "Days to Years", "slug": "days-to-years", "label1": "Days", "label2": "Years", "factor": 1/365.25, "offset": 0, "seo_text": """

Time Conversion - Days to Years: 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.

""" }, { "title": "Degrees to Mils", "slug": "degrees-to-mils", "label1": "Degrees (°)", "label2": "Mils", "factor": 17.777777778, "offset": 0, "seo_text": """

Angle Measurement - Degrees to Mils: While degrees are common in everyday use, mils (milliradians) are frequently used in military and engineering contexts for precise targeting and measurement.

""" }, { "title": "Degrees to Radians", "slug": "degrees-to-radians", "label1": "Degrees (°)", "label2": "Radians (rad)", "factor": 0.0174532925, "offset": 0, "seo_text": """

Mathematical Precision - Degrees to Radians: Radians are the standard unit of angular measure used in mathematics, physics, and computer science. This calculator provides a quick conversion from common degrees.

""" }, { "title": "Dynes to Newtons", "slug": "dynes-to-newtons", "label1": "Dynes", "label2": "Newtons (N)", "factor": 1e-5, "offset": 0, "seo_text": """

Force Measurement - Dynes to Newtons: 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.

""" }, { "title": "Ergs to Joules", "slug": "ergs-to-joules", "label1": "Ergs", "label2": "Joules (J)", "factor": 1e-7, "offset": 0, "seo_text": """

Energy Conversion - Ergs to Joules: 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.

""" }, { "title": "Feet to Meters", "slug": "feet-to-meters", "label1": "Feet (ft)", "label2": "Meters (m)", "factor": 0.3048, "offset": 0, "seo_text": """

Length Conversion - Feet to Meters: 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.

""" }, { "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": """

Torque Conversion: Foot-pounds and newton-meters are units used to measure torque or work. This calculator is particularly useful for mechanics and engineers.

""" }, { "title": "Gallons to Liters", "slug": "gallons-to-liters", "label1": "Gallons (US)", "label2": "Liters (L)", "factor": 3.78541178, "offset": 0, "seo_text": """

Volume Conversion - Gallons to Liters: Converting between US gallons and metric liters is a common requirement in automotive, culinary, and scientific fields.

""" }, { "title": "Gigabytes to Megabytes", "slug": "gigabytes-to-megabytes", "label1": "Gigabytes (GB)", "label2": "Megabytes (MB)", "factor": 1000.0, "offset": 0, "seo_text": """

Digital Storage - GB to MB: This calculator uses the standard decimal (base-10) convention used by hard drive manufacturers and memory card providers, where 1 GB = 1,000 MB.

""" } ] for item in batch_4: print(f"\\n--- Processing {item['title']} ---") slug_raw = item['slug'].replace("-", "") content_html = f"""
{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"""""" 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 ---")