-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.py
40 lines (32 loc) · 1002 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
Well done! You've found the source.
If you're at PyCon 2024, email ntollervey <at> anaconda.com
and (subject to availability) you can have some PyScript
swag. :-)
Now go build cool stuff with PyScript.
"""
import asyncio
import random
from pyscript import document
# It's the same API as JS when using the document object!
python_terminal = document.getElementById("python-terminal")
async def type_it_in(code):
"""
Advanced AI to type code into the terminal. ;-)
"""
lines = code.split("\n")
for line in lines:
await asyncio.sleep(1)
for char in line:
wait = random.choice(
[0.05, 0.07, 0.1, 0.15, 0.2, 0.3]
)
await asyncio.sleep(wait)
python_terminal.terminal.write(char)
python_terminal.terminal.write("\x1b[2K\r>>> ")
python_terminal.process(line.strip())
# Web scale use of advanced AI.
await type_it_in(
'print("Hello, from PyScript!")\r\n'
'# Your turn...'
)