import subprocess
from time import sleep
class CameraMonitor:
def __init__(self):
self.IP12 = '192.168.0.100'
self.IP13 = '192.168.0.101'
self.RODOS12 = '192.168.1.100'
self.RODOS13 = '192.168.1.101'
self.fail_count = {'Купол 12': 0, 'Купол 13': 0}
self.reboot_count = {'Купол 12': 0, 'Купол 13': 0}
def ping_camera(self, ip):
cmd = f'ping {ip} -n 1 -w 100'
response = subprocess.call(cmd, stdout=subprocess.DEVNULL)
return response == 0
def cameras_checker(self):
r_dict = {'Купол 12': self.IP12, 'Купол 13': self.IP13}
while True:
for camera, ip in r_dict.items():
if self.ping_camera(ip):
print(f'Camera {camera} - OK')
self.fail_count[camera] = 0
else:
self.fail_count[camera] += 1
print(f'Camera {camera} - Died')
if self.fail_count[camera] >= 5:
self.cameras_reboot(camera)
sleep(5)
def cameras_reboot(self, camera):
if camera == 'Купол 12':
ip = self.RODOS12
else:
ip = self.RODOS13
self.reboot_count[camera] += 1
print(f'Rebooting {camera} at IP {ip}')
def info(self):
for camera, count in self.reboot_count.items():
print(f'Перезагрузок {camera}: {count}')
if __name__ == "__main__":
monitor = CameraMonitor()
monitor.cameras_checker()
function increaseSalary() {
return api.getEmployees()
.then(employeeData => {
const [minSalaryEmployee] = employeeData.reduce(([minEmployee, minSalary], employee) => {
const { salary } = employee;
return (salary < minSalary
? [employee, salary]
: [minEmployee, minSalary]
);
}, [null, Infinity]);
const { id, salary: oldSalary } = minSalaryEmployee;
const newSalary = oldSalary * 1.2;
return { id, salary: newSalary };
})
.then(({ id, salary }) => api.setEmployeeSalary(id, salary)
.then(updatedEmployee => {
return api.notifyEmployee(updatedEmployee.id, `Hello, ${updatedEmployee.name}! Congratulations, your new salary is ${salary}!`);
})
)
.catch(e => {
return api.notifyAdmin(e);
});
}
Я так понимаю, нужно сделать проверку...
<section id="our-media">
<div class="container">
<?php
$cats = get_terms(array('taxonomy' => 'headline', 'post_type' => 'our-media'));
foreach ($cats as $cat) {
$query = new WP_Query(array(
'post_type' => 'our-media',
'tax_query' => array(
array(
'taxonomy' => 'headline',
'field' => 'term_id',
'terms' => $cat->term_id,
),
),
'posts_per_page' => -1,
'order' => 'ASC',
));
if ($query->have_posts()) { ?>
<h3><?php echo $cat->name; ?></h3>
<ul>
<?php while ($query->have_posts()) {
$query->the_post(); ?>
<li>
<!-- код поста -->
</li>
<?php } ?>
</ul>
<?php }
wp_reset_postdata();
}
?>
</div>
</section>
<section id="units">
<div class="container">
<?php
$cats = get_terms(array('taxonomy' => 'headline', 'post_type' => 'units'));
foreach ($cats as $cat) {
$query = new WP_Query(array(
'post_type' => 'units',
'tax_query' => array(
array(
'taxonomy' => 'headline',
'field' => 'term_id',
'terms' => $cat->term_id,
),
),
'posts_per_page' => -1,
'order' => 'ASC',
));
if ($query->have_posts()) { ?>
<h3><?php echo $cat->name; ?></h3>
<p><?php echo $cat->description; ?></p>
<ul>
<?php while ($query->have_posts()) {
$query->the_post(); ?>
<li>
<!-- код поста -->
</li>
<?php } ?>
</ul>
<?php }
wp_reset_postdata();
}
?>
</div>
</section>
length = input().split()
data = [int(x) for x in length]
n = len(data)
max_area = 0
for i in range(n):
for j in range(i + 1, n):
pair_width = abs(i - j)
pair_height = min(data[i], data[j])
max_area = max(max_area, pair_height * pair_width)
print(max_area)
$file = 'deal_updates.txt';
$input = file_get_contents('php://input');
$data = json_decode($input, true);
if (isset($data['event']) && $data['event'] === 'ONCRMDEALUPDATE') {
$dealId = $data['data']['FIELDS']['ID'];
$newStatus = $data['data']['FIELDS']['STATUS_ID'];
$updateDate = date('Y-m-d H:i:s');
$log = "Deal ID: $dealId | New Status: $newStatus | Updated at: $updateDate\n";
file_put_contents($file, $log, FILE_APPEND);
}
http_response_code(200);
echo 'OK';
from pyrogram import Client
app = Client("my_account")
new_chat_id = "new_chat_id"
with app:
for message in app.iter_history("source_chat_id"):
app.send_message(new_chat_id, message.text)
from ftplib import FTP
import os
ftp = FTP("tipftp")
ftp.login(user="tuserftp", passwd="tpssword")
local_dir = '/Users/tuser/Documents/py/test/'
files = ftp.nlst('/Backups/tdir/')
xml_files = [file for file in files if file.endswith('.xml')]
for file in xml_files:
local_file = os.path.join(local_dir, os.path.basename(file))
with open(local_file, 'wb') as tempfile:
ftp.retrbinary(f'RETR {file}', tempfile.write)
ftp.quit()
$array = [];
$requiredKeys = ['id', 'name', 'photo'];
foreach ($babysitters as $babysitter) {
$babysitterData = new \stdClass;
foreach ($requiredKeys as => $key) {
$babysitterData->${'babysitter_' . $key} = $babysitter->$key;
}
$array[] = $babysitterData;
}
<div class="knopka">
<div class="kn">
<button onclick="showElement()">Показать больше</button>
</div>
<div class="kn1">
<button onclick="hideElement()">Скрыть</button>
</div>
<div class="container" id="imageContainer">
<div class="scr41">
<img src="/Untitled (5)/Group 10.png" alt="Image 1">
</div>
<div class="scr51">
<img src="/Untitled (5)/Group 11.png" alt="Image 2">
</div>
<div class="scr51">
<img src="/Untitled (5)/Group 12.png" alt="Image 3">
</div>
</div>
</div>
.knopka {
text-align: end;
}
.kn {
margin-top: -55px;
margin-right: 350px;
}
.kn button, .kn1 button {
color: #4E4E4E;
border-radius: 5px;
background-color: #F7F7F7;
font-size: 15px;
border: none;
width: 200px;
height: 40px;
}
.kn button:hover, .kn1 button:hover {
background-color: #ffa34857;
color: rgb(0, 0, 0);
transition: all 0.6s ease;
}
.container {
justify-content: center;
display: flex;
opacity: 0;
transition: opacity 1s ease-in-out;
pointer-events: none;
}
.container.show {
opacity: 1;
pointer-events: auto;
}
.scr41 img, .scr51 img {
margin-top: 70px;
width: 140px;
}
function showElement() {
const element = document.getElementById('imageContainer');
element.classList.add('show');
}
function hideElement() {
const element = document.getElementById('imageContainer');
element.classList.remove('show');
}
import requests
from bs4 import BeautifulSoup
url = 'https://goverla.ua/'
response = requests.get(url)
soup = BeautifulSoup(response.content, 'html.parser')
usd_row = soup.find('div', class_='row', text=lambda t: 'USD' in t)
if usd_row:
sale_value = usd_row.find_all('div', class_='value row__value')[1].find('h3').text.strip()
usd_sale_rate = float(sale_value)
<template>
<button @click="sendGoal">Отправить форму</button>
</template>
<script setup>
const sendGoal = () => {
if (window.ym) {
window.ym(56555551, 'reachGoal', 'form_sent')
}
}
</script>
[Unit]
Description=my_prog
After=network-online.target nss-user-lookup.target
[Service]
User=pi
Group=pi
WorkingDirectory=/home/pi/www
ExecStart=/home/pi/www/env/bin/python3 /home/pi/www/run.py
Environment="PATH=/home/pi/www/env/bin:/usr/bin:/bin"
RestartSec=10
Restart=always
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target