config: Munch = None env = jinja2.Environment(loader=jinja2.PackageLoader('m0rkcoin_explorer')) def load_config(): with open(config_file_path) as config_file: _config = yaml.load(config_file) globals()['config'] = Munch.fromDict(_config) try: with open(config_override_file_path) as config_override_file: _config_override = yaml.load(config_override_file) globals()['config'].update(_config_override) except Exception: pass load_config() cache_client = Walrus(host=config.redis.host, port=config.redis.port) cache = cache_client.cache() CACHE_HOUR = 60 * 60 CACHE_DAY = CACHE_HOUR * 24 CACHE_WEEK = CACHE_DAY * 7 CACHE_MONTH = CACHE_DAY * 30 M0RKCOIN_PREV_HEIGHT = 'm0rkcoin:prev_height' M0RKCOIN_EMISSION_KEY = 'm0rkcoin:emission'
import jwt from datetime import datetime, timedelta from flask import Flask, jsonify, request from flask_cors import CORS from werkzeug.security import generate_password_hash, check_password_hash from walrus import Walrus app = Flask(__name__) app.config['SECRET_KEY'] = 'Herocoders' CORS(app, resources={r"/data/*": {"origins": "*"}}) dbw = Walrus(host='127.0.0.1', port=6379, db=0) cache = dbw.cache() data = model.Data user = model.Users def check_character(character): """Danh sách các ký tự không mong muốn""" special = '''`~!#$%^&*()_=+-*/\[]{}|:;<>'"?''' for i in range(len(special)): if character is special[i]: return 0 return 1 def loc(char):
# contendedores o tipos de datos h = db.Hash('planetas') h.update(mercurio=3.303e+23, venus=4.869e+24) print(h) for key, value in h: print(f'Nombre: {key} -> {value}') del h['tierra'] print(h) print('venus' in h) # autocompletado ac = db.autocomplete() textos = [ 'Python es el mejor lenguaje del mundo', 'La comunidad de python usa mucho software libre', 'La mayoría de módulos de python son software libre', 'Redis está construido usando Ruby' ] for txt in textos: ac.store(txt) print(list(ac.search('python'))) print(list(ac.search('soft'))) # cache expirando a los 3 segundos cache = db.cache() cache.set('secreto', '9s7d86s92', 3) print(cache.get('secreto')) time.sleep(3) print(cache.get('secreto'))
from pydash import py_ from pyquery import PyQuery as pq from sanic import Sanic from sanic.response import json from sanic.exceptions import InvalidUsage from sanic_cors import cross_origin from walrus import Walrus from kekette import get_env config = get_env(prefix='ILEARN_DEV_') app = Sanic() wdb = Walrus() cache = wdb.cache() parse_number = lambda x: float(re.findall(r'[\d\.]+', x)[0]) @cache.cached(timeout=1200) def fetch_data(endpoint, **params): remote_url = f'http://{config.x_server}/{endpoint}' headers = {'Host': config.x_server} return requests.get(remote_url, params=params, headers=headers) def proxy_keywords(url): r = fetch_data('extract_keywords', jsdata=url)