Skip to content

Commit 248a7b5

Browse files
committed
v1.9 cleaned code related to cloudflared tunnel
1 parent c5d766a commit 248a7b5

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

educative-viewer.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from collections import defaultdict
88
import random
99
import sys
10-
import subprocess
1110

1211

1312
ROOT_DIR = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
@@ -79,7 +78,7 @@ def load_files(topic_directory):
7978
for root, _, files in os.walk(os.path.join(course_directory, topic_directory)):
8079
for file in files:
8180
file_path = os.path.join(root, file)
82-
if os.path.isfile(file_path) and topic_directory not in file:
81+
if os.path.isfile(file_path) and topic_directory not in file and ".DS_Store" not in file_path:
8382
content = "\n"
8483
try:
8584
with open(file_path, 'r', encoding='utf-8') as f:
@@ -106,18 +105,18 @@ def topics(topics):
106105
pass
107106
if request.method == "POST" and request.form.get("back") and itr > 0:
108107
itr -= 1
109-
return render_template("topics.html", code_present=check_code_present(topic_folders[itr]), webpage=f"{topic_folders[itr]}/{topic_folders[itr]}.html", folder=f"{topic_folders[itr]}", url=url)
108+
return render_template("topics.html", code_present=check_code_present(topic_folders[itr]), webpage=f"{topic_folders[itr]}/{topic_folders[itr]}.html", folder=f"{topic_folders[itr]}")
110109
elif request.method == "POST" and request.form.get("forward") and itr < len(topic_folders)-1:
111110
itr += 1
112-
return render_template("topics.html", code_present=check_code_present(topic_folders[itr]), webpage=f"{topic_folders[itr]}/{topic_folders[itr]}.html", folder=f"{topic_folders[itr]}", url=url)
111+
return render_template("topics.html", code_present=check_code_present(topic_folders[itr]), webpage=f"{topic_folders[itr]}/{topic_folders[itr]}.html", folder=f"{topic_folders[itr]}")
113112
elif request.method == 'POST' and request.form.get("home"):
114113
itr = 0
115114
return redirect("/")
116115
elif request.method == 'POST' and request.form.get("code_filesystem"):
117116
path = f"file:///{course_directory}/{topic_folders[itr]}"
118117
path = path.replace("\\", "/")
119118
webbrowser.open(path)
120-
return render_template("topics.html", code_present=check_code_present(topic_folders[itr]), webpage=f"{topic_folders[itr]}/{topic_folders[itr]}.html", folder=f"{topic_folders[itr]}", url=url)
119+
return render_template("topics.html", code_present=check_code_present(topic_folders[itr]), webpage=f"{topic_folders[itr]}/{topic_folders[itr]}.html", folder=f"{topic_folders[itr]}")
121120

122121

123122
@app.route("/code/<codes>", methods=['GET', 'POST'])
@@ -152,29 +151,22 @@ def initialization():
152151
Project Link: https://github.com/anilabhadatta/educative-viewer
153152
Read the documentation for more information about this project.
154153
155-
-> For Cloudflared, enter the following command in a new terminal
156-
cloudflared tunnel -url {ip_address}:{port}
154+
-> For Cloudflare Tunneling, enter the following command in a new terminal
155+
For random cloudflare tunnel url : cloudflared tunnel -url {ip_address}:{port}
156+
For custom domain tunnel url :
157+
Step 1: Modify Ip:Port in config.yml
158+
Step 2: Enter "cloudflared tunnel run" in terminal
157159
-> Leave Blank and press Enter to exit
158160
''')
159161

160162

161163
if __name__ == "__main__":
162164
ip_address, port = get_ip()
163165
initialization()
164-
localhost_url = f"http://{ip_address}:{port}"
165-
url = localhost_url
166-
tunnel_url = input(
167-
"Enter cloudflared tunnel url or Press Enter to skip: ")
168-
if "trycloudflare.com" in tunnel_url:
169-
url = tunnel_url
170166
try:
171167
while True:
172168
initialization()
173169
course_directory = input("Enter Course Directory Path: ")
174-
if "trycloudflare.com" not in tunnel_url:
175-
tunnel_url = input(
176-
"Enter cloudflared tunnel url or Press Enter to skip: ")
177-
url = tunnel_url
178170
if course_directory == '':
179171
break
180172
elif os.path.isdir(course_directory):
@@ -185,7 +177,8 @@ def initialization():
185177
f'''
186178
187179
To Open Mobile/Desktop View,
188-
Tunnel Url: {tunnel_url} ,Localhost Url: {localhost_url}
180+
Tunnel Url: Use the url from cloudflare terminal window or the custom domain url
181+
Localhost Url: http://{ip_address}:{port}
189182
190183
''')
191184
app.run(host="0.0.0.0", threaded=True, port=port)

templates/topics.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ <h1 id="top" style="text-align: center;">Educative Viewer</h1>
2323
<div style="margin-top: 5px">
2424

2525
{%if code_present %}
26-
<a id="code" target="_blank" class="btn btn-primary btn-file" style="text-align: center;" href="{{url}}/code/{{folder}}">Open Code in Browser</a>
26+
<a id="code" target="_blank" class="btn btn-primary btn-file" style="text-align: center;" href="/code/{{folder}}">Open Code in Browser</a>
2727
<input target="_blank" name="code_filesystem" id="code_filesystem" class="btn btn-primary btn-file" type="submit" style="text-align: center;" value="Open Code in File System">
2828
{%endif %}
2929

@@ -54,7 +54,7 @@ <h4 style="text-align: center;">Current Topic: {{webpage}}</h4>
5454
<div style="margin-top: 5px">
5555

5656
{%if code_present %}
57-
<a id="code" target="_blank" class="btn btn-primary btn-file" style="text-align: center;" href="{{url}}/code/{{folder}}">Open Code in Browser</a>
57+
<a id="code" target="_blank" class="btn btn-primary btn-file" style="text-align: center;" href="/code/{{folder}}">Open Code in Browser</a>
5858
<input target="_blank" name="code_filesystem" id="code_filesystem" class="btn btn-primary btn-file" type="submit" style="text-align: center;" value="Open Code in File System">
5959
{%endif %}
6060

0 commit comments

Comments
 (0)