import os
import json as js
from bs4 import BeautifulSoup as bs
import requests as req
import tkinter as tk
import sys
import random
import time
Initial Setting
path = os.path.dirname(file)
os.makedirs('db', exist_ok=True)
os.makedirs('local', exist_ok=True)
modoru = ['hoge', 'hoge', 'hoge']
def modoru():
if not modoru:
return
tel_len = 0
while not(10 == tel_len or 11 == tel_len):
#print("Please enter a telephone number. (Without -)")
tel = modoru
tel_len = len(tel)
if 10 == tel_len:
tel_db = tel[1]
tel_db_key = tel[0:6]
tel_db_path = str(path) + "/db/tnum-" + tel_db + ".json"
file_01 = open(tel_db_path, encoding='utf-8')
tel_db_j = js.load(file_01)
tel_left = tel_db_j[tel_db_key]["TNout"]
tel_center = tel_db_j[tel_db_key]["TNins"]
tel_location = tel_db_j[tel_db_key]["Location"]
tel_right = tel[6:10]
if 11 == tel_len:
tel_left = tel[0:3]
tel_center = tel[3:7]
tel_right = tel[7:11]
tel_location = "Unknown"
url = "numberinfo_" + tel_left + "" + tel_center + "" + tel_right + ".html"
# print( "\n" + tel_left + "-" + tel_center + "-" + tel_right + "について情報を検索中...")
# print("発信: " + tel_location + "\n" )
# Collecting html = open( str(path) + '/local/' + url,encoding='utf-8') # Parsing pars = bs(html, 'html.parser') data_who = "" data_how = "" data_location = "" data_raw_detail = pars.find_all('td', class_ = 'autonewline') data_raw_detail_len = len(data_raw_detail) if 0 < data_raw_detail_len: data_who = data_raw_detail[0].text data_how = data_raw_detail[1].text data_location = data_raw_detail[2].text print("名称: " + data_who) print("業種: " + data_how) print("住所: " + data_location) root = tk.Tk() label1 = tk.Label(root, text="番号:" + tel_left + "-" + tel_center + "-" + tel_right, font=("",20)) label1.place(x=0,y=0) label2 = tk.Label(root, text="名称:" + data_who , font=("",20)) label2.place(x=100,y=100) label3 = tk.Label(root, text="業種:" + data_how , font=("",20)) label3.place(x=200,y=200) label4 = tk.Label(root, text="住所:" + data_location , font=("",20)) label4.place(x=300,y=300) root.after(1000, modoru) root.mainloop()
あなたの回答
tips
プレビュー