Showing
1 changed file
with
0 additions
and
123 deletions
app.js
deleted
100644 → 0
1 | -var request = require("request"); | ||
2 | -var express = require('express'); | ||
3 | -var fs=require('fs'); | ||
4 | -var puuid_url_list=[] | ||
5 | -var events=require('events') | ||
6 | -var key = "RGAPI-82f68b2b-8db9-4b3d-951a-7684fbb49a4c" // LOL API key | ||
7 | -var app = express(); | ||
8 | -var eventEmitter=new events.EventEmitter(); | ||
9 | -var bodyParser = require('body-parser'); | ||
10 | -let puuid | ||
11 | -let option | ||
12 | -app.use(bodyParser.urlencoded({ extended: false })); | ||
13 | -app.use(bodyParser.json()); | ||
14 | -var name_list=[] // 유저의 아이디와 매칭되는 고유번호 | ||
15 | -var puuid_list=[] // puuid 저장을 위한 리스트 | ||
16 | -eventEmitter.setMaxListeners(200) | ||
17 | - | ||
18 | - | ||
19 | - | ||
20 | - | ||
21 | -app.get('/', function (req, res) { | ||
22 | - | ||
23 | - }); | ||
24 | - // 버튼 구현 (은하계(맵) 으로 이루어진 버튼들) => 버튼 클릭시 해당 url로 get 하여 데이터 획득 | ||
25 | - | ||
26 | - | ||
27 | -app.get('/galaxy',function(req,res) | ||
28 | -{ | ||
29 | - name_url="https://kr.api.riotgames.com/tft/league/v1/challenger?api_key="+key | ||
30 | - | ||
31 | - request(name_url,function(err,res,body) | ||
32 | - { | ||
33 | - let json = JSON.parse(body) //json으로 파싱 | ||
34 | - var name=json['entries'] | ||
35 | - for (var value in name) | ||
36 | - { | ||
37 | - name_list.push(name[value]["summonerId"]) | ||
38 | - console.log(name_list.length) | ||
39 | - | ||
40 | - if(name_list.length==200) | ||
41 | - { | ||
42 | - eventEmitter.emit('name_done') | ||
43 | - console.log("!") | ||
44 | - } | ||
45 | - } | ||
46 | - }); //request1 END | ||
47 | - | ||
48 | - eventEmitter.on("name_done",function() | ||
49 | - { | ||
50 | - console.log(name_list.length) | ||
51 | - for (i=0; i<name_list.length;i++) | ||
52 | - { | ||
53 | - console.log("https://kr.api.riotgames.com/tft/summoner/v1/summoners/"+name_list[i]) | ||
54 | - puuid_url_list.push("https://kr.api.riotgames.com/tft/summoner/v1/summoners/"+name_list[i]) | ||
55 | - console.log(puuid_url_list) | ||
56 | - if (puuid_url_list.length==200) | ||
57 | - { | ||
58 | - eventEmitter.emit("puuid_url_done") | ||
59 | - break | ||
60 | - } | ||
61 | - } | ||
62 | - | ||
63 | - });//name_done => puuid_url 설정 완료 | ||
64 | - | ||
65 | - eventEmitter.on("puuid_url_done",function(){ //puuid 가져오기 | ||
66 | - console.log(puuid_url_list) | ||
67 | - function delay(option) { | ||
68 | - return new Promise(resolve => //option=> request hedear 가 설정되기 전에 request를 해버리는 문제 해결하기위해 promise 사용 | ||
69 | - setTimeout(() => { | ||
70 | - request(option,function(err,res,body) | ||
71 | - { | ||
72 | - | ||
73 | - puuid = JSON.parse(body) | ||
74 | - console.log(puuid) | ||
75 | - puuid=puuid["puuid"] | ||
76 | - puuid_list.push(puuid) | ||
77 | - console.log(puuid_list) | ||
78 | - console.log(puuid_list.length) | ||
79 | - if(puuid_list.length==200) //puuid 를 100개는 잘가져오고 100개는 못가져오는 문제 생김 | ||
80 | - { | ||
81 | - eventEmitter.emit("puuid_find_done") | ||
82 | - } | ||
83 | - }); | ||
84 | - resolve(); },400) ); | ||
85 | - } | ||
86 | - | ||
87 | - async function loop(puuid_url_list) { | ||
88 | - | ||
89 | - { | ||
90 | - for (i=0;i<puuid_url_list.length;i++) | ||
91 | - { | ||
92 | - | ||
93 | - option={ | ||
94 | - url:puuid_url_list[i], //url 값 설정은 확인 완료 | ||
95 | - method: 'GET', | ||
96 | - headers:{ | ||
97 | - "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", | ||
98 | - "Accept-Language": "ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7", | ||
99 | - "Accept-Charset": "application/x-www-form-urlencoded; charset=UTF-8", | ||
100 | - "Origin": "https://developer.riotgames.com", | ||
101 | - "X-Riot-Token": key} | ||
102 | - } | ||
103 | - | ||
104 | - | ||
105 | - await delay(option); | ||
106 | - | ||
107 | - } | ||
108 | - } | ||
109 | - | ||
110 | - } | ||
111 | - loop(puuid_url_list); | ||
112 | - }); | ||
113 | - | ||
114 | - eventEmitter.on("puuid_find_done",function(){ | ||
115 | - | ||
116 | - res.send(puuid_list) | ||
117 | - }); | ||
118 | - | ||
119 | -});// app end | ||
120 | - | ||
121 | - | ||
122 | -var server = app.listen(80); | ||
123 | -console.log("run!") |
-
Please register or login to post a comment