Open roberthsu2003 opened 1 month ago
import requests
from pprint import pprint
url='https://data.ntpc.gov.tw/api/datasets/010e5b15-3823-4b20-b401-b1cf000550c5/json?size=1000'
response=requests.get(url)
for i in range (1,1000,1):
bruh:list[dict] = response.json()[i] #response 是實體 .json是方法
print(bruh)
a=input('請輸入新北市行政區')
for i in range (1,1000,1):
bruh:list[dict] = response.json()[i] #response 是實體 .json是方法
if bruh['sarea']==a:
print(bruh)
import requests
from pprint import pprint
youbike_url = 'https://data.ntpc.gov.tw/api/datasets/010e5b15-3823-4b20-b401-b1cf000550c5/json?size=1000'
response = requests.get(youbike_url)
data = response.json()
district = input("請輸入新北市行政區: ")
district = district + "區"
district_stations = []
for station in data:
if station['sarea'] == district:
district_stations.append(station)
if district_stations:
pprint(district_stations)
else:
print(f"沒有找到 {district} 行政區的站點資訊。請再輸入一次")
import requests
from pprint import pprint
import pyinputplus as pyip
youbike_url = 'https://data.ntpc.gov.tw/api/datasets/010e5b15-3823-4b20-b401-b1cf000550c5/json?size=1000'
response = requests.get(youbike_url)
records:list[dict] = response.json()
area = pyip.inputStr("請輸入行政區(輸入須打出區):")
print(area,"\n")
stations = []
for record in records:
if record['sarea'] == area:
stations.append(record)
try:
if stations:
pprint(stations)
else:
raise NameError("沒有這個區")
except Exception as error:
print(error)
from os.path import abspath,dirname,join
import json
from pprint import pprint
import requests # type: ignore
file_path=join(dirname(abspath(__name__)),'data','新北市公共自行車租賃系統(YouBike)_export.json')
file_path
with open(file_path,encoding='utf-8',newline='') as file:
content=json.load(file)
url='https://data.ntpc.gov.tw/api/datasets/010e5b15-3823-4b20-b401-b1cf000550c5/json?size=1000'
response=requests.get(url)
records= response.json()
h =input("請輸入行政區(區)")
man=[]
for recode in records:
if recode['sarea']==h:
man.append(recode)
pprint(man)