ソースを参照

corona update

tobby48 5 年 前
コミット
a3e238ea4d

+ 22
- 24
src/main/python/kr/co/swh/lecture/opensource/project/colona/corona-1.py ファイルの表示

@@ -1,24 +1,22 @@
1
-from bs4 import BeautifulSoup
2
-import requests
3
-import json
4
-
5
-page = 1
6
-category = ['약국', '우체국', '농협']
7
-print("%-20s%-80s%-10s" % ('이름', '주소', '유형'))
8
-datas = dict()
9
-while 1:
10
-    response = requests.get('https://8oi9s0nnth.apigw.ntruss.com/corona19-masks/v1/stores/json?page=%d&perPage=500' % page)
11
-    mask = BeautifulSoup(response.text, "html.parser")
12
-    maskdict = json.loads(mask.text)
13
-    if len(maskdict.get('storeInfos')) == 0:
14
-        break
15
-    for b in maskdict.get('storeInfos'):
16
-        d=""
17
-        if b.get('type') == '01':
18
-            d=category[0]
19
-        if b.get('type') == '02':
20
-            d=category[1]
21
-        if b.get('type') == '03':
22
-            d=category[2]
23
-        print("%-20s%-80s%-10s" % (b.get('name'), b.get('addr'), d))
24
-    page = page + 1
1
+import requests
2
+import json
3
+
4
+page = 1
5
+category = ['약국', '우체국', '농협']
6
+print("%-20s%-80s%-10s" % ('이름', '주소', '유형'))
7
+datas = dict()
8
+while 1:
9
+    response = requests.get('https://8oi9s0nnth.apigw.ntruss.com/corona19-masks/v1/stores/json?page=%d&perPage=500' % page)
10
+    maskdict = json.loads(response.text)
11
+    if len(maskdict.get('storeInfos')) == 0:
12
+        break
13
+    for b in maskdict.get('storeInfos'):
14
+        d=""
15
+        if b.get('type') == '01':
16
+            d=category[0]
17
+        if b.get('type') == '02':
18
+            d=category[1]
19
+        if b.get('type') == '03':
20
+            d=category[2]
21
+        print("%-20s%-80s%-10s" % (b.get('name'), b.get('addr'), d))
22
+    page = page + 1

+ 27
- 30
src/main/python/kr/co/swh/lecture/opensource/project/colona/corona-2.py ファイルの表示

@@ -1,30 +1,27 @@
1
-from bs4 import BeautifulSoup
2
-import requests
3
-import json
4
-
5
-page = 1
6
-datas = dict()
7
-while 1:
8
-    response = requests.get('https://8oi9s0nnth.apigw.ntruss.com/corona19-masks/v1/stores/json?page=%d&perPage=500' % page)
9
-    mask = BeautifulSoup(response.text, "html.parser")
10
-    maskdict = json.loads(mask.text)
11
-    if len(maskdict.get('storeInfos')) == 0:
12
-        break
13
-    for b in maskdict.get('storeInfos'):
14
-        datas[b.get('code')] = b;
15
-    page = page + 1
16
-
17
-print("%-20s%-80s%-10s" % ('이름', '주소', '재고상태'))
18
-page = 1
19
-while 1:
20
-    response = requests.get('https://8oi9s0nnth.apigw.ntruss.com/corona19-masks/v1/sales/json?page=%d&perPage=500' % page)
21
-    mask = BeautifulSoup(response.text, "html.parser")
22
-    maskdict = json.loads(mask.text)
23
-    if len(maskdict.get('sales')) == 0:
24
-        break
25
-    for b in maskdict.get('sales'):
26
-        if b.get('code') not in datas:
27
-            continue
28
-        data = datas[b.get('code')]
29
-        print("%-20s%-80s%-10s" % (data.get('name'), data.get('addr'), b.get('remain_stat')))
30
-    page = page + 1
1
+import requests
2
+import json
3
+
4
+page = 1
5
+datas = dict()
6
+while 1:
7
+    response = requests.get('https://8oi9s0nnth.apigw.ntruss.com/corona19-masks/v1/stores/json?page=%d&perPage=500' % page)
8
+    maskdict = json.loads(response.text)
9
+    if len(maskdict.get('storeInfos')) == 0:
10
+        break
11
+    for b in maskdict.get('storeInfos'):
12
+        datas[b.get('code')] = b;
13
+    page = page + 1
14
+
15
+print("%-20s%-80s%-10s" % ('이름', '주소', '재고상태'))
16
+page = 1
17
+while 1:
18
+    response = requests.get('https://8oi9s0nnth.apigw.ntruss.com/corona19-masks/v1/sales/json?page=%d&perPage=500' % page)
19
+    maskdict = json.loads(response.text)
20
+    if len(maskdict.get('sales')) == 0:
21
+        break
22
+    for b in maskdict.get('sales'):
23
+        if b.get('code') not in datas:
24
+            continue
25
+        data = datas[b.get('code')]
26
+        print("%-20s%-80s%-10s" % (data.get('name'), data.get('addr'), b.get('remain_stat')))
27
+    page = page + 1

