import requests
import csv

url = 'http://data.tycg.gov.tw/api/v1/rest/datastore/a1b4714b-3b75-4ff8-a8f2-cc377e4eaa0f?format=csv'

resp = requests.get(url)

if resp.status_code == 200:
    rows = resp.text.splitlines()
    data = list(csv.reader(rows))
    
    while True:
        user = input('請輸入要搜尋的Youbike站台: ')

        total = 0
        for t in data:
            if user in t[3]:
                total += 1   
                print(f'站台: {t[3]}, 地址: {t[6]}')
                print(f'  -可借: {t[12]}')
                print(f'  -可還: {t[5]}')
                print(f'  -總數: {t[10]}')
                print()
        if total == 0:
            print('查無該站台')
            continue
        else:
            print(f'共{total}站')
            break
    else:
        print('無法取得資料')