File size: 1,903 Bytes
1efde42
 
 
fbc3d9d
1efde42
 
 
 
 
 
 
 
 
 
 
 
 
82c6778
1efde42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58450a9
1efde42
 
7f929b0
58450a9
1efde42
 
 
 
 
d7f5125
 
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import streamlit as st 

st.title("Code Converter")
st.divider()
input, output = st.columns(2)
out = ""

def python_to_javascript(python_code):
    js_code = python_code
    replacements = {
        "print": "console.log",
        "if": "if",
        "elif": "else if",
        "else": "else",
        "True": "true",
        "False": "false",
        "==": "===",
        ":": "{"
        "and": "&&",
        "or": "||",
        "not": "!",
        "in": "includes",
        "range": "Array.from(Array",
        "for": "for",
        "while": "while",
        "continue": "continue",
        "break": "break",
        "def": "function",
        "return": "return",
        "lambda": "() =>",
        "is": "===",
        "None": "null",
        "import": "import",
        "from": "from",
        "as": "as",
        "class": "class",
        "self": "this",
        "del": "delete",
        "try": "try",
        "except": "catch",
        "finally": "finally",
        "raise": "throw",
        "assert": "assert",
        "async": "async",
        "await": "await",
        "yield": "yield",
        "global": "global",
        "nonlocal": "nonlocal",
        "pass": "pass",
        "with": "with",
        "yield from": "yield from",
        "async for": "for await",
        "async with": "async with",
        "async def": "async function"
    }

    for key, value in replacements.items():
        if key in js_code:
            js_code = js_code.replace(key, value)

    return js_code

input_code_type = input.selectbox(
    'Convert from',
    ("Python", "Coming soon")
)
output_code_type = output.selectbox(
    'Convert to',
    ("JavaScript", "Comnig soon")
)
input_code = input.text_area("Enter yor code",  height=300)
submit = input.button("Convert")
if submit:
    out = python_to_javascript(input_code)
    output_code = output.code(out, language=output_code_type, line_numbers=True)