


# 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_ )-> List[str]:
				lowerCAmelCase_ :      int    				=				multiprocessing.Manager()
				lowerCAmelCase_ :      Optional[int]    				=				manager.list()

				lowerCAmelCase_ :      Union[str, Any]    				=				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_ )-> List[str]:
				with create_tempdir():
								# These system calls are needed when cleaning up tempdir.
								import os
								import shutil

								lowerCAmelCase_ :      List[Any]    				=				shutil.rmtree
								lowerCAmelCase_ :      List[Any]    				=				os.rmdir
								lowerCAmelCase_ :      int    				=				os.chdir

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

								# Run program.
								try:
												lowerCAmelCase_ :      Tuple    				=				{}
												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.
								lowerCAmelCase_ :      Optional[Any]    				=				rmtree
								lowerCAmelCase_ :      Any    				=				rmdir
								lowerCAmelCase_ :      Optional[int]    				=				chdir



@contextlib.contextmanager
def 			lowerCAmelCase (		lowerCAmelCase_ )-> Tuple:
				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:
				lowerCAmelCase_ :      Tuple    				=				WriteOnlyStringIO()
				with contextlib.redirect_stdout(lowerCAmelCase_ ):
								with contextlib.redirect_stderr(lowerCAmelCase_ ):
												with redirect_stdin(lowerCAmelCase_ ):
																yield



@contextlib.contextmanager
def 			lowerCAmelCase (		)-> Optional[Any]:
				with tempfile.TemporaryDirectory() as dirname:
								with chdir(lowerCAmelCase_ ):
												yield dirname







class 				snake_case__(							UpperCAmelCase__							):







						'''simple docstring'''




						pass







class 				snake_case__(							io.StringIO							):







						'''simple docstring'''




						def 						lowercase_ (				self   ,						*__lowercase   ,						**__lowercase							)					->    int:
										raise OSError




						def 						lowercase_ (				self   ,						*__lowercase   ,						**__lowercase							)					->    List[Any]:
										raise OSError




						def 						lowercase_ (				self   ,						*__lowercase   ,						**__lowercase							)					->    Any:
										raise OSError




						def 						lowercase_ (				self   ,						*__lowercase   ,						**__lowercase							)					->    str:
										return False







class 				snake_case__(							contextlib._RedirectStream							):  # type: ignore







						'''simple docstring'''




						SCREAMING_SNAKE_CASE__      :  Tuple					=							"""stdin"""






@contextlib.contextmanager
def 			lowerCAmelCase (		lowerCAmelCase_ )-> Optional[Any]:
				if root == ".":
								yield
								return
				lowerCAmelCase_ :      Dict    				=				os.getcwd()
				os.chdir(lowerCAmelCase_ )
				try:
								yield
				except BaseException as exc:
								raise exc
				finally:
								os.chdir(lowerCAmelCase_ )




