"""simple docstring"""


from json import JSONDecodeError  # Workaround for requests.exceptions.JSONDecodeError

import requests






def 			__UpperCAmelCase    (	lowercase = "isbn/0140328726"						):







  """simple docstring"""
  _UpperCAmelCase         =					olid.strip().strip("""/"""						)  # Remove leading/trailing whitespace & slashes
  if new_olid.count("""/"""						) != 1:
    _UpperCAmelCase         =					f'''{olid} is not a valid Open Library olid'''
    raise ValueError(lowercase						)
  return requests.get(f'''https://openlibrary.org/{new_olid}.json'''						).json()






def 			__UpperCAmelCase    (	lowercase						):







  """simple docstring"""
  _UpperCAmelCase         =					{
      """title""": """Title""",
      """publish_date""": """Publish date""",
      """authors""": """Authors""",
      """number_of_pages""": """Number of pages:""",
      """first_sentence""": """First sentence""",
      """isbn_10""": """ISBN (10)""",
      """isbn_13""": """ISBN (13)""",
  }
  _UpperCAmelCase         =					{better_key: ol_book_data[key] for key, better_key in desired_keys.items()}
  _UpperCAmelCase         =					[
      get_openlibrary_data(author["""key"""]						)["""name"""] for author in data["""Authors"""]
  ]
  _UpperCAmelCase         =					data["""First sentence"""]["""value"""]
  for key, value in data.items():
    if isinstance(lowercase      ,lowercase						):
      _UpperCAmelCase         =					""", """.join(lowercase						)
  return data


if __name__ == "__main__":
    import doctest

    doctest.testmod()

    while True:
        UpperCAmelCase__     						=  input("""\nEnter the ISBN code to search (or 'quit' to stop): """).strip()
        if isbn.lower() in ("", "q", "quit", "exit", "stop"):
            break

        if len(isbn) not in (1_0, 1_3) or not isbn.isdigit():
            print(F'''Sorry, {isbn} is not a valid ISBN.  Please, input a valid ISBN.''')
            continue

        print(F'''\nSearching Open Library for ISBN: {isbn}...\n''')

        try:
            UpperCAmelCase__     						=  summarize_book(get_openlibrary_data(F'''isbn/{isbn}'''))
            print("""\n""".join(F'''{key}: {value}''' for key, value in book_summary.items()))
        except JSONDecodeError:  # Workaround for requests.exceptions.RequestException:
            print(F'''Sorry, there are no results for ISBN: {isbn}.''')

"""simple docstring"""


UpperCAmelCase__     						=  {
    """meter""": """m""",
    """kilometer""": """km""",
    """megametre""": """Mm""",
    """gigametre""": """Gm""",
    """terametre""": """Tm""",
    """petametre""": """Pm""",
    """exametre""": """Em""",
    """zettametre""": """Zm""",
    """yottametre""": """Ym""",
}
# Exponent of the factor(meter)
UpperCAmelCase__     						=  {
    """m""": 0,
    """km""": 3,
    """Mm""": 6,
    """Gm""": 9,
    """Tm""": 1_2,
    """Pm""": 1_5,
    """Em""": 1_8,
    """Zm""": 2_1,
    """Ym""": 2_4,
}






def 			__UpperCAmelCase    (	lowercase      ,lowercase      ,lowercase						):







  """simple docstring"""
  _UpperCAmelCase         =					from_type.lower().strip("""s"""						)
  _UpperCAmelCase         =					to_type.lower().strip("""s"""						)

  _UpperCAmelCase         =					UNIT_SYMBOL.get(lowercase      ,lowercase						)
  _UpperCAmelCase         =					UNIT_SYMBOL.get(lowercase      ,lowercase						)

  if from_sanitized not in METRIC_CONVERSION:
    _UpperCAmelCase         =					(
        f'''Invalid \'from_type\' value: {from_type!r}.\n'''
        f'''Conversion abbreviations are: {", ".join(lowercase						)}'''
    )
    raise ValueError(lowercase						)
  if to_sanitized not in METRIC_CONVERSION:
    _UpperCAmelCase         =					(
        f'''Invalid \'to_type\' value: {to_type!r}.\n'''
        f'''Conversion abbreviations are: {", ".join(lowercase						)}'''
    )
    raise ValueError(lowercase						)
  _UpperCAmelCase         =					METRIC_CONVERSION[from_sanitized]
  _UpperCAmelCase         =					METRIC_CONVERSION[to_sanitized]
  _UpperCAmelCase         =					1

  if from_exponent > to_exponent:
    _UpperCAmelCase         =					from_exponent - to_exponent
  else:
    _UpperCAmelCase         =					-(to_exponent - from_exponent)

  return value * pow(10      ,lowercase						)


if __name__ == "__main__":
    from doctest import testmod

    testmod()
