get_level.py 1.06 KB
import requests
from urllib import parse
import pymysql
def insert_table(name,level):
    conn = pymysql.connect(host='localhost', user='root', password="!!fnsldkwjsrl11", db="project_troll", charset='utf8')
    try:
        with conn.cursor() as curs:
            sql = 'insert into user_info values(%s, %s)'
            curs.execute(sql, (name, level))
        conn.commit()
    finally:
        conn.close()
APIKEY="RGAPI-dd27bd34-ec78-4c30-8c11-5144d7ec85e5"
headers={
     "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36",
    "Accept-Language": "ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7",
    "Accept-Charset": "application/x-www-form-urlencoded; charset=UTF-8",
    "Origin": "https://developer.riotgames.com",
    "X-Riot-Token": APIKEY
     }
def user_level(name):
    API="https://kr.api.riotgames.com/lol/summoner/v4/summoners/by-name/" + name
    getAPI=requests.get(API, headers=headers)
    apidata=getAPI.json()
    insert_table(name,apidata["summonerLevel"])
    return apidata["summonerLevel"]