



"""simple docstring"""
import multiprocessing
from typing import TYPE_CHECKING, Optional, Union

from .. import Dataset, Features, config
from ..formatting import query_table
from ..packaged_modules.sql.sql import Sql
from ..utils import logging
from .abc import AbstractDatasetInputStream


if TYPE_CHECKING:
      import sqlitea

      import sqlalchemy



class    SCREAMING_SNAKE_CASE__						(      UpperCAmelCase__				):

   def __init__(     self   ,  _SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE = None   ,  _SCREAMING_SNAKE_CASE = None   ,  _SCREAMING_SNAKE_CASE = False   ,  **_SCREAMING_SNAKE_CASE   ,  )						->   List[Any]:





    '''simple docstring'''




    super().__init__(features=_SCREAMING_SNAKE_CASE   ,  cache_dir=_SCREAMING_SNAKE_CASE   ,  keep_in_memory=_SCREAMING_SNAKE_CASE   ,  **_SCREAMING_SNAKE_CASE		)
    UpperCAmelCase			:      List[str]			=			Sql(
        cache_dir=_SCREAMING_SNAKE_CASE   ,  features=_SCREAMING_SNAKE_CASE   ,  sql=_SCREAMING_SNAKE_CASE   ,  con=_SCREAMING_SNAKE_CASE   ,  **_SCREAMING_SNAKE_CASE   ,  )




   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Dict:





    '''simple docstring'''




    UpperCAmelCase			:      Optional[int]			=			None
    UpperCAmelCase			:      List[Any]			=			None
    UpperCAmelCase			:      Optional[Any]			=			None
    UpperCAmelCase			:      Optional[int]			=			None

    self.builder.download_and_prepare(
        download_config=_SCREAMING_SNAKE_CASE   ,  download_mode=_SCREAMING_SNAKE_CASE   ,  verification_mode=_SCREAMING_SNAKE_CASE   ,  base_path=_SCREAMING_SNAKE_CASE   ,  )

    # Build dataset for splits
    UpperCAmelCase			:      Dict			=			self.builder.as_dataset(
        split="""train"""   ,  verification_mode=_SCREAMING_SNAKE_CASE   ,  in_memory=self.keep_in_memory		)
    return dataset



class    SCREAMING_SNAKE_CASE__						:

   def __init__(     self   ,  _SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE = None   ,  _SCREAMING_SNAKE_CASE = None   ,  **_SCREAMING_SNAKE_CASE   ,  )						->   int:





    '''simple docstring'''




    if num_proc is not None and num_proc <= 0:
     raise ValueError(F"num_proc {num_proc} must be an integer > 0."		)

    UpperCAmelCase			:      Any			=			dataset
    UpperCAmelCase			:      Tuple			=			name
    UpperCAmelCase			:      List[Any]			=			con
    UpperCAmelCase			:      Any			=			batch_size if batch_size else config.DEFAULT_MAX_BATCH_SIZE
    UpperCAmelCase			:      str			=			num_proc
    UpperCAmelCase			:      Tuple			=			to_sql_kwargs

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   int:





    '''simple docstring'''




    UpperCAmelCase			:      str			=			self.to_sql_kwargs.pop("""sql"""   ,  _SCREAMING_SNAKE_CASE		)
    UpperCAmelCase			:      Tuple			=			self.to_sql_kwargs.pop("""con"""   ,  _SCREAMING_SNAKE_CASE		)
    UpperCAmelCase			:      int			=			self.to_sql_kwargs.pop("""index"""   ,  _SCREAMING_SNAKE_CASE		)

    UpperCAmelCase			:      Optional[Any]			=			self._write(index=_SCREAMING_SNAKE_CASE   ,  **self.to_sql_kwargs		)
    return written

   def 			SCREAMING_SNAKE_CASE  (     self   ,  _SCREAMING_SNAKE_CASE		)						->   int:





    '''simple docstring'''




    UpperCAmelCase			,	UpperCAmelCase			,	UpperCAmelCase			:      Optional[int]			=			args
    UpperCAmelCase			:      str			=			{**to_sql_kwargs, """if_exists""": """append"""} if offset > 0 else to_sql_kwargs
    UpperCAmelCase			:      str			=			query_table(
        table=self.dataset.data   ,  key=slice(_SCREAMING_SNAKE_CASE   ,  offset + self.batch_size		)   ,  indices=self.dataset._indices   ,  )
    UpperCAmelCase			:      Tuple			=			batch.to_pandas()
    UpperCAmelCase			:      int			=			df.to_sql(self.name   ,  self.con   ,  index=_SCREAMING_SNAKE_CASE   ,  **_SCREAMING_SNAKE_CASE		)
    return num_rows or len(_SCREAMING_SNAKE_CASE		)




   def 			SCREAMING_SNAKE_CASE  (     self   ,  _SCREAMING_SNAKE_CASE   ,  **_SCREAMING_SNAKE_CASE		)						->   int:





    '''simple docstring'''




    UpperCAmelCase			:      Any			=			0

    if self.num_proc is None or self.num_proc == 1:
     for offset in logging.tqdm(
         range(0   ,  len(self.dataset		)   ,  self.batch_size		)   ,  unit="""ba"""   ,  disable=not logging.is_progress_bar_enabled()   ,  desc="""Creating SQL from Arrow format"""   ,  ):
      written += self._batch_sql((offset, index, to_sql_kwargs)		)
    else:
     UpperCAmelCase			,	UpperCAmelCase			:      Tuple			=			len(self.dataset		), self.batch_size
     with multiprocessing.Pool(self.num_proc		) as pool:
      for num_rows in logging.tqdm(
          pool.imap(
              self._batch_sql   ,  [(offset, index, to_sql_kwargs) for offset in range(0   ,  _SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE		)]   ,  )   ,  total=(num_rows // batch_size) + 1 if num_rows % batch_size else num_rows // batch_size   ,  unit="""ba"""   ,  disable=not logging.is_progress_bar_enabled()   ,  desc="""Creating SQL from Arrow format"""   ,  ):
       written += num_rows

    return written





"""simple docstring"""
import requests
from bsa import BeautifulSoup

def    _snake_case		(		UpperCamelCase		:	str = "AAPL"		):
 UpperCAmelCase			:      Any			=			F"https://in.finance.yahoo.com/quote/{symbol}?s={symbol}"
 UpperCAmelCase			:      Optional[int]			=			BeautifulSoup(requests.get(UpperCamelCase		).text    ,	"""html.parser"""		)
 UpperCAmelCase			:      int			=			"""My(6px) Pos(r) smartphone_Mt(6px)"""
 return soup.find("""div"""    ,	class_=class_		).find("""span"""		).text


if __name__ == "__main__":
      for symbol in "AAPL AMZN IBM GOOG MSFT ORCL".split():
            print(f"""Current {symbol:<4} stock price is {stock_price(symbol):>8}""")
