User Tools

Site Tools


язык_программирования_python

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
язык_программирования_python [2025/06/16 14:56]
val [FastAPI Uvicorn]
язык_программирования_python [2025/07/08 09:53] (current)
val
Line 167: Line 167:
  
   * [[https://​tproger.ru/​articles/​testiruem-na-python-unittest-i-pytest-instrukcija-dlja-nachinajushhih|Тестируем на Python: unittest и pytest. Инструкция для начинающих]]   * [[https://​tproger.ru/​articles/​testiruem-na-python-unittest-i-pytest-instrukcija-dlja-nachinajushhih|Тестируем на Python: unittest и pytest. Инструкция для начинающих]]
 +
 +  * [[https://​habr.com/​ru/​articles/​349860/​|Регулярные выражения в Python от простого к сложному. Подробности,​ примеры,​ картинки,​ упражнения]]
   * [[https://​regex101.com/​|Online Regular expression tester with syntax highlighting]]   * [[https://​regex101.com/​|Online Regular expression tester with syntax highlighting]]
  
Line 198: Line 200:
   * [[https://​www.geeksforgeeks.org/​python-find-dictionary-matching-value-in-list/​|Find dictionary matching value in list - Python]]   * [[https://​www.geeksforgeeks.org/​python-find-dictionary-matching-value-in-list/​|Find dictionary matching value in list - Python]]
   * [[https://​docs-python.ru/​tutorial/​vstroennye-funktsii-interpretatora-python/​funktsija-next/​|Функция next() в Python, следующий элемент итератора]]   * [[https://​docs-python.ru/​tutorial/​vstroennye-funktsii-interpretatora-python/​funktsija-next/​|Функция next() в Python, следующий элемент итератора]]
 +
 +==== Пример 1 ====
 <​code>​ <​code>​
 gate# apt install python3-xmltodict/​stable gate# apt install python3-xmltodict/​stable
Line 233: Line 237:
 </​code>​ </​code>​
  
 +==== Пример 2 ====
 +<​code>​
 +# cat /​usr/​local/​bin/​asterisk.chansip.discovery.py
 +</​code><​code>​
 +#​!/​usr/​bin/​env python3
 +
 +import subprocess, io, json
 +
 +result=[]
 +
 +proc = subprocess.Popen('/​usr/​sbin/​asterisk -x "sip show users" | tail -n +2 | cut -d" " -f1', stdout=subprocess.PIPE,​ shell=True)
 +for line in io.TextIOWrapper(proc.stdout,​ encoding="​utf-8"​):​
 +  #​print(line.rstrip())
 +  s={}
 +  s["​{#​CHANNAME}"​]="​SIP/"​+line.rstrip()
 +  result.insert(1,​s)
 +print(json.dumps(result))
 +</​code>​
 +
 +Вариант от DeepSeek
 +
 +<​code>​
 +# cat /​usr/​local/​bin/​asterisk.chansip.discovery.ds.py
 +</​code><​code>​
 +#​!/​usr/​bin/​env python3
 +
 +import subprocess
 +import json
 +
 +# Запускаем команду и сразу получаем вывод
 +output = subprocess.check_output(
 +    '/​usr/​sbin/​asterisk -x "sip show users" | tail -n +2 | cut -d" " -f1',
 +    shell=True,
 +    text=True
 +)
 +
 +# Формируем список словарей в одну строку
 +result = [{"​{#​CHANNAME}":​ f"​SIP/​{line.strip()}"​} for line in output.splitlines() if line.strip()]
 +
 +# Выводим результат в формате JSON
 +print(json.dumps(result))
 +</​code>​
 ===== Zabbix API приложение ===== ===== Zabbix API приложение =====
  
язык_программирования_python.1750074996.txt.gz · Last modified: 2025/06/16 14:56 by val