+ 56
- 0
src/main/python/kr/co/swh/lecture/opensource/project/colona/final-corona.py ファイルの表示

@@ -0,0 +1,56 @@
1
+from konlpy.tag import Kkma
2
+import os
3
+import sys
4
+import urllib.request
5
+import json
6
+import re
7
+from flask import Flask, jsonify, render_template
8
+import requests
9
+import json
10
+
11
+app = Flask(__name__)
12
+# app.config['JSON_AS_ASCII'] = False
13
+
14
+
15
+def getMask(): 
16
+    page = 1
17
+    datas = dict()
18
+    while 1:
19
+        response = requests.get('https://8oi9s0nnth.apigw.ntruss.com/corona19-masks/v1/stores/json?page=%d&perPage=500' % page)
20
+        maskdict = json.loads(response.text)
21
+        if len(maskdict.get('storeInfos')) == 0:
22
+            break
23
+        for b in maskdict.get('storeInfos'):
24
+            datas[b.get('code')] = b;
25
+        page = page + 1
26
+        if page < 3:
27
+            break
28
+    result = []
29
+    page = 1
30
+    while 1:
31
+        response = requests.get('https://8oi9s0nnth.apigw.ntruss.com/corona19-masks/v1/sales/json?page=%d&perPage=500' % page)
32
+        maskdict = json.loads(response.text)
33
+        if len(maskdict.get('sales')) == 0:
34
+            break
35
+        for b in maskdict.get('sales'):
36
+            if b.get('code') not in datas:
37
+                continue
38
+            data = datas[b.get('code')]
39
+            
40
+            if data.get('lat'):
41
+                o = dict()
42
+                o['name'] = data.get('name')
43
+                o['addr'] = data.get('addr')
44
+                o['loc'] = [data.get('lat'), data.get('lng')]
45
+                o['remain_stat'] = b.get('remain_stat')
46
+                result.append(o)
47
+        page = page + 1
48
+    return result
49
+
50
+@app.route("/")
51
+def view():
52
+    return render_template("final-corona.html", values=result)
53
+
54
+if __name__ == "__main__":
55
+    result = getMask()
56
+    app.run(host="127.0.0.1", port="8080")

+ 19
- 0
src/main/python/kr/co/swh/lecture/opensource/project/colona/templates/1-map.html ファイルの表示

@@ -0,0 +1,19 @@
1
+<html>
2
+<head>
3
+    <meta charset="UTF-8">
4
+    <title>간단한 지도 표시하기</title>
5
+    <script type="text/javascript" src="https://openapi.map.naver.com/openapi/v3/maps.js?ncpClientId=o88z15l7bh"></script>
6
+</head>
7
+<body>
8
+<div id="map" style="width:100%;height:400px;"></div>
9
+
10
+<script>
11
+var mapOptions = {
12
+    center: new naver.maps.LatLng(37.3595704, 127.105399),
13
+    zoom: 10
14
+};
15
+
16
+var map = new naver.maps.Map('map', mapOptions);
17
+</script>
18
+</body>
19
+</html>

+ 26
- 0
src/main/python/kr/co/swh/lecture/opensource/project/colona/templates/2-one-marker.html ファイルの表示

