forked from wasi-master/13ft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.py
134 lines (119 loc) · 3.69 KB
/
index.py
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import flask
import requests
from flask import request
import gc
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 = """
<html lang="en">
<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 rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Open+Sans&display=swap" rel="stylesheet">
<style>
div.centered {
position: absolute;
left: 50%;
top: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
h1{
font-family: 'Product Sans', 'Open Sans', sans-serif;
text-rendering: optimizeLegibility;
margin: 0;
text-align: center;
}
input[type=text] {
padding: 10px;
margin-bottom: 10px;
border: 0;
box-shadow: 0 0 15px 4px rgba(0,0,0,0.3);
border-radius: 10px;
width:100%;
font-family: 'Product Sans', 'Open Sans', sans-serif;
font-size: inherit;
text-rendering: optimizeLegibility;
}
input[type="submit"] {
/* remove default behavior */
-webkit-appearance:none;
appearance:none;
/* usual styles */
padding:10px;
border:none;
background-color:#6a0dad;
color:#fff;
font-weight:600;
border-radius:5px;
width:100%;
text-transform: uppercase;
font-family: 'Product Sans', 'Open Sans', sans-serif;
font-size: 1rem;
text-rendering: optimizeLegibility;
}
input[type="submit"]:active {
scale: 1.02;
}
</style>
</head>
<body>
<div class="centered">
<form action="/article" method="post">
<h1>
<label for="link">Enter Website Link</label>
</h1>
<br>
<input
title="Link of the website you want to remove paywall for"
type="text"
name="link"
required
>
<input type="submit" value="submit">
</form>
</div>
</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
gc.collect()
app.run(host="0.0.0.0", debug=False, port=8083)