-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
90 lines (84 loc) · 2.32 KB
/
app.py
File metadata and controls
90 lines (84 loc) · 2.32 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from flask import Flask, request, render_template_string
app = Flask(__name__)
# HTML template with CSS for styling
HTML_TEMPLATE = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>URL Encoder/Decoder</title>
<style>
body {
font-family: Arial, sans-serif;
background: linear-gradient(to right, #74ebd5, #acb6e5);
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
}
.container {
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
form {
display: flex;
flex-direction: column;
}
input[type="text"], button {
margin-bottom: 10px;
padding: 10px;
border-radius: 4px;
border: 1px solid #ddd;
}
button {
background-color: #4CAF50;
color: white;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<div class="container">
<h2>URL Encoder/Decoder</h2>
<form action="" method="post">
<input type="text" name="url" placeholder="Enter URL here..." required>
<button type="submit" name="action" value="encode">Encode</button>
<button type="submit" name="action" value="decode">Decode</button>
</form>
{% if result %}
<div class="result">{{ result }}
<button onclick="copyToClipboard('{{ result }}')">Copy to clipboard</button>
</div>
{% endif %}
</div>
<script>
function copyToClipboard(text) {
navigator.clipboard.writeText(text).then(function() {
log("Copied to clipboard");
}, function(err) {
log('Error in copying text: ', err);
});
}
</script>
</body>
</html>
"""
@app.route('/', methods=['GET', 'POST'])
def home():
result = None
if request.method == 'POST':
url = request.form['url']
action = request.form.get('action')
if action == 'encode':
result = url.replace('.', '[.]')
elif action == 'decode':
result = url.replace('[.]', '.')
return render_template_string(HTML_TEMPLATE, result=result)
if __name__ == '__main__':
app.run(debug=True)