The visitors flow python program that handle data processing and storing.
This project is including two program. Upload and Calling API.
create a new file named config.py
host = "Your host IP"
user = "your db user name"
password = "your db password"
db = "your db name"
api_id = 12345 # your telegram app api id
api_hash = 'xxxxxx' # your telegram app api hash
phone_number = '+886012312312' # your telegram phone number
socketServer = 'localhost' # your socket server IP
$ pip install -r requirements.txt
$ python uploadData.py [folder path]
Note: It may requests telegram Auth code, just enter it and go on.
排程每五分鐘執行 callAPI.py,程式會自行計算資料並 POST 資料至官方 API 位址
Note: 請注意執行程式的 IP 必須為官方已解鎖之 IP
$ python callAPI.py
- Watching on folder
- if the new json come in, handle it.
- Store the content of the json into database
- Use telegram to send a message if errors occur
程式執行時開始計時,有新檔案進入受監視資料夾時計時歸零,否則當計時超過指定時間(ex: 一分鐘)即以 telegram 依下列訊息進行通知
已經一分鐘沒有資料了,快去查看一下吧 [ recorded time ]
Note: 若是 json 內容為空陣列 [ ],程式會忽略不存入資料庫並且印出以下訊息
空資料...[ time ]
- getting data from SQL by start time (today morning) and end time (current time).
- calculate the request data format of the API.
- calling API to post the output data
Note: 取資料喂當日起始時間 00:00:00 及當下時間做為起始時間及結束時間,但是輸出的統計起始時間及統計結束時間為以下定義:
- 統計起始時間:傳回資料的第一筆資料的時間(已照時間排序)
- 統計結束時間:傳回資料的最後一筆資料的時間
在 Windows 上面執行此程式可能會遇到解析 json 檔後印出內容時的編碼問題
此時將 ==line 91== 的內容替換成下列程式碼
res.encoding = 'utf-8-sig'
[
{
"SSID":"SS-007",
"TagType":"Count",
"TagID":"901",
"TagValue":"56",
"StartTime":"20180531101825",
"EndTime":"20180531102825"
},
{
"SSID":"SS-007",
"TagType":"CountAccuIn",
"TagID":"902",
"TagValue":"72",
"StartTime":"20180531101825",
"EndTime":"20180531102825"
},
{
"SSID":"SS-007",
"TagType":"CountAccuOut",
"TagID":"903",
"TagValue":"20",
"StartTime":"20180531101825",
"EndTime":"20180531102825"
}
]
- SSID
- TagType
- Count
- CountAcculn
- CountAccuOut
- TagID: 901, 902, 903
- TagValue: Count of People who's type matches TagType
- StartTime: the calculate start time
- EndTime: the calculate end time