Created
May 10, 2017 14:47
-
-
Save dmnlk/93353b8a422b7ac7b657437219461410 to your computer and use it in GitHub Desktop.
change slack status by wheather
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var token = ""; // fill your legacy token from https://api.slack.com/custom-integrations/legacy-tokens | |
| var city_id = "130010"; // change your city id from http://weather.livedoor.com/weather_hacks/webservice | |
| function myFunction() { | |
| var response = UrlFetchApp.fetch("http://weather.livedoor.com/forecast/webservice/json/v1?city="+city_id); | |
| if (response.getResponseCode() != 200) { | |
| return false; | |
| } | |
| var json = JSON.parse(response.getContentText()); | |
| var forecast = json["forecasts"][0]["telop"]; | |
| var short_forecast = forecast.substr(0,1) | |
| Logger.log(short_forecast); | |
| var emoji = ""; | |
| switch (short_forecast) { | |
| case "晴": | |
| emoji = ":sunny:"; | |
| break; | |
| case "曇": | |
| emoji = ":cloud:"; | |
| break; | |
| case "雨": | |
| emoji = ":umbrella_with_rain_drops:"; | |
| break; | |
| case "雪": | |
| emoji = ":snowman:"; | |
| break; | |
| default: | |
| emoji = ":sushi:"; | |
| break; | |
| } | |
| var profile = { | |
| "status_emoji": emoji, | |
| "status_text": forecast | |
| } | |
| var encodedProfile = encodeURIComponent(JSON.stringify(profile)) | |
| var result = UrlFetchApp.fetch("https://slack.com/api/users.profile.set?token=" + token + "&profile=" + encodedProfile); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment