add message sending with stomp protocol
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 3s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 3s
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
"""
|
||||
read file with URLs and store in DB
|
||||
"""
|
||||
|
||||
import json
|
||||
import logging.config
|
||||
from pathlib import Path
|
||||
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
|
||||
import yaml
|
||||
import stomp
|
||||
from platformdirs import PlatformDirs
|
||||
|
||||
parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter)
|
||||
parser.add_argument("-u", "--url", help="link")
|
||||
parser.add_argument("--config", "-c", default="kontor-docker")
|
||||
parser.add_argument("--verbose", "-v", action="count", default=0)
|
||||
parser.add_argument("--server", "-s", default="127.0.0.1")
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
def get_logger(level: int, config: str):
|
||||
"""
|
||||
create Logger with configuration from config file
|
||||
"""
|
||||
dirs = PlatformDirs(config)
|
||||
logging_config = Path(dirs.user_config_dir, "logging-config.yaml")
|
||||
with open(logging_config, "rt", encoding="UTF-8") as f:
|
||||
config_dict = yaml.safe_load(f.read())
|
||||
logging.config.dictConfig(config_dict)
|
||||
log = logging.getLogger("development")
|
||||
if level is not None:
|
||||
match level:
|
||||
case 0:
|
||||
log.setLevel(logging.INFO)
|
||||
case 1:
|
||||
log.setLevel(logging.DEBUG)
|
||||
case _:
|
||||
log.setLevel(logging.CRITICAL)
|
||||
return log
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
logger = get_logger(args.verbose, args.config)
|
||||
logger.info("kontor.add_link_stomp started")
|
||||
link: str = args.url
|
||||
data = {"url": link}
|
||||
server_url = [(args.server,61613)]
|
||||
conn = stomp.Connection(host_and_ports=server_url)
|
||||
conn.connect('artemis', 'artemis', wait=True, headers={'client-id': 'wsl'})
|
||||
conn.send(body=json.dumps(data), destination="update_title")
|
||||
#Container(AddLinkMessage(server=server_url, message=data, log=logger)).run()
|
||||
logger.info("kontor.add_link finished")
|
||||
@@ -25,5 +25,5 @@ dependencies = [
|
||||
"simple-term-menu>=1.6.6",
|
||||
"sqlalchemy>=2.0.40",
|
||||
"sqlmodel>=0.0.24",
|
||||
"stomp.py",
|
||||
"stomp-py",
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user