replace shelve with redis
This commit is contained in:
parent
4de584e59d
commit
dbff4005fc
12
app.py
12
app.py
@ -1,7 +1,7 @@
|
||||
import locale
|
||||
|
||||
import redis
|
||||
from flask import Flask, render_template, request, redirect
|
||||
|
||||
from flask_caching import Cache
|
||||
from forms.SearchForm import SearchForm
|
||||
from arztapi.APIHandler import APIHandler
|
||||
|
||||
@ -9,6 +9,14 @@ app = Flask(__name__)
|
||||
app.config.from_prefixed_env()
|
||||
app.secret_key = app.config["THERAPY_SECRET"]
|
||||
locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8')
|
||||
app.config["CACHE_TYPE"] = "redis"
|
||||
app.config["CACHE_REDIS_HOST"] = "localhost"
|
||||
app.config["CACHE_REDIS_PORT"] = 6379
|
||||
app.config["CACHE_REDIS_DB"] = 0
|
||||
|
||||
cache = Cache(app=app)
|
||||
cache.init_app(app)
|
||||
redis_client = redis.Redis(host='localhost', port=6379, db=0)
|
||||
|
||||
|
||||
@app.route('/')
|
||||
|
@ -1,10 +1,12 @@
|
||||
import json
|
||||
from typing import List
|
||||
|
||||
import requests
|
||||
from requests import JSONDecodeError
|
||||
import base64
|
||||
import shelve
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from app import redis_client
|
||||
from arztapi.ArztPraxisDatas import ArztPraxisDatas
|
||||
from arztapi.DoctorInformation import DoctorInformation, PhoneTime
|
||||
from arztapi.DoctorPhoneTime import DoctorPhoneTime
|
||||
@ -23,7 +25,6 @@ class APIHandler:
|
||||
self.phone_times = []
|
||||
self.general_information = []
|
||||
self.processed_doctor_phone_times = []
|
||||
self._cache = shelve.open("_therapydb.cache")
|
||||
|
||||
def get_lat_lon_location_list(self, location):
|
||||
"""
|
||||
@ -160,8 +161,9 @@ class APIHandler:
|
||||
return self.phone_times
|
||||
|
||||
def get_current_doctor_information_data_in_cache_with_time_check(self, amount_of_days):
|
||||
cached_data = self._cache.get(str(self.json_data))
|
||||
cached_data = redis_client.get(str(self.json_data))
|
||||
if cached_data:
|
||||
cached_data = json.loads(cached_data)
|
||||
cache_timestamp = cached_data["timestamp"]
|
||||
current_date = datetime.now()
|
||||
time_difference = current_date - cache_timestamp
|
||||
@ -170,7 +172,7 @@ class APIHandler:
|
||||
|
||||
def set_current_doctor_information_data_in_cache(self):
|
||||
current_date = datetime.now()
|
||||
self._cache[str(self.json_data)] = {"timestamp": current_date, "data": self.phone_times}
|
||||
redis_client.set(str(self.json_data), json.dumps({"timestamp": current_date, "data": self.phone_times}))
|
||||
|
||||
def filter_for_therapy_types(self, therapy_types):
|
||||
"""
|
||||
|
@ -14,8 +14,9 @@ MarkupSafe==2.1.5
|
||||
packaging==24.1
|
||||
pydantic==2.8.2
|
||||
pydantic_core==2.20.1
|
||||
redis==5.2.0
|
||||
requests==2.32.3
|
||||
typing_extensions==4.12.2
|
||||
urllib3==2.2.2
|
||||
Werkzeug==3.0.3
|
||||
WTForms==3.1.2
|
||||
WTForms==3.1.2
|
Loading…
Reference in New Issue
Block a user