mirror of
https://github.com/simon987/hexlib.git
synced 2025-04-19 17:56:43 +00:00
add redis_publish
This commit is contained in:
parent
53a03baaa4
commit
021da84433
@ -1,11 +1,14 @@
|
|||||||
import redis
|
|
||||||
import os
|
import os
|
||||||
from fake_useragent import UserAgent
|
|
||||||
|
|
||||||
|
import redis
|
||||||
|
from fake_useragent import UserAgent
|
||||||
|
|
||||||
from hexlib.log import stdout_logger
|
from hexlib.log import stdout_logger
|
||||||
from hexlib.web import Web
|
from hexlib.web import Web
|
||||||
|
|
||||||
|
ARC_LISTS = os.environ.get("ARC_LISTS", "arc").split(",")
|
||||||
|
PUBLISH_CHANNEL = os.environ.get("PUBLISH_CHANNEL", None)
|
||||||
|
|
||||||
|
|
||||||
def get_redis():
|
def get_redis():
|
||||||
return redis.Redis(
|
return redis.Redis(
|
||||||
@ -14,6 +17,20 @@ def get_redis():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def redis_publish(rdb, item, item_source, item_type, item_category="x"):
|
||||||
|
|
||||||
|
item_source = item_source.replace(".", "-")
|
||||||
|
item_type = item_type.replace(".", "-")
|
||||||
|
item_category = item_category.replace(".", "-")
|
||||||
|
|
||||||
|
if PUBLISH_CHANNEL is not None:
|
||||||
|
routing_key = f"{PUBLISH_CHANNEL}.{item_source}.{item_type}.{item_category}"
|
||||||
|
rdb.publish(routing_key, item)
|
||||||
|
for arc_list in ARC_LISTS:
|
||||||
|
routing_key = f"{arc_list}.{item_source}.{item_type}.{item_category}"
|
||||||
|
rdb.publish(routing_key, item)
|
||||||
|
|
||||||
|
|
||||||
def get_web():
|
def get_web():
|
||||||
ua = UserAgent()
|
ua = UserAgent()
|
||||||
|
|
||||||
|
2
setup.py
2
setup.py
@ -2,7 +2,7 @@ from setuptools import setup
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="hexlib",
|
name="hexlib",
|
||||||
version="1.31",
|
version="1.32",
|
||||||
description="Misc utility methods",
|
description="Misc utility methods",
|
||||||
author="simon987",
|
author="simon987",
|
||||||
author_email="me@simon987.net",
|
author_email="me@simon987.net",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user