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
🚨 Lucky Box Session 2: SOLD OUT 🚨
Big thanks to everyone who joined! 🎉 Now, get ready for the new game launch and don’t forget to claim your NFTs as soon as the game goes live 🚀
Stay tuned for more exciting updates! 🎁
#SingSingTycoon#LuckyBox
🚀 SingSing Top Referral Event 🚀
To celebrate the launch of the new SingSing Tycoon game, we're hosting a special event with a total prize pool of 160,000 $KARA! 🔥
🏆 Categories:
Top 10 Referrers with most Referees - 95,000 $KARA
🥇 1st: 30K $KARA
🥈 2nd: 20K $KARA
🥉 3rd: 10K $KARA
🏅 4th-10th: 5K $KARA
Top 5 Referrers with highest TON Commission - 65,000 $KARA
🥇 1st: 20K $KARA
🥈 2nd: 15K $KARA
🏅 3rd-5th: 10K $KARA
📅 Duration: Sep 30, 13:00 UTC - Oct 30, 23:59 UTC
Invite & Earn BIG! 💸
#SingSingTycoon#KARA
🎤Announcement | Chat | X (Twitter) | Website | Game
🎉 Let’s recap the 10 Lucky Stakers who snagged the first 10 TON in the 100 TON Daily Tycoon Launchpool!
1️⃣ CebuanoKing 🔵 ONUS BITS $X💠
2️⃣ Süleyman
3️⃣@Click_Mining
4️⃣ Arthur
5️⃣ Modzilla 🐔🐈⬛🎤 Firefox
6️⃣ SanMoTraz
7️⃣ Tuấn Anh 🇻🇳🐾
8️⃣ Em 🐔🍅🎤 C ^^
9️⃣ Pham Minh Nhan
🔟 Xaumarket
🔥 9 more days to go! Keep staking for your chance to win big 👉https://t.me/SingSing_TG_bot/app
👉#SingSingTycoon#TON#Launchpool
⚡️ Game Adjustment Alert ⚡️
Starting from floor 2, rooms without NFT will see a 50% decrease in earnings! 👀
Application time: From 13:00 UTC - Oct 9
You know what to do! Don’t let those NFTs sit idle in the Vault—equip them NOW for max earnings 💥🎤
#SingSingTycoon#NFTPower
🎤Announcement | Chat | X (Twitter) | Website | Game
🎤 Ready to take your karaoke empire to the next level? With Karaoke Box NFT and KTV NFT, the path to becoming the ultimate tycoon is within reach!
💥 Karaoke Box NFT is your ticket to faster earnings! The rarer the box, the more your earning speed skyrockets:
Common ➡️ x1.5 earning speed
Uncommon ➡️ x2 earning speed
Rare ➡️ x4 earning speed
Epic ➡️ x6 earning speed
Legendary ➡️ x8 earning speed
🏢 Meanwhile, the KTV NFT is key to unlocking more floors, allowing your karaoke chain to expand beyond limits:
Common ➡️ +1 floor
Uncommon ➡️ +3 floors
Rare ➡️ +5 floors
Epic ➡️ +10 floors
Legendary ➡️ +15 floors
✨ The rarer the NFT, the bigger the rewards! Time to upgrade and watch your karaoke business thrive like never before! 🚀
Check out how to leverage your NFTs here: https://t.me/singsingchannel/831
#SingSingTycoon#NFTPower
🎤Announcement | Chat | X (Twitter) | Website | Game
🚀 How to List Your NFT on SingSing Tycoon NFT Marketplace 🚀
1️⃣ Activate 2FA first! (Required for all NFT Marketplace transactions) (https://t.me/singsingchannel/869)
2️⃣ Tap the NFT Trade icon at the bottom-right to enter the Marketplace.
3️⃣ Click the Options Menu (top-right) and select 'List Your NFT.'
4️⃣ Choose the NFT you want to list.
5️⃣ Set your price in TON & hit 'List NFT.' Once listed, check 'My Listed' to view your NFTs.
Start listing and trading now! 💎🛒
#SingSingTycoon#NFTMarketplace#Web3
🎤Announcement | Chat | X (Twitter) | Website | Game
🎤 Add this emoji to your Telegram name & get free $KARA! 🎉
How to claim:
1️⃣ Copy this emoji: 🎤
2️⃣ Open Telegram -> Settings -> My Account -> Name
3️⃣ Paste that adorable 🎤 next to your name
4️⃣ Complete the task in the SingSing Tycoon app 👉Claim your $KARA💰
Easy peasy! Go claim your rewards now! 🎉
#SingSingTycoon#FreeKARA#Web3
🎤Announcement | Chat | X (Twitter) | Website | Game
🚨 Oct 14 Sale is LIVE NOW! 🚨
🎁 30 Lucky Boxes – 400 RUBY each
Unbox and receive random KTV NFT or Karaoke Box NFT 🎤
🔗Purchase Link - https://t.me/SingSing_TG_bot/app?startapp=_marketplace
#SingSingTycoon#LuckyBox#KaraBox
🎤Announcement | Chat | X (Twitter) | Website | Game
🚨 Oct 14 Sale will LIVE at 13:00 UTC - Oct 14🚨
🎁 30 Lucky Boxes – 400 RUBY each
Unbox and receive random KTV NFT or Karaoke Box NFT 🎤
#SingSingTycoon#LuckyBox#KaraBox
🎤Announcement | Chat | X (Twitter) | Website | Game
🚨 Oct 9 Sale is LIVE NOW! 🚨
🎁 40 Lucky Boxes – 400 RUBY each
Unbox and receive random KTV NFT or Karaoke Box NFT 🎤
🔗Purchase Link - https://t.me/SingSing_TG_bot/app?startapp=_marketplace
#SingSingTycoon#LuckyBox#KaraBox
🎤Announcement | Chat | X (Twitter) | Website | Game
🚨 Oct 9 Sale will LIVE at 13:00 UTC - Oct 9🚨
🎁 40 Lucky Boxes – 400 RUBY each
Unbox and receive random KTV NFT or Karaoke Box NFT 🎤
#SingSingTycoon#LuckyBox#KaraBox
🎤Announcement | Chat | X (Twitter) | Website | Game
🚨 Oct 7 Sale is LIVE NOW! 🚨
🎁 30 Lucky Boxes – 400 RUBY each
📦 20 Kara Boxes – 300 RUBY each
🔗Purchase Link - https://t.me/SingSing_TG_bot/app?startapp=_marketplace
#SingSingTycoon#LuckyBox#KaraBox
🎤Announcement | Chat | X (Twitter) | Website | Game