Beispiel #1
0
def clock(event):
    if event.message.text == '打卡':
        try:
            user_id = event.source.user_id
            timestamp = event.timestamp
            date_time = Methods.Timestamp_Datetime(timestamp)
            data = My_SQL.DB.select_profile(user_id)

            if data:
                user_name = data[0][1]
                user_info = data[0][3]
                user_image = data[0][4]

                contents = Flex_Message.simulator(user_image, user_name,
                                                  user_info, date_time)

                line_bot_api.reply_message(
                    event.reply_token,
                    FlexSendMessage(alt_text='說明文字', contents=contents))
            else:
                line_bot_api.reply_message(event.reply_token,
                                           TextSendMessage('你是誰??先去報到'))
        except Exception as msg:
            print(msg)
        return True
    else:
        return False
Beispiel #2
0
def batch_record(event):
    if event.message.text == 'batch':
        try:
            reply = '權限不足'
            if access_right(event.source.user_id):
                timestamp = event.timestamp
                date_time = Methods.Timestamp_Datetime(timestamp)
                editor = event.source.user_id
                df = Google_API.Batch_import()
                c = 0
                for location in df.values.tolist():
                    location = location[0]
                    lat, lng, address = Google_API.get_GC(location)
                    if lat != None:
                        My_SQL.DB.insert_data(date_time, location, address,
                                              lat, lng, editor)
                        c += 1
                reply = '成功匯入{}筆資料'.format(c)
            line_bot_api.reply_message(event.reply_token,
                                       TextSendMessage(reply))
        except Exception as msg:
            print(msg)
        return True
    else:
        return False
Beispiel #3
0
def upload_image_message(event):
    user_id = event.source.user_id
    timestamp = event.timestamp
    message_content = line_bot_api.get_message_content(event.message.id)
    try:
        link = Methods.imgur(message_content, timestamp)
        reply = My_SQL.DB.update_image(link, user_id)
        line_bot_api.reply_message(event.reply_token, TextSendMessage(reply))
    except Exception as msg:
        print(msg)
Beispiel #4
0
def handle_postback(event):
    user_id = event.source.user_id
    timestamp = event.timestamp
    time_is = Methods.Timestamp_Datetime(timestamp)

    if event.postback.data == 'clock_in':
        reply = clock_in(user_id, time_is)

    elif event.postback.data == 'clock_out':
        reply = clock_out(user_id, time_is)

    line_bot_api.reply_message(event.reply_token, TextSendMessage(text=reply))
Beispiel #5
0
def handle_location_message(event):
    #weathermap
    latitude = event.message.latitude
    longitude = event.message.longitude
    img_url = Methods.openweathermap(latitude, longitude)
    line_bot_api.reply_message(
        event.reply_token,
        ImageSendMessage(original_content_url=img_url,
                         preview_image_url=img_url))
    #nearby
    user_id = event.source.user_id
    lat_d, lat_u, lon_d, lon_u = Methods.select_range(latitude, longitude)
    df = My_SQL.DB.select_nearby(lat_d, lat_u, lon_d, lon_u)
    Title, Address, Latitude, Longitude, Cluster = Methods.nearest(
        df, latitude, longitude)
    if Address != None:
        line_bot_api.push_message(
            user_id,
            LocationSendMessage(title=Title + Cluster,
                                address=Address,
                                latitude=float(Latitude),
                                longitude=float(Longitude)))
    else:
        line_bot_api.push_message(user_id, TextSendMessage(text=Title))
Beispiel #6
0
def insert_record(event):
    if '@' in event.message.text:
        try:
            timestamp = event.timestamp
            date_time = Methods.Timestamp_Datetime(timestamp)
            location = event.message.text.strip('@')
            lat, lng, address = Google_API.get_GC(location)
            editor = event.source.user_id
            if lat != None:
                reply = My_SQL.DB.insert_data(date_time, location, address,
                                              lat, lng, editor)
            else:
                reply = '請輸入正確地標或地址'
            line_bot_api.reply_message(event.reply_token,
                                       TextSendMessage(reply))
        except Exception as msg:
            print(msg)
        return True
    else:
        return False
Beispiel #7
0
def get_cluster(event):
    if event.message.text == "cluster":
        try:
            reply = '權限不足'
            if access_right(event.source.user_id):
                df = My_SQL.DB.get_df()
                list_Coordinate = df[["Latitude", "Longitude"]].values.tolist()
                clusters = Methods.clustering(list_Coordinate)
                df["Cluster"] = clusters
                reply = My_SQL.DB.insert_cluster(df[["Location", "Cluster"
                                                     ]].values.tolist())
                My_SQL.DB.append()
                My_SQL.DB.truncate('calculation')
            line_bot_api.reply_message(event.reply_token,
                                       TextSendMessage(reply))
        except Exception as msg:
            print(msg)
        return True
    else:
        return False
Beispiel #8
0
def completed_record(event):
    if '#' in event.message.text:
        try:
            timestamp = event.timestamp
            Completion = Methods.Timestamp_Datetime(timestamp)
            Labor = event.source.user_id
            Location = event.message.text.strip('#')
            access = clocked(Labor, Completion)
            if access:
                reply = My_SQL.DB.mission_completed(Location, Labor,
                                                    Completion)
            else:
                reply = '先去打卡喔!'
            line_bot_api.reply_message(event.reply_token,
                                       TextSendMessage(reply))
        except Exception as msg:
            print(msg)
        return True
    else:
        return False
Beispiel #9
0
def group(event):
    if "group" in event.message.text:
        try:
            group_name = event.message.text.strip('group')
            data = My_SQL.DB.group_members(group_name)
            if len(data) != 0:
                Text, Url = Google_API.static_map(data)
                Url = Methods.reurl(Url)
            else:
                Text = 'Not Exists'
                Url = 'https://reurl.cc/2b7k7E'
            line_bot_api.reply_message(
                event.reply_token,
                TextSendMessage(
                    text=Text,
                    quick_reply=QuickReply(items=[
                        QuickReplyButton(
                            action=URIAction(label="Static Map", uri=Url))
                    ])))
        except Exception as msg:
            print(msg)
        return True
    else:
        return False