juandesant, Spanish

Hace tiempo que tendría que haber escrito sobre las charadas (riddles) the Howard Oakley, una de las cosas que más me gustan de su siempre interesante blog The Eclectic Light Company.

Solutions to Saturday Mac riddles 247

Enlace a la última (a la fecha) entrada Solutions to Saturday Mac riddles 247.Lo más curioso es que lleva desde el 29 de Junio de 2019 publicándolas sin saltárselas ni una sola semana… pero no tiene forma de encontrar esas charadas de los sábados — y las soluciones de los lunes — de forma sencilla.

Así que me puse a escribir un script en Python que me proporciona el URL de cualquier charada, o su solución, asumiendo que se sigan publicando de forma ininterrumpida.

Aquí lo tenéis, por si os sirve de algo (con sus comentarios):

import datetime as dt<br></br><br></br>def riddle_for_date(date, solutions=False):<br></br>    base_date = dt.datetime(2019,6,29)<br></br>    if solutions: # A monday<br></br>        base_date = base_date+dt.timedelta(days=2)<br></br>        <br></br>    return ((date-base_date).days//7 + 1)<br></br><br></br>def date_for_riddle(riddle_num, solutions=True):<br></br>    """<br></br>    Computes the date associated with a given Eclectic Light Co Saturday's riddle number, considering whether to give the date for the riddle or for the solution.<br></br><br></br>    Parameters:<br></br>    riddle_num (int): The number of the riddle for which to calculate the date.<br></br>    solutions (bool): Indicates whether to use the solution's or the riddle's date. Default is True (for the solution's date).<br></br><br></br>    Returns:<br></br>    datetime: The computed date associated with the specified riddle number.<br></br><br></br>    Raises:<br></br>    ValueError: If the specified riddle number is less than 1.<br></br>    """<br></br>    # Set a base date for the riddles<br></br>    # The first riddle was issued on June 29th, 2019<br></br>    base_date = dt.datetime(2019, 6, 29)<br></br><br></br>    # Adjust base date to the next Monday (two days after)<br></br>    # if solutions are requested<br></br>    if solutions:<br></br>        base_date = base_date + dt.timedelta(days=2)<br></br><br></br>    # Validate riddle number<br></br>    riddle_num = int(riddle_num)<br></br><br></br>    # We use -1 to indicate the latest date<br></br>    if riddle_num < 1 and riddle_num != -1:<br></br>        raise ValueError(f"The specified riddle number ({riddle_num}) is less than 1, and not -1.")<br></br><br></br>    # Compute the date associated with the riddle number<br></br>    # by adding as many weeks as the riddle number - 1.<br></br>    if riddle_num == -1: # Latest riddle<br></br>        riddle_num = riddle_for_date(dt.datetime.today(),solutions=solutions)<br></br>    result = base_date + (riddle_num - 1) * dt.timedelta(days=7)<br></br>    return result<br></br><br></br><br></br>def url_for_riddle(riddle_num, solutions=True, open_in_browser=False):<br></br>    """<br></br>    Generates a URL for accessing a specific Mac riddle from the Eclectic Light Company's blog.<br></br><br></br>    Parameters:<br></br>    riddle_num (int): The number of the riddle to generate URL for.<br></br>    solutions (bool): Indicates whether the URL should lead to the riddle's solutions (True), or just to the original riddle. Default is True.<br></br>    open_in_browser (bool): Indicates whether the generated URL should be opened in the default web browser. Default is False.<br></br><br></br>    Returns:<br></br>    str: The generated URL for the specified Mac riddle.<br></br><br></br>    Raises:<br></br>    ValueError (through `date_for_riddle`) if the riddle_num is less than 1, or not an int.<br></br>    """<br></br>    if riddle_num == -1:<br></br>        riddle_num = riddle_for_date(dt.datetime.now(),solutions=solutions)<br></br>    date = date_for_riddle(riddle_num,solutions=solutions)<br></br>    slug = f"saturday-mac-riddles-{riddle_num}/"<br></br>    <br></br>    result = f"https://eclecticlight.co/{date.year:04d}/{date.month:02d}/{date.day:02}/"<br></br>    if solutions:<br></br>        result += f"solutions-to-{slug}"<br></br>    else:<br></br>        result += slug<br></br>    <br></br>    if open_in_browser:<br></br>        import webbrowser<br></br>        webbrowser.open(result)<br></br>        <br></br>    return result

Perdón por haberlo escrito en inglés, pero dado que el sitio de Howard Oakley está en inglés, lo preferí. Con ese código en Python, ahora podéis teclear algo como:

url_for_riddle(-1,True,True)

Y se abrirá en vuestro navegador por defecto las soluciones a la última charada de Howard Oakley.

https://juandesant.wpcomstaging.com/2024/03/21/the-eclectic-light-company-y-las-charadas-de-howard-oakley/

juandesant,
@juandesant@astrodon.social avatar

@juandesant probando si este comentario acaba en el blog…

  • All
  • Subscribed
  • Moderated
  • Favorites
  • python
  • DreamBathrooms
  • magazineikmin
  • ethstaker
  • InstantRegret
  • tacticalgear
  • rosin
  • love
  • Youngstown
  • slotface
  • ngwrru68w68
  • kavyap
  • cubers
  • thenastyranch
  • mdbf
  • megavids
  • cisconetworking
  • GTA5RPClips
  • modclub
  • khanakhh
  • everett
  • Leos
  • osvaldo12
  • normalnudes
  • tester
  • Durango
  • anitta
  • provamag3
  • JUstTest
  • All magazines