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:49:28 +0900
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
6d470d4369b8d36ad7b2345b21f27571e28507cc
6d470d43
2 parents
80aa0474
039e1a43
merge listing
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
111 additions
and
0 deletions
main.js
package-lock.json
package.json
test/weather_test.js
weather.js
main.js
View file @
6d470d4
<<<<<<<
HEAD
import
fs
from
'fs/promises'
import
{
login
,
load
,
logout
}
from
'./khcanvas.js'
;
=======
>>>>>>>
weather
...
...
package-lock.json
View file @
6d470d4
This diff is collapsed. Click to expand it.
package.json
View file @
6d470d4
...
...
@@ -13,12 +13,19 @@
"author"
:
""
,
"license"
:
""
,
"dependencies"
:
{
"@types/axios"
:
"^0.14.0"
,
"@types/selenium-webdriver"
:
"^4.1.0"
,
<<<<<<<
HEAD
<<<<<<<
HEAD
"csv-parser"
:
"^3.0.0"
,
"eslint"
:
"^8.15.0"
,
=======
>>>>>>>
6
c
6
e
356
fa
8269
fbbdee
92
f
54
a
6
f
2
f
16
ffe
2
ba
729
=======
=======
"axios"
:
"^0.27.2"
,
>>>>>>>
weather
>>>>>>>
039
e
1
a
43
c
37157
ea
46
e
8
f
87599
a
93
f
75536
a
140
e
"mocha"
:
"^10.0.0"
,
"selenium-webdriver"
:
"^4.1.2"
},
...
...
test/weather_test.js
0 → 100644
View file @
6d470d4
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 @
6d470d4
//@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