mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-14 21:38:38 +00:00
more work needed
This commit is contained in:
@@ -1,51 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
import argparse
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import uuid
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
# CONFIGURATION
|
|
||||||
JSON_DB = '/var/log/share_scan.json'
|
|
||||||
SHARE_DIR = Path('/var/www/html/share')
|
|
||||||
BASE_URL = 'https://czernobog.pl/share'
|
|
||||||
|
|
||||||
# Ensure share directory exists
|
|
||||||
SHARE_DIR.mkdir(parents=True, exist_ok=True)
|
|
||||||
|
|
||||||
def load_db():
|
|
||||||
with open(JSON_DB) as f:
|
|
||||||
return json.load(f)['entries']
|
|
||||||
|
|
||||||
ENTRIES = load_db()
|
|
||||||
|
|
||||||
def relevancy(path, keywords):
|
|
||||||
score = 0
|
|
||||||
low = path.lower()
|
|
||||||
for kw in keywords:
|
|
||||||
if kw.lower() in low:
|
|
||||||
score += low.count(kw.lower())
|
|
||||||
return score
|
|
||||||
|
|
||||||
def find_matches(count, keywords):
|
|
||||||
scored = []
|
|
||||||
for e in ENTRIES:
|
|
||||||
score = relevancy(e['path'], keywords)
|
|
||||||
if score > 0:
|
|
||||||
scored.append((score, e['path']))
|
|
||||||
scored.sort(reverse=True, key=lambda x: x[0])
|
|
||||||
result = [p for _, p in scored]
|
|
||||||
return result[:count]
|
|
||||||
|
|
||||||
def publish(paths):
|
|
||||||
urls = []
|
|
||||||
for path in paths:
|
|
||||||
token = uuid.uuid4().hex
|
|
||||||
link = SHARE_DIR / token
|
|
||||||
try:
|
|
||||||
os.symlink(path, link)
|
|
||||||
except FileExistsError:
|
|
||||||
pass
|
|
||||||
urls.append(f"{BASE_URL}/{token}")
|
|
||||||
return urls
|
|
||||||
@@ -68,6 +68,7 @@ async def on_ready():
|
|||||||
|
|
||||||
await client.load_extension("other_commands")
|
await client.load_extension("other_commands")
|
||||||
await client.load_extension("voice_recognition_commands")
|
await client.load_extension("voice_recognition_commands")
|
||||||
|
await client.load_extension("file_search_commands")
|
||||||
logger.info("Sensors: online")
|
logger.info("Sensors: online")
|
||||||
|
|
||||||
logger.info(client.cogs)
|
logger.info(client.cogs)
|
||||||
|
|||||||
Reference in New Issue
Block a user