# %% import os import sys import numpy as np import pandas as pd import requests import urllib.request import json from pykml import parser import warnings warnings.filterwarnings("ignore") def POHANG_cctv_info() : url_0 = 'https://utis.pohang.go.kr/api/traffic/cctv-list' headers = {'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36'} html_0 = requests.post(url_0, verify = False, headers=headers) str_0 = json.loads(html_0.text) cctv_info = [] for idx, j in enumerate(str_0) : cctv_info.append(j) #print(idx + 1, j) df_1 = pd.DataFrame(cctv_info) df_2 = df_1[['istl_lctn_nm', 'istl_lctn_addr', 'strm_http_addr']] df_2.columns = ['CCTV_LOCA', 'CCTV_ADDR', 'CCTV_HLS'] df_2 = df_2.sort_values(by = 'CCTV_LOCA') df_2['CCTV_ADDR'] = df_2['CCTV_ADDR'].apply(lambda x : x.replace("경북", "") if isinstance(x, str) else x) df_2['CCTV_ADDR'] = df_2['CCTV_ADDR'].apply(lambda x : x.replace("포항시", "") if isinstance(x, str) else x) df_2['CCTV_ADDR'] = df_2['CCTV_ADDR'].apply(lambda x : x.replace("포항", "") if isinstance(x, str) else x) df_2['CCTV_ADDR'] = df_2['CCTV_ADDR'].apply(lambda x : x.strip() if isinstance(x, str) else x) df_2['CCTV_ADDR'] = df_2['CCTV_ADDR'].apply(lambda x : "경북 포항시 " + x if isinstance(x, str) else x) return df_2 df = POHANG_cctv_info() html_head = """

    Go Parent

""" html_tail = """
""" html_body = "" str_1 = "" str_1 += """\n""" for i in df.index : try : str_1 += " \n" except : pass str_1 += """\n
    " + df.loc[i, 'CCTV_LOCA'] + "" + df.loc[i, 'CCTV_ADDR'] + "
""" html_body += str_1 html_full = html_head + html_body + html_tail output_name = os.path.join(os.getcwd(), 'pohang_cctv_live.htm') with open(output_name, 'w', encoding = 'utf-8-sig') as f : f.write(html_full) print("-" * 50) print("Webcast Page generated : " + output_name)