mirror of
https://github.com/simon987/hexlib.git
synced 2025-04-10 06:06:41 +00:00
add redis_publish
This commit is contained in:
parent
53a03baaa4
commit
021da84433
@ -1,11 +1,14 @@
|
||||
import redis
|
||||
import os
|
||||
from fake_useragent import UserAgent
|
||||
|
||||
import redis
|
||||
from fake_useragent import UserAgent
|
||||
|
||||
from hexlib.log import stdout_logger
|
||||
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():
|
||||
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():
|
||||
ua = UserAgent()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user