Skip to content

Instantly share code, notes, and snippets.

@YoruNoHikage
Last active August 21, 2018 10:06
Show Gist options
  • Save YoruNoHikage/59667b9ef36d9b6b53fb07748056adf1 to your computer and use it in GitHub Desktop.
Save YoruNoHikage/59667b9ef36d9b6b53fb07748056adf1 to your computer and use it in GitHub Desktop.
tenkizu
const Twitter = require('twitter');
const fetch = require('node-fetch');
const generateWeather = async () => {
let c = [
// hokkaido
1116988, 1117873, 1118108, 1117927,
// honshu north
// aomori, , morioka,
1116973, 1116952, 1117776, 1117881, 1118129,
// honshu east
// kanazawa, nagano, utsunomiya, nagoya, shizuoka, tokyo
1117438, 1117807, 1118483, 1117817, 1118217, 1118370,
// kansai
// yamaguchi, hiroshima, okayama, kyoto, hashimoto, toba
1118517, 1117227, 28377462, 15015372, 1117171, 1118345,
// shikoku
// kochi, tokushima
28642722, 1118368,
// kyushu
23388316, 1117378,
// miyakojima, okinawa
28379331, 1113469,
// ogasawara
// not on Yahoo :(
];
const url = `https://query.yahooapis.com/v1/public/yql?q=select location.city, item.condition from weather.forecast where woeid in (${c.join(',')})&format=json`;
const response = await fetch(url);
const data = await response.json();
const conditionsList = c.map((id, index) => data.query.results.channel[index] && data.query.results.channel[index].item.condition.code || 3200);
const conditions = {
0: 'πŸŒͺ️', // tornado
1: 'πŸŒ€', // tropical storm
2: 'πŸŒ€', // hurricane
3: 'β›ˆ', // severe thunderstorms
4: 'β›ˆ', // thunderstorms
5: '🌧️', // mixed rain and snow
6: '🌧️', // mixed rain and sleet
7: '🌨️', // mixed snow and sleet
8: '🌧️', // freezing drizzle
9: '🌧️', // drizzle
10: '🌧️', // freezing rain
11: 'πŸ’¦', // showers
12: 'πŸ’¦', // showers
13: '❄', // snow flurries
14: '🌨️', // light snow showers
15: '❄', // blowing snow
16: '❄', // snow
17: '🌨️', // hail
18: '🌨️', // sleet
19: 'πŸ€”', // dust
20: '🌁', // foggy
21: '🌫️', // haze
22: '🌫️', // smoky
23: 'πŸ’¨', // blustery
24: 'πŸƒ', // windy
25: 'πŸ₯Ά', // cold
26: '☁', // cloudy
27: '☁', // mostly cloudy (night)
28: 'πŸŒ₯️', // mostly cloudy (day)
29: '☁', // partly cloudy (night)
30: '🌀️', // partly cloudy (day)
31: 'πŸŒ‘', // clear (night)
32: 'β˜€', // sunny
33: 'πŸŒ‘', // fair (night)
34: 'β˜€', // fair (day)
35: '🌧', // mixed rain and hail
36: 'πŸ₯΅', // hot
37: '⚑️', // isolated thunderstorms
38: '🌩️', // scattered thunderstorms
39: '🌩️', // scattered thunderstorms
40: '🌧', // scattered showers
41: '❄', // heavy snow
42: '🌨', // scattered snow showers
43: '❄', // heavy snow
44: '🌀', // partly cloudy
45: 'β›ˆοΈ', // thundershowers
46: '❄', // snow showers
47: 'β›ˆοΈ', // isolated thundershowers
3200: '❔', // not available
}
c = conditionsList.map(code => conditions[code]);
c.unshift(0);
const weather =
`#倩気 #倩気情報
γ€€γ€€γ€€ ${c[27]}γ€€γ€€γ€€γ€€γ€€γ€€γ€€ ${c[ 1]}${c[ 2]}
γ€€γ€€γ€€ γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€ ${c[ 3]}${c[ 4]}
γ€€${c[26]}γ€€γ€€γ€€ γ€€γ€€ γ€€γ€€γ€€ ${c[ 5]}
          ${c[ 6]}${c[ 7]}
          ${c[ 8]}${c[ 9]}
γ€€γ€€γ€€γ€€γ€€γ€€γ€€γ€€${c[10]}${c[11]}${c[12]}
${c[16]}${c[17]}${c[18]}${c[19]}${c[13]}${c[14]}${c[15]}
${c[24]}γ€€${c[22]}${c[23]}γ€€${c[20]}${c[21]}
${c[25]}`;
return weather;
};
export default async function postTweet(hook) {
const client = new Twitter({
consumer_key: hook.env.TWITTER_CONSUMER_KEY,
consumer_secret: hook.env.TWITTER_CONSUMER_SECRET,
access_token_key: hook.env.TWITTER_ACCESS_TOKEN_KEY,
access_token_secret: hook.env.TWITTER_ACCESS_TOKEN_SECRET
});
const status = await generateWeather();
client.post('statuses/update', {status}, (err, data) => {
if (err) console.log(err);
hook.res.end(data);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment