work on lan
This commit is contained in:
parent
a5983d32a4
commit
a52465a54f
13 changed files with 151 additions and 33 deletions
|
@ -1,5 +1,5 @@
|
|||
from . import insert
|
||||
from .insert import time_insert
|
||||
|
||||
from .blocklist import BlockList
|
||||
insert = insert.insert_block
|
||||
time_insert = time_insert
|
41
src/onionrblocks/blocklist.py
Normal file
41
src/onionrblocks/blocklist.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
from threading import Thread
|
||||
|
||||
from watchdog.observers import Observer
|
||||
from watchdog.events import FileSystemEventHandler
|
||||
|
||||
from utils.identifyhome import identify_home
|
||||
from coredb.dbfiles import block_meta_db
|
||||
from coredb.blockmetadb import get_block_list, get_blocks_by_type
|
||||
from onionrutils.epoch import get_epoch
|
||||
|
||||
class BlockList:
|
||||
def __init__(self, auto_refresh=True, block_type=''):
|
||||
self.block_type = block_type
|
||||
self.refresh_db()
|
||||
self.check_time = get_epoch()
|
||||
|
||||
class Refresher(FileSystemEventHandler):
|
||||
@staticmethod
|
||||
def on_modified(event):
|
||||
if event.src_path != block_meta_db:
|
||||
return
|
||||
self.refresh_db()
|
||||
if auto_refresh:
|
||||
def auto_refresher():
|
||||
observer = Observer()
|
||||
observer.schedule(Refresher(), identify_home(), recursive=False)
|
||||
observer.start()
|
||||
while observer.is_alive():
|
||||
# call import func with timeout
|
||||
observer.join(120)
|
||||
Thread(target=auto_refresher, daemon=True).start()
|
||||
|
||||
def get(self):
|
||||
return self.block_list
|
||||
|
||||
def refresh_db(self):
|
||||
self.check_time = get_epoch()
|
||||
if not self.block_type:
|
||||
self.block_list = get_block_list()
|
||||
else:
|
||||
self.block_list = get_blocks_by_type(self.block_type)
|
Loading…
Add table
Add a link
Reference in a new issue