Showing
1 changed file
with
125 additions
and
0 deletions
app.js
0 → 100644
1 | +var request = require("request"); | ||
2 | +var express = require('express'); | ||
3 | +var puuid_url_list=[] | ||
4 | +var events=require('events') | ||
5 | +var key = "RGAPI-78e43419-9016-45e3-8300-1e5febc8ef54" // LOL API key | ||
6 | +var app = express(); | ||
7 | +var eventEmitter=new events.EventEmitter(); | ||
8 | +var bodyParser = require('body-parser'); | ||
9 | +let puuid | ||
10 | +let option | ||
11 | +let checking=1 | ||
12 | +app.use(bodyParser.urlencoded({ extended: false })); | ||
13 | +app.use(bodyParser.json()); | ||
14 | +var name_list=[] // 유저의 아이디와 매칭되는 고유번호 | ||
15 | +var puuid_list=[] // puuid 저장을 위한 리스트 | ||
16 | + | ||
17 | + | ||
18 | +app.get('/', function (req, res) { | ||
19 | + res.send("My galaxy") // 버튼 구현 (은하계(맵) 으로 이루어진 버튼들) => 버튼 클릭시 해당 url로 get 하여 데이터 획득 | ||
20 | +}); | ||
21 | + | ||
22 | + | ||
23 | +app.get('/galaxy',function(req,res) | ||
24 | +{ | ||
25 | + name_url="https://kr.api.riotgames.com/tft/league/v1/challenger?api_key="+key | ||
26 | + | ||
27 | + request(name_url,function(err,res,body) | ||
28 | + { | ||
29 | + let json = JSON.parse(body) //json으로 파싱 | ||
30 | + var name=json['entries'] | ||
31 | + for (var value in name) | ||
32 | + { | ||
33 | + name_list.push(name[value]["summonerId"]) | ||
34 | + | ||
35 | + } | ||
36 | + eventEmitter.emit('name_done') | ||
37 | + }); //request1 END | ||
38 | + | ||
39 | + | ||
40 | + eventEmitter.on('name_done',function() //url 설정 | ||
41 | + { | ||
42 | + | ||
43 | + for (i=0;i<name_list.length;i++) | ||
44 | + { | ||
45 | + puuid_url_list.push("https://kr.api.riotgames.com/tft/summoner/v1/summoners/"+name_list[i]) | ||
46 | + | ||
47 | + } | ||
48 | + eventEmitter.emit("setting_done") | ||
49 | +});//setting end | ||
50 | + | ||
51 | + | ||
52 | + eventEmitter.on("setting_done",function() //puuid 가져오기 | ||
53 | + { | ||
54 | + if (checking==1) | ||
55 | + { | ||
56 | + option={ | ||
57 | + url:puuid_url_list[0], | ||
58 | + method: 'GET', | ||
59 | + headers:{ | ||
60 | + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36", | ||
61 | + "Accept-Language": "ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7", | ||
62 | + "Accept-Charset": "application/x-www-form-urlencoded; charset=UTF-8", | ||
63 | + "Origin": "https://developer.riotgames.com", | ||
64 | + "X-Riot-Token": key} | ||
65 | + } | ||
66 | + eventEmitter.emit("run_request") //for 문 마다 run_request를 한다. | ||
67 | + | ||
68 | + } | ||
69 | + else | ||
70 | + { | ||
71 | + | ||
72 | + for (i=1;i<name_list.length;i++) | ||
73 | + { | ||
74 | + eventEmitter.emit("run_request") | ||
75 | + eventEmitter.on('run_request2',function(){ | ||
76 | + option={ | ||
77 | + url:puuid_url_list[i], | ||
78 | + method: 'GET', | ||
79 | + headers:{ | ||
80 | + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36", | ||
81 | + "Accept-Language": "ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7", | ||
82 | + "Accept-Charset": "application/x-www-form-urlencoded; charset=UTF-8", | ||
83 | + "Origin": "https://developer.riotgames.com", | ||
84 | + "X-Riot-Token": key} | ||
85 | + } | ||
86 | + //for 문 마다 run_request를 한다. | ||
87 | + }); | ||
88 | + } | ||
89 | +} | ||
90 | + eventEmitter.emit('data_received') | ||
91 | + | ||
92 | + });//event-setting done end | ||
93 | + | ||
94 | +eventEmitter.on('run_request',function()//자료 가져오기 (puuid) | ||
95 | +{ | ||
96 | + request(option,function(err,res,body) | ||
97 | + | ||
98 | + { | ||
99 | + puuid = JSON.parse(body) | ||
100 | + puuid=puuid["puuid"] | ||
101 | + puuid_list.push(puuid) | ||
102 | + if (checking==1) | ||
103 | + { | ||
104 | + checking=2 | ||
105 | + eventEmitter.emit("setting_done") | ||
106 | + | ||
107 | + | ||
108 | + } | ||
109 | + else | ||
110 | + { | ||
111 | + eventEmitter.emit("run_request2") | ||
112 | + } | ||
113 | + | ||
114 | + }); | ||
115 | +}); //run_request end | ||
116 | + | ||
117 | + | ||
118 | +});// app end | ||
119 | + | ||
120 | + | ||
121 | +var server = app.listen(80); | ||
122 | +eventEmitter.on('data_received',function(){ | ||
123 | + console.log(name_list); | ||
124 | + console.log(puuid_list) | ||
125 | +}); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment