


from functools import partial
from typing import Any, Callable, Dict, List, Type, TypeVar, Union, overload

import torch
import torch.nn as nn
import torch.types

def 				lowercase_		(		_A      :   torch.Tensor   , _A      :   torch.Tensor   , _A      :   bool						):

      """simple docstring"""




      if not inplace:
            lowerCamelCase__		:    Optional[int]   =  ma + ma
      else:
            ma += ma

      return ma

def 				lowercase_		(		_A      :   torch.Tensor   , _A      :   List[int]						):

      """simple docstring"""




      lowerCamelCase__		:    str   =  -1 * len(_A						)
      lowerCamelCase__		:    Dict   =  list(range(len(tensor.shape[:zero_index]						)						)						)
      return tensor.permute(first_inds + [zero_index + i for i in inds]						)

def 				lowercase_		(		_A      :   torch.Tensor   , _A      :   int						):

      """simple docstring"""




      return t.reshape(t.shape[:-no_dims] + (-1,)						)

def 				lowercase_		(		_A      :   torch.Tensor   , _A      :   torch.Tensor   , _A      :   int   , _A      :   float = 1E-4						):

      """simple docstring"""




      lowerCamelCase__		:    List[str]   =  mask.expand(*value.shape						)
      return torch.sum(mask * value   , dim=_A						) / (eps + torch.sum(_A   , dim=_A						))

def 				lowercase_		(		_A      :   torch.Tensor   , _A      :   torch.types.Number = 2.3_125   , _A      :   torch.types.Number = 21.6_875   , _A      :   int = 64						):

      """simple docstring"""




      lowerCamelCase__		:    Any   =  torch.linspace(_A   , _A   , no_bins - 1   , device=pts.device						)
      lowerCamelCase__		:    Optional[int]   =  torch.sqrt(torch.sum((pts.unsqueeze(-2						) - pts.unsqueeze(-3						)) ** 2   , dim=-1						)						)
      return torch.bucketize(_A   , _A						)

def 				lowercase_		(		_A      :   Callable[[list], Any]   , _A      :   List[dict]						):

      """simple docstring"""




      lowerCamelCase__		:    Optional[Any]   =  dicts[0]
      lowerCamelCase__		:    List[str]   =  {}
      for k, v in first.items():
            lowerCamelCase__		:    Optional[int]   =  [d[k] for d in dicts]
            if isinstance(_A   , _A						):
                  lowerCamelCase__		:    Dict   =  dict_multimap(_A   , _A						)
            else:
                  lowerCamelCase__		:    List[str]   =  fn(_A						)

      return new_dict

def 				lowercase_		(		_A      :   torch.Tensor   , _A      :   torch.Tensor						):

      """simple docstring"""




      lowerCamelCase__		:    Optional[Any]   =  v_bins.view(((1,) * len(x.shape						)) + (len(_A						),)						)
      lowerCamelCase__		:    List[Any]   =  x[..., None] - reshaped_bins
      lowerCamelCase__		:    int   =  torch.argmin(torch.abs(_A						)   , dim=-1						)
      return nn.functional.one_hot(_A   , num_classes=len(_A						)						).float()

def 				lowercase_		(		_A      :   torch.Tensor   , _A      :   torch.Tensor   , _A      :   int = 0   , _A      :   int = 0						):

      """simple docstring"""




      lowerCamelCase__		:    List[Union[slice, torch.Tensor]]   =  []
      for i, s in enumerate(data.shape[:no_batch_dims]						):
            lowerCamelCase__		:    Any   =  torch.arange(_A						)
            lowerCamelCase__		:    List[str]   =  r.view(*(*((1,) * i), -1, *((1,) * (len(inds.shape						) - i - 1)))						)
            ranges.append(_A						)

      lowerCamelCase__		:    List[Union[slice, torch.Tensor]]   =  [slice(_A						) for _ in range(len(data.shape						) - no_batch_dims						)]
      lowerCamelCase__		:    int   =  inds
      ranges.extend(_A						)
      # Matt note: Editing this to get around the behaviour of using a list as an array index changing
      # in recent Numpy versions
      return data[tuple(_A						)]


A				:   Any		= TypeVar("T")

