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
#CELR/USDT analysis :
#CELR is currently forming a triangle pattern. A breakout from this pattern is anticipated, with the price expected to test previous highs. A long entry is recommended upon a breakout above the $0.02130 level.
TF : 1D
Entry : $0.02130
Target : $0.03180
SL : $0.01695
#CELR/USDT analysis :
#CELR is currently in a downtrend, trading below the 200 EMA. The price is currently facing resistance in this zone. It is expected to reverse from this point and continue its bearish trend to test previous lows. Wait for a breakout below the $0.01114 level to consider going short.
TF : 4H
Entry : $0.01114
Target : $0.01014
SL : $0.01169
#CELR/USDT analysis :
#CELR is in a downtrend, trading below the 200 EMA. The price is forming LLs and LHs structure. Before continuing its bearish momentum, the price is expected to experience a pullback and test the resistance zone. Wait for the pullback for a short entry.
TF : 1H
Entry : $0.01142
Target : $0.01043
SL : $0.01177
#CELR/USDT analysis -
#CELR is in a downtrend, trading below the 200 EMA. The price is currently approaching a resistance zone. It is expected to be rejected from there and continue the bearish momentum towards the previous lows.
TF : 4h
Entry : $0.0157
Target : $0.0129
SL : $0.0164
#CELR/USDT BUY SETUP
CELR has broken out of the descending triangle and is currently testing it. A successful test will confirm a bullish move. Get ready for takeoff. 🚀