Skip to content

Commit

Permalink
Merge 52f9156 into 655f164
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Mar 24, 2019
2 parents 655f164 + 52f9156 commit ee30a89
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 88 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Expand Up @@ -3,7 +3,7 @@ environment:
RANDOM_SEED: 0
matrix:
- PYTHON_MAJOR: 3
PYTHON_MINOR: 6
PYTHON_MINOR: 7

cache:
- .venv -> Makefile
Expand Down
5 changes: 3 additions & 2 deletions .travis.yml
@@ -1,6 +1,7 @@
dist: xenial

language: python
python:
- 3.6
python: 3.7

cache:
pip: true
Expand Down
17 changes: 8 additions & 9 deletions Pipfile
Expand Up @@ -6,23 +6,22 @@ name = "pypi"

[requires]

python_version = "3.6"
python_version = "3.7"

[packages]

# Flask
Flask = "~=1.0"
Flask-API = "~=1.0"
Flask-CORS = "~=3.0.3"
Flask-Caching = "*"
Flask-Cachecontrol = "==0.1.2"
Flask = "~=1.0.2"
Flask-API = "~=1.1"
Flask-CORS = "~=3.0.7"
Flask-Caching = "~=1.6.0"
Flask-Script = "~=2.0.6"

# Utilities
background = "*"
markdown = "<3"
markdown = "~=3.0.1"
minilog = "*"
pillow = "~=4.1.1"
pillow = "~=5.3.0"
profanityfilter = "~=2.0.5"
pymdown-extensions = "<6"
requests = "~=2.20.0"
Expand All @@ -33,7 +32,7 @@ yorm = "~=1.6.2"
blinker = "~=1.4"
bugsnag = "~=3.1.1"
eventlet = "==0.21.0"
gunicorn = "~=19.7.1"
gunicorn = "~=19.9.0"

[dev-packages]

Expand Down
98 changes: 44 additions & 54 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions memegen/extensions.py
Expand Up @@ -2,7 +2,7 @@

from flask_cors import CORS
from flask_caching import Cache
from flask_cachecontrol import FlaskCacheControl


cors = CORS()
cache = Cache(config={
Expand All @@ -12,4 +12,3 @@
'CACHE_DEFAULT_TIMEOUT': (60 if os.getenv('FLASK_ENV') == 'local'
else 99999),
})
cache_control = FlaskCacheControl()
1 change: 0 additions & 1 deletion memegen/factory.py
Expand Up @@ -64,7 +64,6 @@ def register_extensions(app):
extensions.cors.init_app(app, methods=['GET', 'OPTIONS'],
allow_headers='*')
extensions.cache.init_app(app)
extensions.cache_control.init_app(app)


def register_services(app):
Expand Down
9 changes: 5 additions & 4 deletions memegen/routes/custom.py
@@ -1,15 +1,16 @@
from flask import Blueprint, render_template, current_app
from flask_cachecontrol import cache_for
from flask import Blueprint, render_template, current_app, make_response


blueprint = Blueprint('custom-page', __name__)


@blueprint.route("/custom")
@cache_for(days=7)
def get():
return render_template(
html = render_template(
'custom.html',
fonts=sorted(current_app.font_service.all()),
config=current_app.config,
)
response = make_response(html)
response.headers['Cache-Control'] = f'max-age={60*60*24*7}'
return response
9 changes: 5 additions & 4 deletions memegen/routes/examples.py
@@ -1,5 +1,4 @@
from flask import Blueprint, render_template, current_app
from flask_cachecontrol import cache_for
from flask import Blueprint, render_template, current_app, make_response

from ._utils import samples

Expand All @@ -8,11 +7,13 @@


@blueprint.route("/examples")
@cache_for(days=7)
def get():
sample_images = list(samples())
return render_template(
html = render_template(
"examples.html",
sample_images=sample_images,
config=current_app.config,
)
response = make_response(html)
response.headers['Cache-Control'] = f'max-age={60*60*24*7}'
return response
10 changes: 6 additions & 4 deletions memegen/routes/index.py
@@ -1,8 +1,8 @@
import random
from pathlib import Path

from flask import Blueprint, Markup, render_template, current_app
from flask_cachecontrol import cache_for
from flask import (Blueprint, Markup,
render_template, current_app, make_response)
from markdown import markdown

from ._utils import samples
Expand All @@ -12,16 +12,18 @@


@blueprint.route("/")
@cache_for(hours=12)
def get():
template_images = list(samples(blank=True))
return render_template(
html = render_template(
"index.html",
template_images=template_images,
default_template=random.choice(template_images)['key'],
readme=_load_readme(),
config=current_app.config,
)
response = make_response(html)
response.headers['Cache-Control'] = f'max-age={60*60*12}'
return response


def _load_readme():
Expand Down
9 changes: 5 additions & 4 deletions memegen/routes/latest.py
@@ -1,5 +1,4 @@
from flask import Blueprint, render_template, current_app
from flask_cachecontrol import cache_for
from flask import Blueprint, render_template, current_app, make_response
from webargs import fields, flaskparser

from ._utils import route
Expand All @@ -10,14 +9,16 @@


@blueprint.route("/latest")
@cache_for(seconds=REFRESH_SECONDS - 1)
@flaskparser.use_kwargs({'nsfw': fields.Bool(missing=False)})
def get(nsfw):
filtered = 'false' if nsfw else 'true'
return render_template(
html = render_template(
'latest.html',
srcs=[route('image.get_latest', index=i, filtered=filtered)
for i in range(24)],
refresh=REFRESH_SECONDS,
config=current_app.config,
)
response = make_response(html)
response.headers['Cache-Control'] = f'max-age={REFRESH_SECONDS-1}'
return response
15 changes: 12 additions & 3 deletions scripts/generate_sample_images.py
@@ -1,6 +1,7 @@
#!env/bin/python
#!/usr/bin/env python

import log
import background

from memegen.settings import ProductionConfig
from memegen.factory import create_app
Expand All @@ -17,8 +18,16 @@ def main():
for template in app.template_service.all():
for text in [Text("_"), template.sample_text]:
for watermark in ["", "memegen.link"]:
app.image_service.create(template, text,
watermark=watermark)
create_image(app, template, text, watermark)


def create_image(app, template, text, watermark):

@background.task
def run():
app.image_service.create(template, text, watermark=watermark)

run()


if __name__ == '__main__':
Expand Down

0 comments on commit ee30a89

Please sign in to comment.