From 7ab30974b7a0a3bd16c8efc7788a9036aa09993e Mon Sep 17 00:00:00 2001 From: Wasi Master Date: Mon, 11 May 2026 23:59:32 +0600 Subject: [PATCH] Remove index and rely on only portable.py --- README.md | 13 ++-- app/index.html | 177 ------------------------------------------------ app/index.py | 85 ----------------------- app/portable.py | 7 +- 4 files changed, 12 insertions(+), 270 deletions(-) delete mode 100644 app/index.html delete mode 100644 app/index.py diff --git a/README.md b/README.md index 23bcea5..b7f6501 100644 --- a/README.md +++ b/README.md @@ -44,11 +44,17 @@ If that doesn't work retry but replace `python` with `py`, then try `python3`, t Then run `portable.py`, click [this link](https://realpython.com/run-python-scripts/) for a tutorial on how to run python scripts. +```sh +python portable.py +``` + +Or you can also run via gunicorn as follows: + ```sh python -m gunicorn 'portable:app' ``` -Then open the link shown in the terminal in the browser and you'll be able to use this +Then open the link shown in the terminal in the browser and you'll be able to use this script ### Installation using venv and running under specific bind address / port @@ -64,10 +70,7 @@ FLASK_APP=app/portable.py flask run --host=127.0.0.1 --port=9982 You can create a bookmarklet that performs the URL transformation by writing a small JavaScript snippet. Below is the JavaScript code for your bookmarklet: ```javascript -javascript: (function () { - window.location.href = - "https://13ft.wasimaster.me/" + encodeURIComponent(window.location.href); -})(); +javascript: (function () {window.location.href="https://13ft.wasimaster.me/" + encodeURIComponent(window.location.href);})(); ``` You can replace https://13ft.wasimaster.me with your own 13ft instance if desired. diff --git a/app/index.html b/app/index.html deleted file mode 100644 index 45b6b4d..0000000 --- a/app/index.html +++ /dev/null @@ -1,177 +0,0 @@ - - - - - - - - 13ft Ladder - - - - - -
- - -
-
-

Enter Website Link

- - - -
- - - - - \ No newline at end of file diff --git a/app/index.py b/app/index.py deleted file mode 100644 index 27e6b0e..0000000 --- a/app/index.py +++ /dev/null @@ -1,85 +0,0 @@ -from urllib.parse import urljoin, urlparse - -import flask -import requests -from bs4 import BeautifulSoup -from flask import request - -app = flask.Flask(__name__) -googlebot_headers = { - "User-Agent": "Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.6533.119 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" -} - - -def add_base_tag(html_content, original_url): - soup = BeautifulSoup(html_content, "html.parser") - parsed_url = urlparse(original_url) - base_url = f"{parsed_url.scheme}://{parsed_url.netloc}/" - - # Handle paths that are not root, e.g., "https://x.com/some/path/w.html" - if parsed_url.path and not parsed_url.path.endswith("/"): - base_url = urljoin(base_url, parsed_url.path.rsplit("/", 1)[0] + "/") - base_tag = soup.find("base") - - print(base_url) - if not base_tag: - new_base_tag = soup.new_tag("base", href=base_url) - if soup.head: - soup.head.insert(0, new_base_tag) - else: - head_tag = soup.new_tag("head") - head_tag.insert(0, new_base_tag) - soup.insert(0, head_tag) - - return str(soup) - - -def bypass_paywall(url): - """ - Bypass paywall for a given url - """ - if url.startswith("http"): - response = requests.get(url, headers=googlebot_headers) - response.encoding = response.apparent_encoding - return add_base_tag(response.text, response.url) - - try: - return bypass_paywall("https://" + url) - except requests.exceptions.RequestException as e: - return bypass_paywall("http://" + url) - - -@app.route("/") -def main_page(): - return flask.send_from_directory(".", "index.html") - - -@app.route("/article", methods=["POST"]) -def show_article(): - link = flask.request.form["link"] - try: - return bypass_paywall(link) - except requests.exceptions.RequestException as e: - return str(e), 400 - except Exception as exc: - raise exc - - -@app.route("/", defaults={"path": ""}) -@app.route("/", methods=["GET"]) -def get_article(path): - full_url = request.url - parts = full_url.split("/", 4) - if len(parts) >= 5: - actual_url = "https://" + parts[4].lstrip("/") - try: - return bypass_paywall(actual_url) - except requests.exceptions.RequestException as e: - return str(e), 400 - except e: - raise e - else: - return "Invalid URL", 400 - - -app.run(debug=False) diff --git a/app/portable.py b/app/portable.py index acfa0f5..0fada62 100644 --- a/app/portable.py +++ b/app/portable.py @@ -1,3 +1,4 @@ +import os from urllib.parse import urljoin, urlparse import flask @@ -239,7 +240,7 @@ def show_article(): return bypass_paywall(link) except requests.exceptions.RequestException as e: return str(e), 400 - except e: + except Exception as e: raise e @@ -254,11 +255,11 @@ def get_article(path): return bypass_paywall(actual_url) except requests.exceptions.RequestException as e: return str(e), 400 - except e: + except Exception as e: raise e else: return "Invalid URL", 400 if __name__ == "__main__": - app.run(host="0.0.0.0", port=5000, debug=False) + app.run(host="0.0.0.0", port=os.getenv("PORT") or 5000, debug=False)