This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# External network (WAN) connection watchdog | |
# | |
# Tested and works in RouterOS 6.49.17 (stable) | |
# | |
# If device gets 10 unsuccessfull pings to all ips in $pingAdresses array, it will try to restart the | |
# LTE modem and its interface - multiple times (RebootThreshold - ResetThreshold), until the | |
# RebootThreshold is met. Then the device reboots completely. | |
# | |
# How to kill the routeros script/job? | |
# With terminal: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import random | |
from pathlib import Path | |
from playwright.async_api import BrowserContext, async_playwright | |
CWD = Path().resolve() | |
# Example path | |
user_data_dir = Path.joinpath(CWD, 'playwright/data_dir/chromium') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from playwright.sync_api import sync_playwright | |
def save_mhtml(path: str, text: str): | |
with open(path, mode='w', encoding='UTF-8', newline='\n') as file: | |
file.write(text) | |
def save_page(url: str, path: str): | |
with sync_playwright() as playwright: | |
browser = playwright.chromium.launch(headless=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
def _epoch_to_datetime(self, epoch:int, strf='%Y-%m-%d_%H-%M-%S') -> str: | |
'Return human readable datetime string from given epoch int.' | |
return datetime.fromtimestamp(epoch).strftime(strf) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
from pathlib import Path | |
from typing import List, Optional | |
def _exit(message: str, status=0): | |
'Gracefully exit with status code and message to stderr.' | |
if status != 0: | |
sys.stderr.write(message) | |
raise SystemExit(status) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def age_str_calc(date: str, strp_format: str, bounds=(1, 120)) -> tuple: | |
'''Calulate age from given date, if age fit the bounds (default is 1-120 years), | |
then return string: prefix (RU) + age (in years) + postfix (RU). Otherwise return empty string.''' | |
def age(birthdate: object) -> int: | |
'''Return age (int) by given datetime object''' | |
today = datetime.date.today() | |
age = today.year - birthdate.year - ( | |
(today.month, today.day) < (birthdate.month, birthdate.day) | |
) | |
return age |