Skip to content

Instantly share code, notes, and snippets.

@rinsuki
Created June 25, 2016 01:35
Show Gist options
  • Save rinsuki/799ab614fd88bfa22409ec1bc91d12a9 to your computer and use it in GitHub Desktop.
Save rinsuki/799ab614fd88bfa22409ec1bc91d12a9 to your computer and use it in GitHub Desktop.
#!/usr/bin/python2
# configure
slack_api_token="PLEASE_REPLACE_YOUR_SLACK_BOT_API_TOKEN"
slack_channel="update-notify"
server_name="main vm"
import os
os.system("echo n | LANG=C pacman -Syu > /tmp/pacman-result.txt 2> /dev/null")
import requests
fp = open("/tmp/pacman-result.txt","r")
while(True):
text = fp.readline()
if(text[0:23]==" there is nothing to do"):
exit()
if(text[0:8]=="Packages"):
break
fp.close()
post = "ArchLinux("+server_name+") Updates\n"
packages=(' '.join(text.split(" ")[2:])).split(" ")
for package in packages:
post += "- "+package+"\n"
requests.post("https://slack.com/api/chat.postMessage",data={
"text":post,
"token":slack_api_token,
"channel":slack_channel
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment