Merge branch 'development'
This commit is contained in:
commit
d2de0a883b
3 changed files with 43 additions and 5 deletions
34
main.py
34
main.py
|
@ -35,7 +35,29 @@ def get_pip_command():
|
||||||
def install_dependencies():
|
def install_dependencies():
|
||||||
|
|
||||||
pip_command = get_pip_command()
|
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):
|
def signal_handler(sig, frame):
|
||||||
print('SIGINT/SIGTERM aknowledged. Stopping script gracefully, please wait...')
|
print('SIGINT/SIGTERM aknowledged. Stopping script gracefully, please wait...')
|
||||||
|
@ -45,7 +67,14 @@ def loadUrl(url):
|
||||||
|
|
||||||
headers = { 'User-Agent': 'Monutil monitor' }
|
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
|
return response
|
||||||
|
|
||||||
def prepareUrl(src, baseUrl):
|
def prepareUrl(src, baseUrl):
|
||||||
|
@ -233,6 +262,7 @@ if __name__ == "__main__":
|
||||||
import threading
|
import threading
|
||||||
import signal
|
import signal
|
||||||
import socket
|
import socket
|
||||||
|
from retrying import retry
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
13
rabbitmq.py
13
rabbitmq.py
|
@ -28,6 +28,7 @@ import base64
|
||||||
import config
|
import config
|
||||||
import log
|
import log
|
||||||
import datetime
|
import datetime
|
||||||
|
from retrying import retry
|
||||||
|
|
||||||
class rabbitMQClient:
|
class rabbitMQClient:
|
||||||
|
|
||||||
|
@ -42,6 +43,13 @@ class rabbitMQClient:
|
||||||
|
|
||||||
def publish(self, message):
|
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'))
|
message = base64.b64encode(message.encode('utf-8'))
|
||||||
|
|
||||||
context = ssl.create_default_context(
|
context = ssl.create_default_context(
|
||||||
|
@ -55,10 +63,9 @@ class rabbitMQClient:
|
||||||
|
|
||||||
with pika.BlockingConnection(connParams) as conn:
|
with pika.BlockingConnection(connParams) as conn:
|
||||||
|
|
||||||
ch = conn.channel()
|
publishMessage(conn)
|
||||||
|
|
||||||
ch.basic_publish(exchange='', routing_key=self.routingKey, body=message, properties=pika.BasicProperties(delivery_mode=pika.spec.PERSISTENT_DELIVERY_MODE))
|
|
||||||
|
|
||||||
|
@retry(stop_max_attempt_number=3)
|
||||||
def retrieve(self):
|
def retrieve(self):
|
||||||
|
|
||||||
def callback(ch, method, properties, body):
|
def callback(ch, method, properties, body):
|
||||||
|
|
|
@ -2,3 +2,4 @@ psutil
|
||||||
requests
|
requests
|
||||||
bs4
|
bs4
|
||||||
datetime
|
datetime
|
||||||
|
retrying
|
||||||
|
|
Loading…
Reference in a new issue