mirror of
https://github.com/simon987/hexlib.git
synced 2025-04-10 14:06:43 +00:00
Initial commit
This commit is contained in:
commit
476491ca7b
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*.iml
|
||||
.idea/
|
0
__init__.py
Normal file
0
__init__.py
Normal file
8
imhash.py
Normal file
8
imhash.py
Normal file
@ -0,0 +1,8 @@
|
||||
import base64
|
||||
|
||||
|
||||
def b64hash(imhash, bcount):
|
||||
"""ImageHash hash to base64 string"""
|
||||
return base64.b64encode(
|
||||
sum(1 << i for i, b in enumerate(imhash.hash.flatten()) if b).to_bytes(bcount, "big")
|
||||
).decode("ascii")
|
24
misc.py
Normal file
24
misc.py
Normal file
@ -0,0 +1,24 @@
|
||||
import time
|
||||
|
||||
last_time_called = dict()
|
||||
|
||||
|
||||
def rate_limit(per_second):
|
||||
min_interval = 1.0 / float(per_second)
|
||||
|
||||
def decorate(func):
|
||||
last_time_called[func] = 0
|
||||
|
||||
def wrapper(*args, **kwargs):
|
||||
elapsed = time.perf_counter() - last_time_called[func]
|
||||
wait_time = min_interval - elapsed
|
||||
if wait_time > 0:
|
||||
time.sleep(wait_time)
|
||||
|
||||
last_time_called[func] = time.perf_counter()
|
||||
return func(*args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
return decorate
|
||||
|
30
monitoring.py
Normal file
30
monitoring.py
Normal file
@ -0,0 +1,30 @@
|
||||
import logging
|
||||
import traceback
|
||||
|
||||
from influxdb import InfluxDBClient
|
||||
|
||||
|
||||
class Monitoring:
|
||||
def __init__(self, db, host="localhost", logger=logging.getLogger("default")):
|
||||
self._db = db
|
||||
self._client = InfluxDBClient(host, 8086, "", "", db)
|
||||
self._logger = logger
|
||||
|
||||
self._init()
|
||||
|
||||
def db_exists(self, name):
|
||||
for db in self._client.get_list_database():
|
||||
if db["name"] == name:
|
||||
return True
|
||||
return False
|
||||
|
||||
def _init(self):
|
||||
if not self.db_exists(self._db):
|
||||
self._client.create_database(self._db)
|
||||
|
||||
def log(self, event):
|
||||
try:
|
||||
self._client.write_points(event)
|
||||
except Exception as e:
|
||||
self._logger.debug(traceback.format_exc())
|
||||
self._logger.error(str(e))
|
4
regex.py
Normal file
4
regex.py
Normal file
@ -0,0 +1,4 @@
|
||||
import re
|
||||
|
||||
LINK_RE = re.compile(r"(https?://[\w\-_.]+\.[a-z]{2,4}([^\s<'\"]*|$))")
|
||||
HTML_HREF_RE = re.compile(r"href=\"([^\"]+)\"")
|
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
ImageHash
|
||||
influxdb
|
Loading…
x
Reference in New Issue
Block a user