Python + bash
Если вам часто требуется запускать shell команды из Python-кода, какой способ вы используете?
Самый низкоуровневый это функция os.system(), либо os.popen(). Рекомендованный способ это subprocess.call(). Но это всё еще достаточно неудобно.
Советую обратить своё внимание на очень крутую библиотеку sh.
Что она умеет?
🔸 удобный синтаксис вызова команд как функций
# os
import os
os.system("tar cvf demo.tar ~/")
# subprocess
import subprocess
subprocess.call(['tar', 'cvf', 'demo.tar', '~/'])
# sh
import sh
sh.tar('cvf', 'demo.tar', "~/")
🔸 простое создание функции-алиаса для длинной команды
fn = sh.lsof.bake('-i', '-P', '-n')
output = sh.grep(fn(), 'LISTEN')
в этом примере также задействован пайпинг
🔸 удобный вызов команд от sudo
with sh.contrib.sudo:
print(ls("/root"))
Такой запрос спросит пароль. Чтобы это работало нужно соответствующим способом настроить юзера.
А вот вариант с вводом пароля через код.
password = "secret"
sudo = sh.sudo.bake("-S", _in=password+"\n")
print(sudo.ls("/root"))
Это не все фишки. Больше интересных примеров смотрите в документации.
Специально для Windows💀 юзеров
#libs#linux
#HOT/USDT analysis :
#HOT has broken and retested the support levels, which are now acting as resistance for the price. The price is currently in a downtrend on the higher timeframe and is expected to continue its momentum from the current level.
TF : 1H
Entry : $0.00135
Target : $0.00123
SL : $0.00142
#HOT/USDT analysis -
#HOT is currently consolidating sideways above a support line. The price has tapped into liquidity from previous lows below the support line. It appears poised to move upwards, with the previous high as the target level.
TF : 5min
Entry : $0.00145
Target : $0.00150
SL : $0.00143
#HOT/USDT analysis -
#HOT is currently on a downtrend, trading below the 200 EMA. At the moment, it's experiencing a pullback and has retraced to previous support levels near the 200 EMA. The price is encountering resistance near the 200 EMA and appears poised to start moving downwards. It's likely that the price will test previous lows in the near future.
TF : 1h
Entry : $0.00184
Target : $0.00162
SL : $0.00201
4834 new target 5000 🔥
🔥Claim/198 activationsFiredrop 0.25 HOT
How to claim:
╔•1.Join our village.
╠•
╚•2.Subscribe claim 0.25 HOT
🎁Gifts, NFTs, stars, premium Telegram, crypto airdrops, and tokens like 🔥HOT and more! Premium 👥VIP status! Join and win every day!
#hot
#HOT rejected from the ceiling of supply zone on 3D Time frame,it can bounce again from the Green zone, everything is bullish now
📈
❄️@signals_bitcoin_crypto❄️
❄️@Shadow_support0o❄️
🪙1853 new target 2000 #HOT🔥
How to claim:
1) Join our village.
2) Follow @ChatCryptoTON
🔥Claim 170/288 activationsFiredrop0.15 HOT
🔥Claim/88 activationsFiredrop0.25 HOT