Toggle navigation
Toggle navigation
This project
Loading...
Sign in
신원형
/
study-or-enjoy
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
신원형
2022-05-29 15:44:15 +0900
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
039e1a43c37157ea46e8f87599a93f75536a140e
039e1a43
2 parents
6c6e356f
e9504433
merged weather
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
288 additions
and
0 deletions
main.js
package-lock.json
package.json
test/weather_test.js
weather.js
main.js
View file @
039e1a4
<<<<<<<
HEAD
import
fs
from
'fs/promises'
import
{
login
,
load
,
logout
}
from
'./khcanvas.js'
;
=======
>>>>>>>
weather
...
...
package-lock.json
View file @
039e1a4
...
...
@@ -8,7 +8,12 @@
"name"
:
"study-or-enjoy"
,
"version"
:
"1.0.0"
,
"dependencies"
:
{
"@types/axios"
:
"^0.14.0"
,
"@types/selenium-webdriver"
:
"^4.1.0"
,
<<<<<<<
HEAD
=======
"axios"
:
"^0.27.2"
,
>>>>>>>
weather
"mocha"
:
"^10.0.0"
,
"selenium-webdriver"
:
"^4.1.2"
},
...
...
@@ -100,6 +105,18 @@
"resolved"
:
"https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz"
,
"integrity"
:
"sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA=="
,
"dev"
:
true
<<<<<<<
HEAD
=======
},
"node_modules/@types/axios"
:
{
"version"
:
"0.14.0"
,
"resolved"
:
"https://registry.npmjs.org/@types/axios/-/axios-0.14.0.tgz"
,
"integrity"
:
"sha512-KqQnQbdYE54D7oa/UmYVMZKq7CO4l8DEENzOKc4aBRwxCXSlJXGz83flFx5L7AWrOQnmuN3kVsRdt+GZPPjiVQ=="
,
"deprecated"
:
"This is a stub types definition for axios (https://github.com/mzabriskie/axios). axios provides its own type definitions, so you don't need @types/axios installed!"
,
"dependencies"
:
{
"axios"
:
"*"
}
>>>>>>>
weather
},
"node_modules/@types/node"
:
{
"version"
:
"17.0.35"
,
...
...
@@ -211,6 +228,20 @@
"resolved"
:
"https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz"
,
"integrity"
:
"sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q=="
},
"node_modules/asynckit"
:
{
"version"
:
"0.4.0"
,
"resolved"
:
"https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz"
,
"integrity"
:
"sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
},
"node_modules/axios"
:
{
"version"
:
"0.27.2"
,
"resolved"
:
"https://registry.npmjs.org/axios/-/axios-0.27.2.tgz"
,
"integrity"
:
"sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ=="
,
"dependencies"
:
{
"follow-redirects"
:
"^1.14.9"
,
"form-data"
:
"^4.0.0"
}
},
"node_modules/balanced-match"
:
{
"version"
:
"1.0.2"
,
"resolved"
:
"https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz"
,
...
...
@@ -346,6 +377,17 @@
"resolved"
:
"https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz"
,
"integrity"
:
"sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
},
"node_modules/combined-stream"
:
{
"version"
:
"1.0.8"
,
"resolved"
:
"https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz"
,
"integrity"
:
"sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg=="
,
"dependencies"
:
{
"delayed-stream"
:
"~1.0.0"
},
"engines"
:
{
"node"
:
">= 0.8"
}
},
"node_modules/concat-map"
:
{
"version"
:
"0.0.1"
,
"resolved"
:
"https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz"
,
...
...
@@ -407,6 +449,17 @@
"resolved"
:
"https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz"
,
"integrity"
:
"sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ=="
,
"dev"
:
true
<<<<<<<
HEAD
=======
},
"node_modules/delayed-stream"
:
{
"version"
:
"1.0.0"
,
"resolved"
:
"https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz"
,
"integrity"
:
"sha1-3zrhmayt+31ECqrgsp4icrJOxhk="
,
"engines"
:
{
"node"
:
">=0.4.0"
}
>>>>>>>
weather
},
"node_modules/diff"
:
{
"version"
:
"5.0.0"
,
...
...
@@ -725,6 +778,41 @@
"resolved"
:
"https://registry.npmjs.org/flatted/-/flatted-3.2.5.tgz"
,
"integrity"
:
"sha512-WIWGi2L3DyTUvUrwRKgGi9TwxQMUEqPOPQBVi71R96jZXJdFskXEmf54BoZaS1kknGODoIGASGEzBUYdyMCBJg=="
,
"dev"
:
true
<<<<<<<
HEAD
=======
},
"node_modules/follow-redirects"
:
{
"version"
:
"1.15.0"
,
"resolved"
:
"https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.0.tgz"
,
"integrity"
:
"sha512-aExlJShTV4qOUOL7yF1U5tvLCB0xQuudbf6toyYA0E/acBNw71mvjFTnLaRp50aQaYocMR0a/RMMBIHeZnGyjQ=="
,
"funding"
:
[
{
"type"
:
"individual"
,
"url"
:
"https://github.com/sponsors/RubenVerborgh"
}
],
"engines"
:
{
"node"
:
">=4.0"
},
"peerDependenciesMeta"
:
{
"debug"
:
{
"optional"
:
true
}
}
},
"node_modules/form-data"
:
{
"version"
:
"4.0.0"
,
"resolved"
:
"https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz"
,
"integrity"
:
"sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww=="
,
"dependencies"
:
{
"asynckit"
:
"^0.4.0"
,
"combined-stream"
:
"^1.0.8"
,
"mime-types"
:
"^2.1.12"
},
"engines"
:
{
"node"
:
">= 6"
}
>>>>>>>
weather
},
"node_modules/fs.realpath"
:
{
"version"
:
"1.0.0"
,
...
...
@@ -1058,6 +1146,25 @@
"url"
:
"https://github.com/sponsors/sindresorhus"
}
},
"node_modules/mime-db"
:
{
"version"
:
"1.52.0"
,
"resolved"
:
"https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz"
,
"integrity"
:
"sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg=="
,
"engines"
:
{
"node"
:
">= 0.6"
}
},
"node_modules/mime-types"
:
{
"version"
:
"2.1.35"
,
"resolved"
:
"https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz"
,
"integrity"
:
"sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw=="
,
"dependencies"
:
{
"mime-db"
:
"1.52.0"
},
"engines"
:
{
"node"
:
">= 0.6"
}
},
"node_modules/minimatch"
:
{
"version"
:
"5.0.1"
,
"resolved"
:
"https://registry.npmjs.org/minimatch/-/minimatch-5.0.1.tgz"
,
...
...
@@ -1757,6 +1864,17 @@
"resolved"
:
"https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz"
,
"integrity"
:
"sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA=="
,
"dev"
:
true
<<<<<<<
HEAD
=======
},
"@types/axios"
:
{
"version"
:
"0.14.0"
,
"resolved"
:
"https://registry.npmjs.org/@types/axios/-/axios-0.14.0.tgz"
,
"integrity"
:
"sha512-KqQnQbdYE54D7oa/UmYVMZKq7CO4l8DEENzOKc4aBRwxCXSlJXGz83flFx5L7AWrOQnmuN3kVsRdt+GZPPjiVQ=="
,
"requires"
:
{
"axios"
:
"*"
}
>>>>>>>
weather
},
"@types/node"
:
{
"version"
:
"17.0.35"
,
...
...
@@ -1841,6 +1959,20 @@
"resolved"
:
"https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz"
,
"integrity"
:
"sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q=="
},
"asynckit"
:
{
"version"
:
"0.4.0"
,
"resolved"
:
"https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz"
,
"integrity"
:
"sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
},
"axios"
:
{
"version"
:
"0.27.2"
,
"resolved"
:
"https://registry.npmjs.org/axios/-/axios-0.27.2.tgz"
,
"integrity"
:
"sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ=="
,
"requires"
:
{
"follow-redirects"
:
"^1.14.9"
,
"form-data"
:
"^4.0.0"
}
},
"balanced-match"
:
{
"version"
:
"1.0.2"
,
"resolved"
:
"https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz"
,
...
...
@@ -1940,6 +2072,14 @@
"resolved"
:
"https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz"
,
"integrity"
:
"sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
},
"combined-stream"
:
{
"version"
:
"1.0.8"
,
"resolved"
:
"https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz"
,
"integrity"
:
"sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg=="
,
"requires"
:
{
"delayed-stream"
:
"~1.0.0"
}
},
"concat-map"
:
{
"version"
:
"0.0.1"
,
"resolved"
:
"https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz"
,
...
...
@@ -1986,6 +2126,14 @@
"resolved"
:
"https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz"
,
"integrity"
:
"sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ=="
,
"dev"
:
true
<<<<<<<
HEAD
=======
},
"delayed-stream"
:
{
"version"
:
"1.0.0"
,
"resolved"
:
"https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz"
,
"integrity"
:
"sha1-3zrhmayt+31ECqrgsp4icrJOxhk="
>>>>>>>
weather
},
"diff"
:
{
"version"
:
"5.0.0"
,
...
...
@@ -2227,6 +2375,24 @@
"resolved"
:
"https://registry.npmjs.org/flatted/-/flatted-3.2.5.tgz"
,
"integrity"
:
"sha512-WIWGi2L3DyTUvUrwRKgGi9TwxQMUEqPOPQBVi71R96jZXJdFskXEmf54BoZaS1kknGODoIGASGEzBUYdyMCBJg=="
,
"dev"
:
true
<<<<<<<
HEAD
=======
},
"follow-redirects"
:
{
"version"
:
"1.15.0"
,
"resolved"
:
"https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.0.tgz"
,
"integrity"
:
"sha512-aExlJShTV4qOUOL7yF1U5tvLCB0xQuudbf6toyYA0E/acBNw71mvjFTnLaRp50aQaYocMR0a/RMMBIHeZnGyjQ=="
},
"form-data"
:
{
"version"
:
"4.0.0"
,
"resolved"
:
"https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz"
,
"integrity"
:
"sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww=="
,
"requires"
:
{
"asynckit"
:
"^0.4.0"
,
"combined-stream"
:
"^1.0.8"
,
"mime-types"
:
"^2.1.12"
}
>>>>>>>
weather
},
"fs.realpath"
:
{
"version"
:
"1.0.0"
,
...
...
@@ -2474,6 +2640,19 @@
"is-unicode-supported"
:
"^0.1.0"
}
},
"mime-db"
:
{
"version"
:
"1.52.0"
,
"resolved"
:
"https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz"
,
"integrity"
:
"sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg=="
},
"mime-types"
:
{
"version"
:
"2.1.35"
,
"resolved"
:
"https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz"
,
"integrity"
:
"sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw=="
,
"requires"
:
{
"mime-db"
:
"1.52.0"
}
},
"minimatch"
:
{
"version"
:
"5.0.1"
,
"resolved"
:
"https://registry.npmjs.org/minimatch/-/minimatch-5.0.1.tgz"
,
...
...
package.json
View file @
039e1a4
...
...
@@ -13,7 +13,12 @@
"author"
:
""
,
"license"
:
""
,
"dependencies"
:
{
"@types/axios"
:
"^0.14.0"
,
"@types/selenium-webdriver"
:
"^4.1.0"
,
<<<<<<<
HEAD
=======
"axios"
:
"^0.27.2"
,
>>>>>>>
weather
"mocha"
:
"^10.0.0"
,
"selenium-webdriver"
:
"^4.1.2"
},
...
...
test/weather_test.js
0 → 100644
View file @
039e1a4
import
*
as
mocha
from
'mocha'
import
*
as
weater
from
'../weather.js'
mocha
.
describe
(
'weather'
,
()
=>
{
mocha
.
it
(
'get tomorrow weather'
,
async
()
=>
{
weater
.
get_weather_forecast
(
new
Date
())
.
then
(
it
=>
console
.
log
(
it
))
.
catch
(
it
=>
console
.
log
(
it
))
})
mocha
.
it
(
'get 7 days later weather'
,
async
()
=>
{
const
date
=
new
Date
()
date
.
setDate
(
new
Date
().
getDate
()
+
7
)
weater
.
get_weather_forecast
(
date
)
.
then
(
it
=>
console
.
log
(
it
))
.
catch
(
it
=>
console
.
log
(
it
))
})
});
\ No newline at end of file
weather.js
0 → 100644
View file @
039e1a4
//@ts-check
/* eslint-disable no-unused-vars */
import
*
as
axios
from
'axios'
;
// 최대 7 일간 예보를 반환합니다. 경희대 국제캠퍼스 정문 앞 삼거리 기준으로 호출됩니다.
// 5/27일에 호출했을 경우 6/3일까지의 정오 (한국표준시 기준) 결과를 반환할 수 있습니다.
// 정오 기준, 가장 가까운 날짜의 예보를 반환합니다.
// 예) 호출한 날짜로부터 한 달 뒤 호출 => 호출한 날짜로부터 일주일 뒤 날짜 반환 (최대가 일주일이므로)
// 예) 6/2일 오후 4시 호출 => 6/2일 정오 날씨 반환 (정오 기준이므로)
// 온도의 경우 단위는 섭씨입니다.
/*example
"dt": 1653620400,
"sunrise": 1653596132,
"sunset": 1653648142,
"moonrise": 1653589560,
"moonset": 1653637140,
"moon_phase": 0.9,
"temp": {
"day": 21.75,
"min": 15.7,
"max": 22.85,
"night": 16.88,
"eve": 21.29,
"morn": 15.7
},
"feels_like": {
"day": 21.13,
"night": 16.35,
"eve": 20.57,
"morn": 15.41
},
"pressure": 1001,
"humidity": 44,
"dew_point": 8.88,
"wind_speed": 5.88,
"wind_deg": 273,
"wind_gust": 12.32,
"weather": [
{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10d"
}
],
"clouds": 9,
"pop": 0.2, //Probability of precipitation. The values of the parameter vary between 0 and 1, where 0 is equal to 0%, 1 is equal to 100%
"rain": 0.13, //Precipitation volume, mm
"uvi": 7.71 //The maximum value of UV index for the day
*/
export
async
function
get_weather_forecast
(
date
)
{
const
lat
=
37.24764302276268
//위도
const
lon
=
127.0783992268606
//경도
const
api_key
=
"336ddd01d3d6f78782eed90d3921bc7e"
const
target
=
`https://api.openweathermap.org/data/2.5/onecall?lat=
${
lat
}
&lon=
${
lon
}
&exclude=minutely,hourly,alerts&appid=
${
api_key
}
&units=metric`
return
await
axios
.
default
.
get
(
target
).
then
(
it
=>
{
return
extract_from
(
date
,
it
.
data
)
})
}
function
extract_from
(
date
,
json_response
)
{
const
target_timestamp
=
Math
.
floor
(
date
.
getTime
()
/
1000
)
const
target_index
=
find_min_index
(
json_response
.
daily
.
map
(
it
=>
Math
.
abs
(
it
.
dt
-
target_timestamp
)))
return
json_response
.
daily
[
target_index
]
}
function
find_min_index
(
array
)
{
let
lowest_index
=
0
for
(
var
i
=
0
;
i
<
array
.
length
;
i
++
)
{
if
(
array
[
lowest_index
]
>
array
[
i
])
{
lowest_index
=
i
}
}
return
lowest_index
}
\ No newline at end of file
Please
register
or
login
to post a comment