Skip to content

Commit

Permalink
termux: add local web server for termux users
Browse files Browse the repository at this point in the history
Solves permission issues in android
  • Loading branch information
TheDarkW3b authored Jan 23, 2024
1 parent 15f346d commit 810ffc9
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion tool.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import os
import random
import sys
import time
import platform
import subprocess
import pandas as pd
from datetime import datetime
from colorama import init, Fore
import http.server
import socketserver
import threading

init()

Expand All @@ -22,6 +26,10 @@
author_name = "Ksauraj"
version = "v2.0.2"

class NoLogRequestHandler(http.server.SimpleHTTPRequestHandler):
def log_request(self, code='-', size='-'):
pass

def pre_setup():
os.system("cls" if os.name == "nt" else "clear")
print(Fore.GREEN + ascii_art)
Expand Down Expand Up @@ -442,6 +450,24 @@ def display_df_web(df, heading, subheading):
elif platform.system() == "Darwin":
subprocess.Popen(["open", filename],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
elif "TERMUX_VERSION" in os.environ:
os.chdir("output")
PORT = random.randint(50000, 65535)
handler = NoLogRequestHandler
server = socketserver.ThreadingTCPServer(("", PORT), handler)
server_thread = threading.Thread(target=server.serve_forever)
server_thread.daemon = True
server_thread.start()

print(f"{Fore.GREEN} Web server started at http://localhost:{PORT} {Fore.RESET}")

try:
fileName = filename.split("/")[1]
os.system(f"termux-open http://localhost:{PORT}/{fileName}")
input("Press Enter to stop the server...\n")
finally:
print("Stopping web server...")
return
else:
subprocess.Popen(["xdg-open", filename],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
Expand Down Expand Up @@ -493,7 +519,7 @@ def filter_by_choices(choices, column_name):
display_df_web(filtered_df, "JEE Counsellor", "-By Ksauraj")
print(
Fore.GREEN +
"Congratulations! File successfully opened in browser." +
"Congratulations! File successfully opened in browser. Please wait......" +
Fore.RESET)
time.sleep(3)
os.system("cls" if os.name == "nt" else "clear")
Expand Down

0 comments on commit 810ffc9

Please sign in to comment.