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
#TFUEL/USDT analysis :
#TFUEL is currently forming a symmetrical triangle pattern on the monthly timeframe. The price is showing strong volume, indicating that a breakout from this pattern is likely to occur soon that can continue its upward momentum and test higher levels. A potential gain of around +620% is anticipated from the current level.
TF : 1M
Entry : $0.09330
Target : $0.67520
SL : $0.06149
#TFUEL/USDT analysis :
#TFUEL has bounce back from the support zone and break above the trendline. Price is expected to continue its bullish momentum and test previous highs.
TF : 4h
Entry : $0.06237
Target : $0.06954
SL : $0.05766
#TFUEL/USDT analysis :
#TFUEL is currently consolidating sideways near the resistance zone. The price is unable to break the zone upside and facing resistance. It's expected that the price will continue its bearish momentum from the current zone to test the previous swing low.
TF : 4H
Entry : $0.05740
Target : $0.04363
SL : $0.06297
#TFUEL/USDT analysis -
#TFUEL is in a downtrend on the HTF. The price is expected to continue its momentum, and previous lows will be tested. Before entering a short position, wait for a retracement for entry.
TF : 4H
Entry : $0.06791
Target : $0.06011
SL : $0.07132
#Tfuel Falling Wedge Breakout Has Confirmed Overall Consolidating In Symmetrical Triangle Expecting Move Towards In Descending Trendline In Coming Days And Once Trendline Got Cleared Can Easily Test 0.30$ In Midterm