


# This code is adapted from OpenAI's release
# https://github.com/openai/human-eval/blob/master/human_eval/execution.py

import contextlib
import faulthandler
import io
import multiprocessing
import os
import platform
import signal
import tempfile





def 	_lowerCAmelCase       (    _lowerCAmelCase      ,	_lowerCAmelCase      ,	_lowerCAmelCase      ,	_lowerCAmelCase )						->	Dict:


						'''simple docstring'''






						__snake_case				=		multiprocessing.Manager()
						__snake_case				=		manager.list()

						__snake_case				=		multiprocessing.Process(target=_lowerCAmelCase      ,	args=(check_program, result, timeout) )
						p.start()
						p.join(timeout=timeout + 1 )
						if p.is_alive():
												p.kill()

						if not result:
												result.append("timed out" )

						return {
						    "task_id": task_id,
						    "passed": result[0] == "passed",
						    "result": result[0],
						    "completion_id": completion_id,
						}





def 	_lowerCAmelCase       (    _lowerCAmelCase      ,	_lowerCAmelCase      ,	_lowerCAmelCase )						->	Dict:


						'''simple docstring'''






						with create_tempdir():
												# These system calls are needed when cleaning up tempdir.
												import os
												import shutil

												__snake_case				=		shutil.rmtree
												__snake_case				=		os.rmdir
												__snake_case				=		os.chdir

												# Disable functionalities that can make destructive changes to the test.
												reliability_guard()

												# Run program.
												try:
																		__snake_case				=		{}
																		with swallow_io():
																								with time_limit(_lowerCAmelCase ):
																														exec(_lowerCAmelCase      ,	_lowerCAmelCase )
																		result.append("passed" )
												except TimeoutException:
																		result.append("timed out" )
												except BaseException as e:
																		result.append(F'''failed: {e}''' )

												# Needed for cleaning up.
												__snake_case				=		rmtree
												__snake_case				=		rmdir
												__snake_case				=		chdir





@contextlib.contextmanager
def 	_lowerCAmelCase       (    _lowerCAmelCase )						->	Union[str, Any]:


						'''simple docstring'''






						def signal_handler(_lowerCAmelCase      ,	_lowerCAmelCase ):
												raise TimeoutException("Timed out!" )

						signal.setitimer(signal.ITIMER_REAL      ,	_lowerCAmelCase )
						signal.signal(signal.SIGALRM      ,	_lowerCAmelCase )
						try:
												yield
						finally:
												signal.setitimer(signal.ITIMER_REAL      ,	0 )





@contextlib.contextmanager
def 	_lowerCAmelCase       (    )						->	Any:


						'''simple docstring'''






						__snake_case				=		WriteOnlyStringIO()
						with contextlib.redirect_stdout(_lowerCAmelCase ):
												with contextlib.redirect_stderr(_lowerCAmelCase ):
																		with redirect_stdin(_lowerCAmelCase ):
																								yield





@contextlib.contextmanager
def 	_lowerCAmelCase       (    )						->	str:


						'''simple docstring'''






						with tempfile.TemporaryDirectory() as dirname:
												with chdir(_lowerCAmelCase ):
																		yield dirname






class     UpperCamelCase(  snake_case__   ):
					pass






class     UpperCamelCase(  io.StringIO   ):


					def 							SCREAMING_SNAKE_CASE_  (						self	:		int     ,    *SCREAMING_SNAKE_CASE	:		Optional[Any]     ,    **SCREAMING_SNAKE_CASE	:		Dict						)			->	Any:




											'''simple docstring'''

											raise OSError


					def 							SCREAMING_SNAKE_CASE_  (						self	:		int     ,    *SCREAMING_SNAKE_CASE	:		Optional[int]     ,    **SCREAMING_SNAKE_CASE	:		Dict						)			->	Optional[int]:




											'''simple docstring'''

											raise OSError


					def 							SCREAMING_SNAKE_CASE_  (						self	:		Optional[int]     ,    *SCREAMING_SNAKE_CASE	:		Tuple     ,    **SCREAMING_SNAKE_CASE	:		List[str]						)			->	int:




											'''simple docstring'''

											raise OSError






					def 							SCREAMING_SNAKE_CASE_  (						self	:		Any     ,    *SCREAMING_SNAKE_CASE	:		Union[str, Any]     ,    **SCREAMING_SNAKE_CASE	:		int						)			->	List[str]:




											'''simple docstring'''

											return False






