- commit
- fcc85232beceacf9b225ab752e25e215f1df0122
- parent
- bea05206a241c2f7ab695698eeaa1950ad564bf2
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2023-07-01 17:48
use @functools.lru_cache
Diffstat
| M | plutopluto/__init__.py | 14 | +++----------- |
1 files changed, 3 insertions, 11 deletions
diff --git a/plutopluto/__init__.py b/plutopluto/__init__.py
@@ -1,6 +1,7 @@ 1 1 #!/usr/bin/env python 2 2 3 3 import argparse -1 4 import functools 4 5 import os 5 6 import sys 6 7 from time import mktime @@ -12,12 +13,10 @@ from flask import Flask 12 13 from flask import request 13 14 from flask import jsonify 14 15 from flask import abort15 -1 from werkzeug.contrib.cache import SimpleCache16 16 17 17 __version__ = '1.2.0' 18 18 19 19 app = Flask(__name__)20 -1 cache = SimpleCache()21 20 22 21 23 22 def strip_atts(s): @@ -36,6 +35,7 @@ def strip_atts(s): 36 35 return str(tree) 37 36 38 37 -1 38 @functools.lru_cache 39 39 def parse(url): 40 40 """Get feed and convert to JSON.""" 41 41 @@ -71,21 +71,13 @@ def parse(url): 71 71 } 72 72 73 7374 -1 def cachedParse(url, timeout=5 * 60):75 -1 data = cache.get(url)76 -1 if data is None:77 -1 data = parse(url)78 -1 cache.set(url, data, timeout=timeout)79 -1 return data80 -181 -182 74 @app.route('/parse', methods=['GET']) 83 75 def _parse(): 84 76 if 'url' in request.values: 85 77 url = request.values['url'] 86 78 87 79 try:88 -1 data = cachedParse(url)-1 80 data = parse(url) 89 81 except Exception as err: 90 82 app.logger.warning('%s: %s' % (url, err)) 91 83 abort(500)