This file contains hidden or 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 |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
| #!/bin/bash | |
| # Use exact same file naming as GUI exports | |
| BACKUP_NAME=`hostname -s`-`cat /etc/version | cut -d ' ' -f 1`-`date +%Y%m%d%H%M%S` | |
| # Change to your desired path | |
| BACKUP_LOCATION="/mnt/some_pool/some_dataset/some_folder" | |
| # Include secret seed as well | |
| tar cf "$BACKUP_LOCATION"/$BACKUP_NAME.tar -C /data/ freenas-v1.db pwenc_secret | |
| # Remove backups older than 365 days | |
| find "$BACKUP_LOCATION"/*.tar -mtime +365 -exec rm {} + |