コード例 #1
0
def api(params):
    '''
    params : dict_key [name,start,finish,city]
    '''
    with open('./api_code/keys/calenderID.txt') as f:
        calenderID = f.read()  # Goto ID

    name = params['name']
    start = params['departure']
    finish = params['destination']

    # city parameters (緯度と経度)
    if params['city'] == '大阪':
        lat = '34.70'
        lon = '135.49'

    elif params['city'] == '東京':
        lat = '35.70'
        lon = '139.73'
    else:
        lat = '35.17'
        lon = '136.88'

    name = name + "さん"
    tdatetime, hour, minute, second = train_api(
        start, finish)  # tdatetime is date. others are str.
    weather = weather_api(lat, lon)
    # eventlist = []
    eventlist, startlist = calender_api(calenderID)  # list returned
    currenttime = datetime.datetime.now()
    u = tdatetime - currenttime

    tmp = u.seconds // 60

    # 発車時刻ちょうどに実行すると,tmpの結果が 24*60 - 1 分くらいになってしまう.
    # この時だけ除外する処理を行う.
    if tmp == 1439:
        print("やばい")
        tmp = 0
    tmp = str(tmp)

    train = hour + '時' + minute + '分' + 'に発車します。' + 'あと' + tmp + '分で発車します。'
    weather = '今日の' + params['city'] + 'の天気は' + weather + 'です。'

    if len(eventlist) == 0:
        schedule = '予定はありません.'
    else:
        schedule = '予定は' + eventlist[0] + 'があります。'

    # these lines will be deleted.
    print(name)
    print(train)
    print(weather)
    print(schedule)

    return name, train, weather, schedule
コード例 #2
0
def main():
    api = w_api.weather_api()

    while(1):
        code = input("Enter Airport Code\n")

        if(code.lower() == "exit"):
            break
        else:
            data = api.get_weather(code, 1)
            if data != -1:
                plot_data(data, code)
コード例 #3
0
ファイル: ca3.py プロジェクト: ethan-jay/ca3
def schedule_event():
    s.run(blocking=False)
    alarm_time = request.args.get("alarm")
    config = load_config()
    if alarm_time:
        #convert alarm_time to a delay
        alarm_title = request.args.get("two")
        current_time = datetime.now()
        alarm_time_obj = datetime.strptime(alarm_time, "%Y-%m-%dT%H:%M")
        delay = datetime_difference_seconds(alarm_time_obj, current_time)
        repeat = False
        for item in alarms:
            if item['title'] == alarm_title:
                repeat = True
        if delay > 0 and not repeat:
            scheduled_event = s.enter(int(delay),
                                      1,
                                      alarm_time_reached,
                                      argument=(
                                          alarms,
                                          s,
                                          request.args.get("two"),
                                      ))
            alarms.append({
                'title': alarm_title,
                'content': alarm_time_obj,
                'eventID': scheduled_event
            })
    if request.args.get("notif"):
        #removes notification when x is clicked
        delete_list_item(notifications, request.args.get("notif"), s, False)
    if request.args.get("alarm_item"):
        #cancels an alarm when x is clicked
        delete_list_item(alarms, request.args.get("alarm_item"), s, True)
    if request.args.get("news"):
        #runs news update
        news_dictionary = news_api(
            config[4],
            config[1])  #config[3] is country code, config[2] is newsapikey
        process_news_api(news_dictionary, notifications)
        covid_dictionary = covid19_api(config[2])
        process_covid19_api(covid_dictionary, notifications)
    if request.args.get("weather"):
        #runs weather update
        weather_dictionary = weather_api(
            config[3],
            config[0])  #config[0] is city, config [1] is weatherapikey
        process_weather_api(weather_dictionary, notifications)
    return render_template('index.html',
                           alarms=alarms,
                           notifications=notifications,
                           image='clock.jpeg')
コード例 #4
0
ファイル: api.py プロジェクト: Team-HSL/SmartSpeakDoor
def api(id):

    from train_api import train_api
    from calender_api import calender_api
    from weather_api import weather_api

    if id == 1:
        name = '後藤さん'
        via = '25717:25635'  # from出町柳to河原町
        lat = '35.01'  # 河原町緯度
        lon = '135.76'  # 河原町経度
        calenderID = '*****@*****.**'  # Goto ID

    elif id == 2:
        name = '村木くん'
        via = '25717:26238'  # from出町柳to淀屋橋
        lat = '34.69'  # 淀屋橋緯度
        lon = '135.50'  # 淀屋橋経度
        calenderID = '*****@*****.**'
    else:
        str = 'あなたは登録されていません。'

    tdatetime, hour, minute, second = train_api(
        via)  # tdatetime is date. others are str.
    weather = weather_api(lat, lon)
    eventlist, startlist = calender_api(calenderID)  # list returned

    train = hour + '時' + minute + '分' + 'に発車します。'
    weather = '今日は' + weather + 'です。'
    schedule = '予定は' + eventlist[0] + 'が近いです。'

    # these lines will be deleted.
    print(name)
    print(train)
    print(weather)
    print(schedule)

    return name, train, weather, schedule
コード例 #5
0
def test_wrong_iata_input():
    api = weather_api.weather_api()
    assert api.get_weather("wjwkw", 0) == -1
    assert api.get_weather("wjwkw", 1) == -1
コード例 #6
0
def test_num_input():
    api = weather_api.weather_api()
    assert api.get_weather("1353", 0) == -1
    assert api.get_weather("1353", 1) == -1
コード例 #7
0
def test_symbol_input():
    api = weather_api.weather_api()
    assert api.get_weather("^sj", 0) == -1
    assert api.get_weather("^sj", 1) == -1
コード例 #8
0
def test_nonexistant_iata():
    api = weather_api.weather_api()
    assert api.get_weather("itv", 0) == -1
    assert api.get_weather("itv", 1) == -1