Skip to content

Commit

Permalink
Update RickRoll.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Sherlockcxk authored Jul 29, 2021
1 parent 6f983db commit 9a9d1d9
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src-py/RickRoll.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
from sys import argv, stdout
from time import time
from os.path import exists
from traceback2 import format_exc

from interpreter import run_in_interpreter
from pyrickroll import run_in_py, Token
from crickroll import run_in_cpp
import AudioGenerator
start = time()

from sys import argv, stdout
# from os.path import exists
# from traceback2 import format_exc

# from interpreter import run_in_interpreter
# from pyrickroll import run_in_py, Token
# from crickroll import run_in_cpp
# import AudioGenerator

# Help message
rick_help = """
Translate RickRoll to Python: RickRoll -py [File_Name]
Translate RickRoll to C++: RickRoll -cpp [File_Name]
Generate an audio: RickRoll -py [File_Name] -audio [Audio_Name]
Programming by writing code: rickroll -py [File_Name]
Generate an audio: rickroll -py [File_Name] -audio [Audio_Name]
Other Options:
--time: Show execution time ofyour code
--time: Show execution time of your code
--help/--h: Help
"""

# Set and start a timer
start = time()

audio_engine = None

def play_audio(src_file_name):
import AudioGenerator
from pyrickroll import Token

with open(src_file_name, mode='r', encoding='utf-8') as src:
content = src.readlines()
content[-1] += '\n'
Expand Down Expand Up @@ -67,10 +67,9 @@ def main():
is_intpr = True
# Generate audio. --audio [Output audio file name]
if current_arg == '--audio':
global audio_engine
is_audio = True
# Help message
if current_arg == '--help' or current_arg == '-h':
if current_arg == '--help':
is_help = True

# Show execution time
Expand All @@ -79,21 +78,26 @@ def main():

# Run the RickRoll program
if src_file_name:
from os.path import exists
if exists(src_file_name):
# Convert .rickroll to C++
if is_cpp:
from crickroll import run_in_cpp
run_in_cpp(src_file_name)

# Convert .rickroll to Python
elif is_py:
try:
from pyrickroll import run_in_py
exec(run_in_py(src_file_name), globals(), globals())
except:
from traceback2 import format_exc
error_msg = format_exc().split('File "<string>",')[-1]
stdout.write(f'Exception in{error_msg}')

# Execute .rickroll using the interpreter
elif is_intpr:
from interpreter import run_in_interpreter
run_in_interpreter(src_file_name)

else: exit(f"File [{src_file_name}] doesn't exist...")
Expand Down

0 comments on commit 9a9d1d9

Please sign in to comment.