class     UpperCamelCase(  contextlib._RedirectStream   ):  # type: ignore
					snake_case_		:				Any										=	'''stdin'''





@contextlib.contextmanager
def 	_lowerCAmelCase       (    _lowerCAmelCase )						->	List[str]:


						'''simple docstring'''






						if root == ".":
												yield
												return
						__snake_case				=		os.getcwd()
						os.chdir(_lowerCAmelCase )
						try:
												yield
						except BaseException as exc:
												raise exc
						finally:
												os.chdir(_lowerCAmelCase )





def 	_lowerCAmelCase       (    _lowerCAmelCase=None )						->	List[Any]:


						'''simple docstring'''






						if maximum_memory_bytes is not None:
												import resource

												resource.setrlimit(resource.RLIMIT_AS      ,	(maximum_memory_bytes, maximum_memory_bytes) )
												resource.setrlimit(resource.RLIMIT_DATA      ,	(maximum_memory_bytes, maximum_memory_bytes) )
												if not platform.uname().system == "Darwin":
																		resource.setrlimit(resource.RLIMIT_STACK      ,	(maximum_memory_bytes, maximum_memory_bytes) )

						faulthandler.disable()

						import builtins

						__snake_case				=		None
						__snake_case				=		None

						import os

						__snake_case				=		'1'

						__snake_case				=		None
						__snake_case				=		None
						__snake_case				=		None
						__snake_case				=		None
						__snake_case				=		None
						__snake_case				=		None
						__snake_case				=		None
						__snake_case				=		None
						__snake_case				=		None
						__snake_case				=		None
						__snake_case				=		None
						__snake_case				=		None
						__snake_case				=		None
						__snake_case				=		None
						__snake_case				=		None
						__snake_case				=		None
						__snake_case				=		None
						__snake_case				=		None
						__snake_case				=		None
						__snake_case				=		None
						__snake_case				=		None
						__snake_case				=		None
						__snake_case				=		None
						__snake_case				=		None
						__snake_case				=		None
						__snake_case				=		None
						__snake_case				=		None

						import shutil

						__snake_case				=		None
						__snake_case				=		None
						__snake_case				=		None

						import subprocess

						__snake_case				=		None  # type: ignore

						__snake_case				=		None

						import sys

						__snake_case				=		None
						__snake_case				=		None
						__snake_case				=		None
						__snake_case				=		None
						__snake_case				=		None



from __future__ import annotations

import csv

import requests
from bsa import BeautifulSoup





def 	_lowerCAmelCase       (    _lowerCAmelCase = "" )						->	dict[str, float]:


						'''simple docstring'''






						__snake_case				=		url or "https://www.imdb.com/chart/top/?ref_=nv_mv_250"
						__snake_case				=		BeautifulSoup(requests.get(_lowerCAmelCase ).text      ,	"html.parser" )
						__snake_case				=		soup.find_all("td"      ,	attrs="titleColumn" )
						__snake_case				=		soup.find_all("td"      ,	class_="ratingColumn imdbRating" )
						return {
						    title.a.text: float(rating.strong.text )
						    for title, rating in zip(_lowerCAmelCase      ,	_lowerCAmelCase )
						}





def 	_lowerCAmelCase       (    _lowerCAmelCase = "IMDb_Top_250_Movies.csv" )						->	None:


						'''simple docstring'''






						__snake_case				=		get_imdb_top_aaa_movies()
						with open(_lowerCAmelCase      ,	"w"      ,	newline="" ) as out_file:
												__snake_case				=		csv.writer(_lowerCAmelCase )
												writer.writerow(["Movie title", "IMDb rating"] )
												for title, rating in movies.items():
																		writer.writerow([title, rating] )


if __name__ == "__main__":
	write_movies()





