130 lines
3.5 KiB
Python
130 lines
3.5 KiB
Python
import flask
|
|
import requests
|
|
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/W.X.Y.Z Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
|
|
}
|
|
html = """
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<title>13ft Ladder</title>
|
|
<link href="https://fonts.googleapis.com/css2?family=Open+Sans&display=swap" rel="stylesheet" async>
|
|
<style>
|
|
body {
|
|
font-family: 'Open Sans', sans-serif;
|
|
background-color: #FFF;
|
|
margin: 0;
|
|
padding: 0;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
height: 100vh;
|
|
}
|
|
|
|
h1 {
|
|
font-size: 1.5rem;
|
|
margin-bottom: 20px;
|
|
text-align: center;
|
|
color: #333;
|
|
}
|
|
label {
|
|
display: block;
|
|
margin-bottom: 10px;
|
|
font-weight: bold;
|
|
}
|
|
input[type=text] {
|
|
padding: 10px;
|
|
margin-bottom: 10px;
|
|
border: 1px solid #ccc;
|
|
border-radius: 5px;
|
|
width: 100%;
|
|
font-size: 1rem;
|
|
box-sizing: border-box;
|
|
}
|
|
input[type="submit"] {
|
|
padding: 10px;
|
|
background-color: #6a0dad;
|
|
color: #fff;
|
|
border: none;
|
|
border-radius: 5px;
|
|
width: 100%;
|
|
text-transform: uppercase;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
transition: background-color 0.3s ease;
|
|
}
|
|
input[type="submit"]:hover {
|
|
background-color: #4e0875;
|
|
}
|
|
|
|
/* Responsive adjustments */
|
|
@media only screen and (max-width: 600px) {
|
|
form {
|
|
padding: 10px;
|
|
}
|
|
h1 {
|
|
font-size: 1.2rem;
|
|
}
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<form action="/article" method="post">
|
|
<h1>Enter Website Link</h1>
|
|
<label for="link">Link of the website you want to remove paywall for:</label>
|
|
<input type="text" id="link" name="link" required>
|
|
<input type="submit" value="Submit">
|
|
</form>
|
|
</body>
|
|
</html>
|
|
"""
|
|
|
|
def bypass_paywall(url):
|
|
"""
|
|
Bypass paywall for a given url
|
|
"""
|
|
response = requests.get(url, headers=googlebot_headers)
|
|
response.encoding = response.apparent_encoding
|
|
return response.text
|
|
|
|
|
|
@app.route("/")
|
|
def main_page():
|
|
return 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 e:
|
|
raise e
|
|
|
|
@app.route("/", defaults={"path": ""})
|
|
@app.route('/<path:path>', 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(host='0.0.0.0', port=5000, debug=False)
|