def 				lowercase_		(		_A      :   Callable[[T], Any]   , _A      :   Dict[Any, Union[dict, list, tuple, T]]   , _A      :   Type[T]						):

      """simple docstring"""




      lowerCamelCase__		:    Dict[Any, Union[dict, list, tuple, Any]]   =  {}
      for k, v in dic.items():
            if isinstance(_A   , _A						):
                  lowerCamelCase__		:    Any   =  dict_map(_A   , _A   , _A						)
            else:
                  lowerCamelCase__		:    Union[str, Any]   =  tree_map(_A   , _A   , _A						)

      return new_dict

@overload
def 				lowercase_		(		_A      :   Callable[[T], Any]   , _A      :   T   , _A      :   Type[T]						):

      """simple docstring"""




      ...

@overload
def 				lowercase_		(		_A      :   Callable[[T], Any]   , _A      :   dict   , _A      :   Type[T]						):

      """simple docstring"""




      ...

@overload
def 				lowercase_		(		_A      :   Callable[[T], Any]   , _A      :   list   , _A      :   Type[T]						):

      """simple docstring"""




      ...

@overload
def 				lowercase_		(		_A      :   Callable[[T], Any]   , _A      :   tuple   , _A      :   Type[T]						):

      """simple docstring"""




      ...

def 				lowercase_		(		_A      :   str   , _A      :   Optional[Any]   , _A      :   int						):

      """simple docstring"""




      if isinstance(_A   , _A						):
            return dict_map(_A   , _A   , _A						)
      elif isinstance(_A   , _A						):
            return [tree_map(_A   , _A   , _A						) for x in tree]
      elif isinstance(_A   , _A						):
            return tuple(tree_map(_A   , _A   , _A						) for x in tree						)
      elif isinstance(_A   , _A						):
            return fn(_A						)
      else:
            print(type(_A						)						)
            raise ValueError("Not supported"						)


A				:   int		= partial(tree_map, leaf_type=torch.Tensor)






from urllib.error import HTTPError

from bsa import BeautifulSoup
from requests import exceptions, get

A				:   List[str]		= "https://www.wellrx.com/prescriptions/{0}/{1}/?freshSearch=true"

def 				lowercase_		(		_A      :   str   , _A      :   str						):

      """simple docstring"""




      try:
            # Has user provided both inputs?
            if not drug_name or not zip_code:
                  return None

            lowerCamelCase__		:    List[str]   =  BASE_URL.format(_A   , _A						)
            lowerCamelCase__		:    int   =  get(_A						)

            # Is the response ok?
            response.raise_for_status()

            # Scrape the data using bs4
            lowerCamelCase__		:    Dict   =  BeautifulSoup(response.text   , "html.parser"						)

            # This list will store the name and price.
            lowerCamelCase__		:    int   =  []

            # Fetch all the grids that contains the items.
            lowerCamelCase__		:    List[str]   =  soup.find_all("div"   , {"class": "grid-x pharmCard"}						)
            if grid_list and len(_A						) > 0:
                  for grid in grid_list:
                        # Get the pharmacy price.
                        lowerCamelCase__		:    Optional[int]   =  grid.find("p"   , {"class": "list-title"}						).text

                        # Get price of the drug.
                        lowerCamelCase__		:    Union[str, Any]   =  grid.find("span"   , {"p", "price price-large"}						).text

                        pharmacy_price_list.append(
                            {
                                "pharmacy_name": pharmacy_name,
                                "price": price,
                            }						)

            return pharmacy_price_list

      except (HTTPError, exceptions.RequestException, ValueError):
            return None


if __name__ == "__main__":
    # Enter a drug name and a zip code
    A				:   Any		= input("Enter drug name: ").strip()
    A				:   Union[str, Any]		= input("Enter zip code: ").strip()

    A				:   list | None		= fetch_pharmacy_and_price_list(
        drug_name, zip_code
    )

    if pharmacy_price_list:
        print(f'\nSearch results for {drug_name} at location {zip_code}:')
        for pharmacy_price in pharmacy_price_list:
            A				:   Dict		= pharmacy_price["pharmacy_name"]
            A				:   Optional[int]		= pharmacy_price["price"]

            print(f'Pharmacy: {name} Price: {price}')
    else:
        print(f'No results found for {drug_name}')


