File size: 2,224 Bytes
769e684
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import os

import requests


def test_law():
    oc = os.getenv("LAW_GO_KR_OC")
    url = f"http://www.law.go.kr/DRF/lawSearch.do?target=law&query=๋ฏผ์›&type=XML&OC={oc}"
    try:
        res = requests.get(url, timeout=10)
        print(f"[LAW] Status: {res.status_code}")
        if "์‚ฌ์šฉ์ž ์ •๋ณด ๊ฒ€์ฆ์— ์‹คํŒจ" in res.text:
            print("[LAW] โŒ IP ๋ฏธ์Šน์ธ ์ƒํƒœ (๋“ฑ๋กํ•œ IP๊ฐ€ ๋ฐ˜์˜๋˜์ง€ ์•Š์•˜๊ฑฐ๋‚˜ ๋‹ค๋ฆ„)")
        elif "<law" in res.text:
            print("[LAW] โœ… ์ธ์ฆ ์„ฑ๊ณต! ๋ฐ์ดํ„ฐ ์ˆ˜์ง‘ ๊ฐ€๋Šฅ")
        else:
            print(f"[LAW] โš ๏ธ ์‘๋‹ต ํ™•์ธ ํ•„์š” (๋‚ด์šฉ ์ผ๋ถ€): {res.text[:200]}")
    except Exception as e:
        print(f"[LAW] โŒ ์—๋Ÿฌ: {e}")


def test_alio():
    key = os.getenv("DATA_GO_KR_API_KEY")
    # Decoding ํ‚ค ์‚ฌ์šฉ
    url = "https://apis.data.go.kr/1051000/public_inst/list"
    params = {"serviceKey": key, "pageNo": 1, "numOfRows": 1, "resultType": "json"}
    try:
        res = requests.get(url, params=params, timeout=10)
        print(f"[ALIO] Status: {res.status_code}")
        if res.status_code == 200:
            if "SERVICE_KEY_IS_NOT_REGISTERED" in res.text:
                print("[ALIO] โŒ ํ‚ค ๋ฏธํ™œ์„ฑ ์ƒํƒœ (๋™๊ธฐํ™” ๋Œ€๊ธฐ ์ค‘)")
            elif "INVALID_REQUEST_PARAMETER_ERROR" in res.text:
                print("[ALIO] โŒ ํŒŒ๋ผ๋ฏธํ„ฐ ์˜ค๋ฅ˜")
            else:
                try:
                    data = res.json()
                    # ๊ฒฐ๊ณผ ์ฝ”๋“œ ํ™•์ธ
                    res_code = data.get("response", {}).get("header", {}).get("resultCode")
                    if res_code == "00":
                        print("[ALIO] โœ… ์ธ์ฆ ์„ฑ๊ณต! ๋ฐ์ดํ„ฐ ์ˆ˜์ง‘ ๊ฐ€๋Šฅ")
                    else:
                        print(f"[ALIO] โŒ ๊ฒฐ๊ณผ ์˜ค๋ฅ˜ (์ฝ”๋“œ: {res_code})")
                except:
                    print(f"[ALIO] โš ๏ธ ๋น„์ •์ƒ ์‘๋‹ต (๋‚ด์šฉ ์ผ๋ถ€): {res.text[:200]}")
        else:
            print(f"[ALIO] โŒ HTTP ์˜ค๋ฅ˜: {res.status_code}")
    except Exception as e:
        print(f"[ALIO] โŒ ์—ฐ๊ฒฐ ์—๋Ÿฌ: {e}")


if __name__ == "__main__":
    print("-" * 50)
    print("๐Ÿš€ API ์ตœ์ข… ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ์‹œ์ž‘")
    test_law()
    test_alio()
    print("-" * 50)