@@ -0,0 +1,26 @@
1
+<html>
2
+<head>
3
+    <meta charset="UTF-8">
4
+    <title>간단한 지도 표시하기</title>
5
+    <script type="text/javascript" src="https://openapi.map.naver.com/openapi/v3/maps.js?ncpClientId=o88z15l7bh"></script>
6
+</head>
7
+<body>
8
+<div id="map" style="width:100%;height:400px;"></div>
9
+
10
+<script>
11
+var mapOptions = {
12
+    center: new naver.maps.LatLng(35.8862487, 128.6023765),
13
+    zoom: 10
14
+};
15
+
16
+var map = new naver.maps.Map('map', mapOptions);
17
+
18
+var markerOptions = {
19
+    position: new naver.maps.LatLng(35.8862487, 128.6023765),
20
+    map: map
21
+};
22
+
23
+var marker = new naver.maps.Marker(markerOptions);
24
+</script>
25
+</body>
26
+</html>

+ 32
- 0
src/main/python/kr/co/swh/lecture/opensource/project/colona/templates/3-one-label.html ファイルの表示

@@ -0,0 +1,32 @@
1
+<html>
2
+<head>
3
+    <meta charset="UTF-8">
4
+    <title>간단한 지도 표시하기</title>
5
+    <script type="text/javascript" src="https://openapi.map.naver.com/openapi/v3/maps.js?ncpClientId=o88z15l7bh"></script>
6
+</head>
7
+<body>
8
+<div id="map" style="width:100%;height:400px;"></div>
9
+
10
+<script>
11
+var mapOptions = {
12
+    center: new naver.maps.LatLng(35.8862487, 128.6023765),
13
+    zoom: 10
14
+};
15
+
16
+var map = new naver.maps.Map('map', mapOptions);
17
+
18
+var markerOptions = {
19
+    position: new naver.maps.LatLng(35.8862487, 128.6023765),
20
+    map: map
21
+};
22
+
23
+var marker = new naver.maps.Marker(markerOptions);
24
+
25
+var infoWindow = new naver.maps.InfoWindow({
26
+	content: '<div style="width:150px;text-align:center;padding:10px;">현 위치는 <b>대구</b>.</div>'
27
+});
28
+infoWindow.open(map, marker);
29
+
30
+</script>
31
+</body>
32
+</html>

+ 42
- 0
src/main/python/kr/co/swh/lecture/opensource/project/colona/templates/4-clicked-one-label.html ファイルの表示

@@ -0,0 +1,42 @@
1
+<html>
2
+<head>
3
+    <meta charset="UTF-8">
4
+    <title>간단한 지도 표시하기</title>
5
+    <script type="text/javascript" src="https://openapi.map.naver.com/openapi/v3/maps.js?ncpClientId=o88z15l7bh"></script>
6
+</head>
7
+<body>
8
+<div id="map" style="width:100%;height:400px;"></div>
9
+
10
+<script>
11
+var mapOptions = {
12
+    center: new naver.maps.LatLng(35.8862487, 128.6023765),
13
+    zoom: 10
14
+};
15
+var map = new naver.maps.Map('map', mapOptions);
16
+
17
+var markerOptions = {
18
+    position: new naver.maps.LatLng(35.8862487, 128.6023765),
19
+    map: map
20
+};
21
+var marker = new naver.maps.Marker(markerOptions);
22
+
23
+var infoWindow = new naver.maps.InfoWindow({
24
+	content: '<div style="width:150px;text-align:center;padding:10px;">현 위치는 <b>대구</b>.</div>'
25
+});
26
+// infoWindow.open(map, marker);
27
+
28
+//	클릭에 대한 이벤트
29
+function getClickHandler() {
30
+    return function(e) {
31
+        if (infoWindow.getMap()) {
32
+            infoWindow.close();
33
+        } else {
34
+            infoWindow.open(map, marker);
35
+        }
36
+    }
37
+}
38
+naver.maps.Event.addListener(marker, 'click', getClickHandler());
39
+
40
+</script>
41
+</body>
42
+</html>

+ 30
- 0
src/main/python/kr/co/swh/lecture/opensource/project/colona/templates/5-two-marker.html ファイルの表示