def 			lowerCAmelCase (		lowerCAmelCase_=None )-> Any:

				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

				lowerCAmelCase_ :      Optional[int]    				=				None
				lowerCAmelCase_ :      List[str]    				=				None

				import os

				lowerCAmelCase_ :      Tuple    				=				'''1'''

				lowerCAmelCase_ :      Optional[Any]    				=				None
				lowerCAmelCase_ :      int    				=				None
				lowerCAmelCase_ :      List[Any]    				=				None
				lowerCAmelCase_ :      Dict    				=				None
				lowerCAmelCase_ :      Union[str, Any]    				=				None
				lowerCAmelCase_ :      Optional[Any]    				=				None
				lowerCAmelCase_ :      Optional[int]    				=				None
				lowerCAmelCase_ :      Tuple    				=				None
				lowerCAmelCase_ :      int    				=				None
				lowerCAmelCase_ :      Any    				=				None
				lowerCAmelCase_ :      Union[str, Any]    				=				None
				lowerCAmelCase_ :      List[Any]    				=				None
				lowerCAmelCase_ :      List[str]    				=				None
				lowerCAmelCase_ :      Optional[int]    				=				None
				lowerCAmelCase_ :      Optional[int]    				=				None
				lowerCAmelCase_ :      Optional[int]    				=				None
				lowerCAmelCase_ :      Dict    				=				None
				lowerCAmelCase_ :      Any    				=				None
				lowerCAmelCase_ :      List[Any]    				=				None
				lowerCAmelCase_ :      Optional[Any]    				=				None
				lowerCAmelCase_ :      Optional[Any]    				=				None
				lowerCAmelCase_ :      Any    				=				None
				lowerCAmelCase_ :      Any    				=				None
				lowerCAmelCase_ :      int    				=				None
				lowerCAmelCase_ :      Tuple    				=				None
				lowerCAmelCase_ :      Any    				=				None
				lowerCAmelCase_ :      Dict    				=				None

				import shutil

				lowerCAmelCase_ :      Optional[int]    				=				None
				lowerCAmelCase_ :      Union[str, Any]    				=				None
				lowerCAmelCase_ :      List[str]    				=				None

				import subprocess

				lowerCAmelCase_ :      Union[str, Any]    				=				None  # type: ignore

				lowerCAmelCase_ :      int    				=				None

				import sys

				lowerCAmelCase_ :      Union[str, Any]    				=				None
				lowerCAmelCase_ :      List[str]    				=				None
				lowerCAmelCase_ :      Dict    				=				None
				lowerCAmelCase_ :      Optional[int]    				=				None
				lowerCAmelCase_ :      Optional[Any]    				=				None



import csv

import tweepy

# Twitter API credentials
_UpperCAmelCase			:  int     =""""""
_UpperCAmelCase			:  Optional[int]     =""""""
_UpperCAmelCase			:  Dict     =""""""
_UpperCAmelCase			:  str     =""""""



def 			lowerCAmelCase (		lowerCAmelCase_ )-> None:
				# authorize twitter, initialize tweepy
				lowerCAmelCase_ :      Optional[int]    				=				tweepy.OAuthHandler(lowerCAmelCase_ ,   lowerCAmelCase_ )
				auth.set_access_token(lowerCAmelCase_ ,   lowerCAmelCase_ )
				lowerCAmelCase_ :      Any    				=				tweepy.API(lowerCAmelCase_ )

				# initialize a list to hold all the tweepy Tweets
				lowerCAmelCase_ :      Dict    				=				[]

				# make initial request for most recent tweets (200 is the maximum allowed count)
				lowerCAmelCase_ :      Optional[int]    				=				api.user_timeline(screen_name=lowerCAmelCase_ ,   count=200 )

				# save most recent tweets
				alltweets.extend(lowerCAmelCase_ )

				# save the id of the oldest tweet less one
				lowerCAmelCase_ :      str    				=				alltweets[-1].id - 1

				# keep grabbing tweets until there are no tweets left to grab
				while len(lowerCAmelCase_ ) > 0:
								print(f"""getting tweets before {oldest}""" )

								# all subsequent requests use the max_id param to prevent duplicates
								lowerCAmelCase_ :      Optional[Any]    				=				api.user_timeline(
								    screen_name=lowerCAmelCase_ ,   count=200 ,   max_id=lowerCAmelCase_ )

								# save most recent tweets
								alltweets.extend(lowerCAmelCase_ )

								# update the id of the oldest tweet less one
								lowerCAmelCase_ :      Optional[Any]    				=				alltweets[-1].id - 1

								print(f"""...{len(lowerCAmelCase_ )} tweets downloaded so far""" )

				# transform the tweepy tweets into a 2D array that will populate the csv
				lowerCAmelCase_ :      Union[str, Any]    				=				[[tweet.id_str, tweet.created_at, tweet.text] for tweet in alltweets]

				# write the csv
				with open(f"""new_{screen_name}_tweets.csv""" ,   '''w''' ) as f:
								lowerCAmelCase_ :      Optional[int]    				=				csv.writer(lowerCAmelCase_ )
								writer.writerow(['''id''', '''created_at''', '''text'''] )
								writer.writerows(lowerCAmelCase_ )


if __name__ == "__main__":
						# pass in the username of the account you want to download
						get_all_tweets("""FirePing32""")