Add PyLint

This commit is contained in:
f4lco
2019-01-27 20:45:51 +01:00
parent 6ec0c010e5
commit b86284054f
13 changed files with 688 additions and 28 deletions
+4 -3
View File
@@ -1,8 +1,8 @@
# -*- encoding: utf-8 -*-
import json
import requests
from collections import namedtuple
import requests
MenuParams = namedtuple('MenuParams', ('canteen_id', 'chash'))
@@ -10,8 +10,9 @@ URL = 'https://www.studentenwerk-potsdam.de' + \
'/essen/unsere-mensen-cafeterien/detailinfos/'
def _param_json(it):
return json.dumps(it, separators=(',', ':'))
def _param_json(to_serialize):
"""Obtain JSON string of an object without whitespace on delimiters."""
return json.dumps(to_serialize, separators=(',', ':'))
def download_menu(menu_params):
+3 -3
View File
@@ -4,14 +4,14 @@ import ConfigParser
import io
import os
from functools import partial
from canteen import Canteen
from stw_potsdam.canteen import Canteen
def _get_config(filename):
config = ConfigParser.SafeConfigParser()
path = os.path.join(os.path.dirname(__file__), filename)
with io.open(path, encoding='utf-8') as f:
config.readfp(f)
with io.open(path, encoding='utf-8') as config_file:
config.readfp(config_file)
return config
+1 -2
View File
@@ -33,8 +33,7 @@ def _prices(offer):
price = offer[api_role]
# When no price is set, this can be empty dict
if (isinstance(price, unicode) or isinstance(price, str)) \
and price.strip():
if isinstance(price, (unicode, str)) and price.strip():
# Convert unicode to str for PyOpenMensa -> misses type check
result[role] = str(price)
+11 -6
View File
@@ -4,17 +4,22 @@ import os
import urlparse
from flask import Flask, jsonify, make_response, url_for
from flask.logging import create_logger
from werkzeug.contrib.cache import SimpleCache
import feed
from config import read_canteen_config
from canteen_api import MenuParams, download_menu
from stw_potsdam import feed
from stw_potsdam.config import read_canteen_config
from stw_potsdam.canteen_api import MenuParams, download_menu
CACHE_TIMEOUT = 45 * 60
# pragma pylint: disable=invalid-name
app = Flask(__name__)
app.url_map.strict_slashes = False
log = create_logger(app)
if 'BASE_URL' in os.environ: # pragma: no cover
base_url = urlparse.urlparse(os.environ.get('BASE_URL'))
if base_url.scheme:
@@ -28,7 +33,7 @@ cache = SimpleCache()
def canteen_not_found(config, canteen_name):
app.logger.warn('Canteen %s not found', canteen_name)
log.warn('Canteen %s not found', canteen_name)
configured = ', '.join("'{}'".format(c) for c in config.keys())
message = "Canteen '{0}' not found, available: {1}".format(canteen_name,
configured)
@@ -39,12 +44,12 @@ def get_menu_cached(canteen):
params = MenuParams(canteen_id=canteen.id, chash=canteen.chash)
menu = cache.get(params)
if menu:
app.logger.info('Using cached menu for %s', canteen)
log.info('Using cached menu for %s', canteen)
return menu or get_menu(canteen, params)
def get_menu(canteen, params):
app.logger.info('Downloading menu for %s', canteen)
log.info('Downloading menu for %s', canteen)
menu = download_menu(params)
cache.set(params, menu, timeout=CACHE_TIMEOUT)
return menu