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
#SAND/USDT analysis :
#SAND is currently in a downtrend, consistently making new lows on the daily time frame. The price is facing rejection from the resistance zone and the 200 EMA, and it is expected to test the support zone and the previous swing low. Look for a pullback to identify a potential short entry.
TF : 1D
Entry : $0.2852
Target : $0.2275
SL : $0.3253
#SAND/USDT analysis :
#SAND is currently in an uptrend, forming Higher Highs (HHs) and Higher Lows (HLs) above the 200ema. The price has broken the trendline after bouncing from a support zone. It is expected to maintain its bullish momentum and target previous highs.
TF : 30min
Entry : $0.2958
Target : $0.3076
SL : $0.2888
#SAND Market Analysis
SAND/USDT remains bearish with price hovering near the lower Bollinger Band and RSI sitting close to oversold at 33. MACD confirms downside momentum, reinforcing the weak structure below key resistances around 0.077. Bull case: hold above 0.0717 to target a retest of 0.0755 and possibly 0.0771 resistance. Bear case: lose 0.0717 and risk acceleration toward lower supports. Watch 0.0717 closely for the next directional cue.
---
➖➖➖➖➖➖➖
Bitcoin Bullets® Trading
#SAND Market Analysis
SAND/USDT is in a bearish trend with RSI deep in oversold territory and MACD confirming downside momentum. Price trades near the lower Bollinger Band, signaling potential for a short-term bounce but overall pressure remains. Bull case: hold above 0.0755 to target a retest of 0.0780 resistance. Bear case: break below 0.0755 risks continuation lower, exposing further downside below 0.071. Key level to watch: 0.0755 support.
---
➖➖➖➖➖➖➖
Bitcoin Bullets® Trading
#SAND Market Analysis
SAND/USDT shows a weak bullish structure with price hovering near the lower Bollinger Band and RSI sitting below 50, signaling limited upside momentum. MACD remains bearish, indicating sellers still have influence despite the mild uptrend. Bull case: hold above 0.0765 to target resistance at 0.0797 for a potential bounce. Bear case: lose 0.0755 and risk deeper pullback towards the next support zone. Key level to watch: 0.0765.
---
➖➖➖➖➖➖➖
Bitcoin Bullets® Trading