@@ -0,0 +1,30 @@
1
+<html>
2
+<head>
3
+    <meta charset="UTF-8">
4
+    <title>간단한 지도 표시하기</title>
5
+    <script type="text/javascript" src="https://openapi.map.naver.com/openapi/v3/maps.js?ncpClientId=o88z15l7bh"></script>
6
+</head>
7
+<body>
8
+<div id="map" style="width:100%;height:400px;"></div>
9
+
10
+<script>
11
+var mapOptions = {
12
+    center: new naver.maps.LatLng(35.8862487, 128.6023765),
13
+    zoom: 10
14
+};
15
+var map = new naver.maps.Map('map', mapOptions);
16
+
17
+var markerOptions = {
18
+    position: new naver.maps.LatLng(35.8862487, 128.6023765),
19
+    map: map
20
+};
21
+var marker = new naver.maps.Marker(markerOptions);
22
+
23
+var markerOptions = {
24
+    position: new naver.maps.LatLng(35.6862487, 128.6023765),
25
+    map: map
26
+};
27
+var marker = new naver.maps.Marker(markerOptions);
28
+</script>
29
+</body>
30
+</html>

+ 54
- 0
src/main/python/kr/co/swh/lecture/opensource/project/colona/templates/6-two-label.html ファイルの表示

@@ -0,0 +1,54 @@
1
+<html>
2
+<head>
3
+    <meta charset="UTF-8">
4
+    <title>간단한 지도 표시하기</title>
5
+    <script type="text/javascript" src="https://openapi.map.naver.com/openapi/v3/maps.js?ncpClientId=o88z15l7bh"></script>
6
+</head>
7
+<body>
8
+<div id="map" style="width:100%;height:700px;"></div>
9
+
10
+<script>
11
+//	맵 초기화
12
+var mapOptions = {
13
+    center: new naver.maps.LatLng(37.290932, 127.4531513),
14
+    zoom: 16
15
+};
16
+var map = new naver.maps.Map('map', mapOptions);
17
+
18
+//	데이터 초기화
19
+var datas = new Array();
20
+var data = {
21
+	name : 'SWH코딩',
22
+	loc : [37.2938133, 127.4558164]
23
+}
24
+datas.push(data);
25
+var data = {
26
+	name : '증포중',
27
+	loc : [37.287932, 127.4552513]
28
+}
29
+datas.push(data);
30
+
31
+//	데이터 출력용 샘플
32
+for (var i = 0; i < datas.length; i++) {
33
+	console.log(datas[i].loc);
34
+}
35
+
36
+for (var i = 0; i < datas.length; i++) {
37
+	//	이정표 등록
38
+	var markerOptions = {
39
+	    position: new naver.maps.LatLng(datas[i].loc[0], datas[i].loc[1]),
40
+	    map: map
41
+	};
42
+	var marker = new naver.maps.Marker(markerOptions);
43
+	
44
+	//	이정표 내용 등록
45
+	var infoWindow = new naver.maps.InfoWindow({
46
+		content: '<div style="width:150px;text-align:center;padding:10px;">현 위치는 <b>"'+ datas[i].name +'"</b>.</div>'
47
+	});
48
+	
49
+}
50
+//	어떻게 해야할까?? 알아서 진행~~!!
51
+//	네이버 맵 마커 이미지도 변경할 수 있도록 구글에 검색~!!!
52
+</script>
53
+</body>
54
+</html>

+ 68
- 0
src/main/python/kr/co/swh/lecture/opensource/project/colona/templates/final-corona-template.html ファイルの表示

