generated from Hazel/python-project
cache db
This commit is contained in:
parent
8196da840e
commit
56e77aa861
@ -3,10 +3,30 @@ from hashlib import sha1
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import requests
|
import requests
|
||||||
import pickle
|
import pickle
|
||||||
|
import sqlite3
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from . import CACHE_DIRECTORY
|
from . import CACHE_DIRECTORY
|
||||||
|
|
||||||
|
|
||||||
|
# SQLite database file path
|
||||||
|
DB_FILE = Path(CACHE_DIRECTORY, "cache_metadata.db")
|
||||||
|
|
||||||
|
# Initialize the database
|
||||||
|
def _init_db():
|
||||||
|
with sqlite3.connect(DB_FILE) as conn:
|
||||||
|
conn.execute("""
|
||||||
|
CREATE TABLE IF NOT EXISTS url_cache (
|
||||||
|
url_hash TEXT PRIMARY KEY,
|
||||||
|
last_updated TIMESTAMP
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
# Initialize the database when module is imported
|
||||||
|
_init_db()
|
||||||
|
|
||||||
|
|
||||||
def get_url_hash(url: str) -> str:
|
def get_url_hash(url: str) -> str:
|
||||||
return sha1(encode(url.strip(), "utf-8")).hexdigest()
|
return sha1(encode(url.strip(), "utf-8")).hexdigest()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user