Last active
August 21, 2018 10:06
-
-
Save YoruNoHikage/59667b9ef36d9b6b53fb07748056adf1 to your computer and use it in GitHub Desktop.
tenkizu
This file contains 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
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