@@ -0,0 +1,68 @@
1
+<html>
2
+<head>
3
+    <meta charset="UTF-8">
4
+    <title>간단한 지도 표시하기</title>
5
+    <script type="text/javascript" src="https://openapi.map.naver.com/openapi/v3/maps.js?ncpClientId=o88z15l7bh"></script>
6
+</head>
7
+<body>
8
+<div id="map" style="width:100%;height:700px;"></div>
9
+
10
+<script>
11
+//	맵 초기화
12
+var mapOptions = {
13
+    center: new naver.maps.LatLng(37.290932, 127.4531513),
14
+    zoom: 16
15
+};
16
+var map = new naver.maps.Map('map', mapOptions);
17
+
18
+//	데이터 초기화
19
+var datas = new Array();        
20
+var data = {
21
+	name : 'SWH코딩',
22
+	loc : [37.2938133, 127.4558164]
23
+}
24
+datas.push(data);
25
+var data = {
26
+	name : '증포중',
27
+	loc : [37.287932, 127.4552513]
28
+}
29
+datas.push(data);
30
+
31
+
32
+//	데이터 출력용 샘플
33
+for (var i = 0; i < datas.length; i++) {
34
+	console.log(datas[i].loc);
35
+}
36
+
37
+for (var i = 0; i < datas.length; i++) {
38
+	//	이정표 등록
39
+	var markerOptions = {
40
+	    position: new naver.maps.LatLng(datas[i].loc[0], datas[i].loc[1]),
41
+	    map: map
42
+	};
43
+	var marker = new naver.maps.Marker(markerOptions);
44
+	
45
+	//	이정표 내용 등록
46
+	var infoWindow = new naver.maps.InfoWindow({
47
+		content: '<div style="width:150px;text-align:center;padding:10px;">현 위치는 <b>"'+ datas[i].name +'"</b>.</div>'
48
+	});
49
+	
50
+	//	클릭에 대한 이벤트
51
+	naver.maps.Event.addListener(marker, 'click', getClickHandler(marker, infoWindow));
52
+}
53
+
54
+//	클릭에 대한 이벤트
55
+function getClickHandler(marker, infoWindow) {
56
+    return function(e) {
57
+        if (infoWindow.getMap()) {
58
+            infoWindow.close();
59
+        } else {
60
+            infoWindow.open(map, marker);
61
+        }
62
+    }
63
+}
64
+
65
+
66
+</script>
67
+</body>
68
+</html>

+ 80
- 0
src/main/python/kr/co/swh/lecture/opensource/project/colona/templates/final-corona.html ファイルの表示

@@ -0,0 +1,80 @@
1
+<html>
2
+<head>
3
+    <meta charset="UTF-8">
4
+    <title>간단한 지도 표시하기</title>
5
+    <script type="text/javascript" src="https://openapi.map.naver.com/openapi/v3/maps.js?ncpClientId=6msw8dshkf"></script>
6
+</head>
7
+<body>
8
+<div id="map" style="width:100%;height:700px;"></div>
9
+
10
+<script>
11
+//	맵 초기화
12
+var mapOptions = {
13
+    center: new naver.maps.LatLng(37.3595704, 127.105399),
14
+    zoom: 10
15
+};
16
+var map = new naver.maps.Map('map', mapOptions);
17
+
18
+
19
+//	데이터 초기화
20
+var datas = new Array();
21
+{% for value in values %}
22
+	var data = {
23
+		name : '{{ value.name }}',
24
+		loc : {{ value.loc }},
25
+		addr : '{{ value.addr }}',
26
+		remain_stat : '{{ value.remain_stat }}'
27
+	}
28
+	datas.push(data);
29
+{% endfor %}
30
+
31
+
32
+//	데이터 출력용 샘플
33
+//	for (var i = 0; i < datas.length; i++) {
34
+//		console.log(datas[i].loc);
35
+//	}
36
+
37
+for (var i = 0; i < datas.length; i++) {
38
+	//	이정표 등록
39
+	var markerOptions = {
40
+	    position: new naver.maps.LatLng(datas[i].loc[0], datas[i].loc[1]),
41
+	    map: map
42
+	};
43
+	var marker = new naver.maps.Marker(markerOptions);
44
+	
45
+	//	이정표 내용 등록
46
+	var infoWindow = new naver.maps.InfoWindow({
47
+		content: '<div style="width:150px;text-align:center;padding:10px;">현 위치는 <br><b>"'+ datas[i].name +'"</b>.<br>재고량 : "' + maskInfo(datas[i].remain_stat) +'"</div>'
48
+	});
49
+	
50
+	//	클릭에 대한 이벤트
51
+	naver.maps.Event.addListener(marker, 'click', getClickHandler(marker, infoWindow));
52
+}
53
+
54
+//	클릭에 대한 이벤트
55
+function getClickHandler(marker, infoWindow) {
56
+    return function(e) {
57
+        if (infoWindow.getMap()) {
58
+            infoWindow.close();
59
+        } else {
60
+            infoWindow.open(map, marker);
61
+        }
62
+    }
63
+}
64
+
65
+function maskInfo(value) {
66
+	if (value == "plenty") {
67
+		return "충분";
68
+    } else if (value == "some") {
69
+     	return "보통";
70
+    } else if (value == "few") {
71
+      	return "부족";
72
+    } else if (value == "empty") {
73
+      	return "품절";
74
+    } else {
75
+    	return "정보없음";
76
+    }
77
+}
78
+</script>
79
+</body>
80
+</html>