Merge branch 'development'

This commit is contained in:
Thomas Williams 2024-07-08 14:34:54 +01:00
commit d2de0a883b
3 changed files with 43 additions and 5 deletions

34
main.py
View file

@ -35,7 +35,29 @@ def get_pip_command():
def install_dependencies():
pip_command = get_pip_command()
subprocess.check_call([pip_command, 'install', '-r', 'requirements.txt', '--user'])
with open('requirements.txt', 'r') as req_file:
requirements = req_file.read().splitlines()
try:
with open('installedrequirements.txt', 'r') as installed_file:
installed_requirements = installed_file.read().splitlines()
except FileNotFoundError:
installed_requirements = []
dependencies_to_install = [req for req in requirements if req not in installed_requirements]
if dependencies_to_install:
subprocess.check_call([pip_command, 'install'] + dependencies_to_install + ['--user'])
with open('installedrequirements.txt', 'a') as installed_file:
for dependency in dependencies_to_install:
installed_file.write(dependency + '\n')
def signal_handler(sig, frame):
print('SIGINT/SIGTERM aknowledged. Stopping script gracefully, please wait...')
@ -45,7 +67,14 @@ def loadUrl(url):
headers = { 'User-Agent': 'Monutil monitor' }
response = requests.get(url, timeout=config.urlTimeout, headers=headers)
@retry(stop_max_attempt_number=3)
def submitRequest(url):
response = requests.get(url, timeout=config.urlTimeout, headers=headers)
return response
response = submitRequest(url)
return response
def prepareUrl(src, baseUrl):
@ -233,6 +262,7 @@ if __name__ == "__main__":
import threading
import signal
import socket
from retrying import retry
from functools import partial
from concurrent.futures import ThreadPoolExecutor, as_completed
from bs4 import BeautifulSoup

View file

@ -28,6 +28,7 @@ import base64
import config
import log
import datetime
from retrying import retry
class rabbitMQClient:
@ -42,6 +43,13 @@ class rabbitMQClient:
def publish(self, message):
@retry(stop_max_attempt_number=3)
def publishMessage(conn):
ch = conn.channel()
ch.basic_publish(exchange='', routing_key=self.routingKey, body=message, properties=pika.BasicProperties(delivery_mode=pika.spec.PERSISTENT_DELIVERY_MODE))
message = base64.b64encode(message.encode('utf-8'))
context = ssl.create_default_context(
@ -55,10 +63,9 @@ class rabbitMQClient:
with pika.BlockingConnection(connParams) as conn:
ch = conn.channel()
ch.basic_publish(exchange='', routing_key=self.routingKey, body=message, properties=pika.BasicProperties(delivery_mode=pika.spec.PERSISTENT_DELIVERY_MODE))
publishMessage(conn)
@retry(stop_max_attempt_number=3)
def retrieve(self):
def callback(ch, method, properties, body):

View file

@ -2,3 +2,4 @@ psutil
requests
bs4
datetime
retrying