diff --git a/.gitignore b/.gitignore index c66c576..4a28035 100644 --- a/.gitignore +++ b/.gitignore @@ -129,3 +129,6 @@ dmypy.json .pyre/ /.idea +.vscode/settings.json +input +output diff --git a/ReadMe.md b/ReadMe.md new file mode 100644 index 0000000..23dcb79 --- /dev/null +++ b/ReadMe.md @@ -0,0 +1,21 @@ +# sendIPの使い方 +## ファイルを実行 +`python3 /home/pi/demo_python/sendIP.py` +*** +## raspberrypi起動時にファイルが自動実行 +### /etc/rc.localにプログラムファイルの実行を追記 +``` +#!/bin/sh -e +... + +# Line Notify +su pi -c "/home/pi/demo_python/sendIP.py" & + +exit 0 +``` +* `su pi`とは、ユーザーpiでコマンドを実行する。 +* `-c`とは、コマンドを実行した後に、元のユーザーに戻ります。 +## raspberry pi3のconfigを設定する +1. `sudo raspi-config`コマンドでconfigを開く。 +2. `System Options > Network at Boot`を選択する。 +3. `sudo reboot`で再起動する。 diff --git a/sendIP.py b/sendIP.py new file mode 100755 index 0000000..207436d --- /dev/null +++ b/sendIP.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +# Copyright (c) 2022. 楊鵬. All Rights Reserved. +import os +import socket + +import requests +from dotenv import load_dotenv + +load_dotenv() +URL = "https://notify-api.line.me/api/notify" + + +def sendIP(ip: str): + headers = {"Authorization": "Bearer " + os.environ["TOKEN"]} + params = {"message": ip} + r = requests.post(URL, headers=headers, params=params) + print(r.text) + + +if __name__ == "__main__": + connect_interface = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + connect_interface.connect(("8.8.8.8", 80)) + ip_addr = connect_interface.getsockname()[0] + connect_interface.close() + message = f"IP Address: {ip_addr}" + sendIP(message) diff --git a/txtToCsv.py b/txtToCsv.py old mode 100644 new mode 100755 index bc402b9..7bf0549 --- a/txtToCsv.py +++ b/txtToCsv.py @@ -1,4 +1,5 @@ -# Copyright (c) 2021. 楊鵬. All Rights Reserved. +#!/usr/bin/env python3 +# Copyright (c) 2023. 楊鵬. All Rights Reserved. from datetime import datetime import sys @@ -97,7 +98,7 @@ def create_data_from_file(file_name, keyword, device_code): data_json = {'TIME': []} keys = [] i = 0 - index = KEYWORD_LIST.index(keyword); + index = KEYWORD_LIST.index(keyword) if index == -1: print('can not found keyword from file name...') @@ -112,7 +113,7 @@ def create_data_from_file(file_name, keyword, device_code): if (key == 'ABS_MT_PRESSURE' and row[VALUE_FROM:VALUE_TO] == '00000000') or ( key == 'ABS_MT_TRACKING_ID' and row[VALUE_FROM:VALUE_TO] == 'ffffffff'): continue - data_json['TIME'].append(str.strip(row[TIMESTAMP_FROM:TIMESTAMP_TO])) + # 生データに項目名及び順番を取得 if not (key in keys): keys.append(key) @@ -141,6 +142,7 @@ def create_data_from_file(file_name, keyword, device_code): i += 1 if i == len(keys) and key == EVENT_STOP_FLAG: + data_json['TIME'].append(str.strip(row[TIMESTAMP_FROM:TIMESTAMP_TO])) i = 0 if len(keys) == 0: print('device_code:', device_code, 'is missed...') @@ -168,7 +170,7 @@ def data_convert(data_json, keys, user_id): # 行データ row_data = [] rows = [] - max_len = 0; + max_len = 0 for i in range(event_count_all): event_count_in_row += 1 for col in COLUMNS: