1
0
mirror of https://github.com/alvierahman90/mobile-chemguide.git synced 2024-10-22 12:31:52 +00:00

initial commit

This commit is contained in:
Akbar Rahman 2021-05-02 12:26:15 +01:00
commit d99e8589fd
4 changed files with 69 additions and 0 deletions

10
Dockerfile Normal file
View File

@ -0,0 +1,10 @@
FROM python:3
WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY src/* ./
CMD [ "gunicorn", "-b 0.0.0.0:80", "app:app" ]

12
requirements.txt Normal file
View File

@ -0,0 +1,12 @@
certifi==2020.12.5
chardet==4.0.0
click==7.1.2
Flask==1.1.2
gunicorn==20.1.0
idna==2.10
itsdangerous==1.1.0
Jinja2==2.11.3
MarkupSafe==1.1.1
requests==2.25.1
urllib3==1.26.4
Werkzeug==1.0.1

Binary file not shown.

47
src/app.py Normal file
View File

@ -0,0 +1,47 @@
from flask import Flask
import requests
import re
app = Flask(__name__)
CHEMGUIDE_BASE="https://chemguide.co.uk/"
@app.route('/')
@app.route('/<path:path>')
def path(path='/'):
r = requests.get(CHEMGUIDE_BASE + '/' + path)
try:
return re.sub(
r'<table .* width="480"',
'<table style="max-width: 60em; margin: 0 auto; font-size: 16px;"',
re.sub(
r'</?font.*?>',
'',
re.sub(
r'<head>',
"""<head>
<style>
body center table tr td { font-size: 1.2em; }
body { margin: 2em; line-height: 1.4; }
img {
width: 60% !important;
height: auto !important;
max-height: 15em; display:
block; margin: 0 auto;
object-fit: contain;
}
img[src="padding.GIF"] { display: none }
img[src="padding.gif"] { display: none }
</style>""",
re.sub(
"""(?<=<font color="#[a-f0-9]{6}" size="[0-9]" face="Helvetica, Arial"><b>)[a-zA-z\s]*""",
"an unnoficial chemguide mirror",
str(r.content, encoding='utf-8')
)
)
)
)
except UnicodeDecodeError:
return r.content
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)