Skip to content

Instantly share code, notes, and snippets.

@ypsilon-takai
Created June 5, 2023 09:44
Show Gist options
  • Save ypsilon-takai/4bb541d1f5d1ed4c7cacce3e6dfa5eea to your computer and use it in GitHub Desktop.
Save ypsilon-takai/4bb541d1f5d1ed4c7cacce3e6dfa5eea to your computer and use it in GitHub Desktop.
# 本社サーバのIPをslackにポストするスクリプト
import requests
# gip == global ip
gip_checker = 'http://ifconfig.io/ip'
# slack
TOKEN = '<トークン>'
CHANNEL = '<チャンネル名>'
def get_gip():
res = requests.get(gip_checker)
if res.status_code != 200:
gip = 'global ip get errror'
else
gip = res.text.strip()
return gip
def push_msg2slack(message):
slack_post_url = "https://slack.com/api/chat.postMessage"
headers = {"Authorization": "Bearer "+TOKEN}
data = {
'channel': CHANNEL,
'text': message
}
res = requests.post(slack_post_url, headers=headers, data=data)
print("return ", res.json())
if __name__ == '__main__':
global_ip = get_global_ip()
message = f'本社サーバのIPはこれです: {global_ip}'
push_msg2slack(message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment