From d6262966d5240680e3f6cca8327e727e2d5ddfe7 Mon Sep 17 00:00:00 2001 From: avishenhav76 Date: Wed, 27 Oct 2021 15:15:11 +0300 Subject: [PATCH 01/35] test --- .azure/config | 7 ++++++ app.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++-- client.py | 12 ++++++++++ requirements.txt | 1 + 4 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 .azure/config create mode 100644 client.py diff --git a/.azure/config b/.azure/config new file mode 100644 index 000000000..5d060533c --- /dev/null +++ b/.azure/config @@ -0,0 +1,7 @@ +[defaults] +group = admin_rg_Linux_westeurope +sku = B1 +appserviceplan = admin_asp_Linux_westeurope_0 +location = westeurope +web = locatorwb + diff --git a/app.py b/app.py index 7f8a1f2e8..6a4775e5c 100644 --- a/app.py +++ b/app.py @@ -1,6 +1,60 @@ -from flask import Flask +#from requests import request +import json +from flask import Flask, request, jsonify +import mysql.connector +from datetime import datetime + + +try: + x = 0 + mydb = mysql.connector.connect(user="LocationAdmin1@locatormysqlserver", password="LovelyLocation1!", + host="locatormysqlserver.mysql.database.azure.com", database="new_schema") + x = 1 +except Exception as ex: + print(ex) + + app = Flask(__name__) + +def InsertLocation(lot, lat, phoneid, dt): + mycursor = mydb.cursor() + sql = "INSERT INTO location (lot, lat,phoneid,dt) VALUES (%s, %s,%d,%d)" + val = (lot, lat, phoneid, dt) + mycursor.execute(sql, val) + mydb.commit() + + +@app.route("/testconnection") +def TestConnectio(): + return "Works" + + @app.route("/") def hello(): - return "Hello, World!" + print("Handling request to home page.") + return "Hello, Azure1!" + + +@app.route("/location", methods=['POST']) +def Location(): + try: + content = request.get_json() + lot = content["longitude"] + lat = content["latitude"] + sdt = content["datetime"] + phoneid = content["phoneid"] + dt = datetime.strptime(sdt, '%d/%m/%y %H:%M:%S') + InsertLocation(lot, lat, phoneid, dt) + + data = json.dumps(content) + print(data) + # datetime = request.form.get('datetime') + # longitude = request.form.get('longitude') + # Latitude = request.form.get('latitude') + # phoneid = request.form.get('phoneid') + except Exception as ex: + print(ex) + + +# app.run() diff --git a/client.py b/client.py new file mode 100644 index 000000000..3d4e96f4e --- /dev/null +++ b/client.py @@ -0,0 +1,12 @@ +from datetime import datetime +import mysql.connector + +mydb = None +try: + x = 0 + mydb = mysql.connector.connect(user="locationadmin@locatormysqlserver1", password="LovelyLocation1", + host="locatormysqlserver1.mysql.database.azure.com", database="sys") + print(mydb) + x = 1 +except Exception as ex: + print(ex) diff --git a/requirements.txt b/requirements.txt index 32e2d2715..649bced2a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ Flask>=1.0,<=1.1.2 +mysql-connector-python From ce988f670be08352f29b5bb5fb87d4a5770975a4 Mon Sep 17 00:00:00 2001 From: avishenhav76 Date: Mon, 1 Nov 2021 18:08:21 +0200 Subject: [PATCH 02/35] removed mysql --- app.py | 60 +++++++++++++++++++++++-------------------------------- client.py | 15 ++++++++++++-- 2 files changed, 38 insertions(+), 37 deletions(-) diff --git a/app.py b/app.py index 6a4775e5c..978c96f8a 100644 --- a/app.py +++ b/app.py @@ -1,28 +1,18 @@ #from requests import request import json from flask import Flask, request, jsonify -import mysql.connector from datetime import datetime -try: - x = 0 - mydb = mysql.connector.connect(user="LocationAdmin1@locatormysqlserver", password="LovelyLocation1!", - host="locatormysqlserver.mysql.database.azure.com", database="new_schema") - x = 1 -except Exception as ex: - print(ex) - - app = Flask(__name__) -def InsertLocation(lot, lat, phoneid, dt): - mycursor = mydb.cursor() - sql = "INSERT INTO location (lot, lat,phoneid,dt) VALUES (%s, %s,%d,%d)" - val = (lot, lat, phoneid, dt) - mycursor.execute(sql, val) - mydb.commit() +# def InsertLocation(lot, lat, phoneid, dt): +# mycursor = mydb.cursor() +# sql = "INSERT INTO location (lot, lat,phoneid,dt) VALUES (%s, %s,%d,%d)" +# val = (lot, lat, phoneid, dt) +# mycursor.execute(sql, val) +# mydb.commit() @app.route("/testconnection") @@ -36,25 +26,25 @@ def hello(): return "Hello, Azure1!" -@app.route("/location", methods=['POST']) -def Location(): - try: - content = request.get_json() - lot = content["longitude"] - lat = content["latitude"] - sdt = content["datetime"] - phoneid = content["phoneid"] - dt = datetime.strptime(sdt, '%d/%m/%y %H:%M:%S') - InsertLocation(lot, lat, phoneid, dt) - - data = json.dumps(content) - print(data) - # datetime = request.form.get('datetime') - # longitude = request.form.get('longitude') - # Latitude = request.form.get('latitude') - # phoneid = request.form.get('phoneid') - except Exception as ex: - print(ex) +# @app.route("/location", methods=['POST']) +# def Location(): +# try: +# content = request.get_json() +# lot = content["longitude"] +# lat = content["latitude"] +# sdt = content["datetime"] +# phoneid = content["phoneid"] +# dt = datetime.strptime(sdt, '%d/%m/%y %H:%M:%S') +# InsertLocation(lot, lat, phoneid, dt) + +# data = json.dumps(content) +# print(data) +# # datetime = request.form.get('datetime') +# # longitude = request.form.get('longitude') +# # Latitude = request.form.get('latitude') +# # phoneid = request.form.get('phoneid') +# except Exception as ex: +# print(ex) # app.run() diff --git a/client.py b/client.py index 3d4e96f4e..bf104b639 100644 --- a/client.py +++ b/client.py @@ -1,11 +1,22 @@ from datetime import datetime import mysql.connector +import socket + +hostname = socket.gethostname() +local_ip = socket.gethostbyname(hostname) + +print(local_ip) + mydb = None try: x = 0 - mydb = mysql.connector.connect(user="locationadmin@locatormysqlserver1", password="LovelyLocation1", - host="locatormysqlserver1.mysql.database.azure.com", database="sys") + #hostx = "52.128.23.153" + hostx = "locatormysqlserver.mysql.database.azure.com" + userx = "LocationAdmin1@locatormysqlserver" + + mydb = mysql.connector.connect(user=userx, password="LovelyLocation1!", + host=hostx, port=3306) print(mydb) x = 1 except Exception as ex: From abbc6e8ad2edc28e544be7567c3248c48049a43f Mon Sep 17 00:00:00 2001 From: avishenhav76 Date: Mon, 1 Nov 2021 18:26:01 +0200 Subject: [PATCH 03/35] check db --- app.py | 24 ++++++++++++++++++++++-- requirements.txt | 2 +- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index 978c96f8a..81a64b84d 100644 --- a/app.py +++ b/app.py @@ -2,10 +2,20 @@ import json from flask import Flask, request, jsonify from datetime import datetime +import pyodbc app = Flask(__name__) +server = 'dblocator.database.windows.net' +database = 'locatorserver' +username = 'AdminLocator' +password = 'LovelyLocator1!' +driver = '{ODBC Driver 17 for SQL Server}' + +sCon = 'DRIVER='+driver+';SERVER=tcp:'+server + \ + ';PORT=1433;DATABASE='+database+';UID='+username+';PWD=' + password + # def InsertLocation(lot, lat, phoneid, dt): # mycursor = mydb.cursor() @@ -22,8 +32,18 @@ def TestConnectio(): @app.route("/") def hello(): + con = pyodbc.connect(sCon) + cursor = con.cursor() + cursor.execute("SELECT * FROM test") + rows = cursor.fetchall() + s = "" + for row in rows: + for field in row: + s += str(field)+" " + print("Handling request to home page.") - return "Hello, Azure1!" + con.close() + return "Hello, Azure2!"+s # @app.route("/location", methods=['POST']) @@ -47,4 +67,4 @@ def hello(): # print(ex) -# app.run() +app.run() diff --git a/requirements.txt b/requirements.txt index 649bced2a..3104445dc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ Flask>=1.0,<=1.1.2 -mysql-connector-python +pyodbc From 4adcb03de5d86a9263fe04d7b0e4005cc3e51f49 Mon Sep 17 00:00:00 2001 From: avishenhav76 Date: Mon, 1 Nov 2021 18:26:36 +0200 Subject: [PATCH 04/35] check db1 --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index 81a64b84d..21e401516 100644 --- a/app.py +++ b/app.py @@ -67,4 +67,4 @@ def hello(): # print(ex) -app.run() +# app.run() From a7260f4502e34f375f297d74ccc61929778d3197 Mon Sep 17 00:00:00 2001 From: avishenhav76 Date: Tue, 2 Nov 2021 09:58:28 +0200 Subject: [PATCH 05/35] added exception --- app.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/app.py b/app.py index 21e401516..b357ae0ae 100644 --- a/app.py +++ b/app.py @@ -32,18 +32,21 @@ def TestConnectio(): @app.route("/") def hello(): - con = pyodbc.connect(sCon) - cursor = con.cursor() - cursor.execute("SELECT * FROM test") - rows = cursor.fetchall() - s = "" - for row in rows: - for field in row: - s += str(field)+" " - - print("Handling request to home page.") - con.close() - return "Hello, Azure2!"+s + try: + con = pyodbc.connect(sCon) + cursor = con.cursor() + cursor.execute("SELECT * FROM test") + rows = cursor.fetchall() + s = "" + for row in rows: + for field in row: + s += str(field)+" " + + print("Handling request to home page.") + con.close() + return "Hello, Azure2!"+s + except Exception as ex: + return (str(ex)) # @app.route("/location", methods=['POST']) @@ -66,5 +69,4 @@ def hello(): # except Exception as ex: # print(ex) - # app.run() From 3be1fcbb9d581e3cebce854ed20cb1b30e9f9280 Mon Sep 17 00:00:00 2001 From: avishenhav76 Date: Tue, 2 Nov 2021 13:44:21 +0200 Subject: [PATCH 06/35] Send to azure --- app.py | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/app.py b/app.py index b357ae0ae..7f46a5114 100644 --- a/app.py +++ b/app.py @@ -17,12 +17,17 @@ ';PORT=1433;DATABASE='+database+';UID='+username+';PWD=' + password -# def InsertLocation(lot, lat, phoneid, dt): -# mycursor = mydb.cursor() -# sql = "INSERT INTO location (lot, lat,phoneid,dt) VALUES (%s, %s,%d,%d)" -# val = (lot, lat, phoneid, dt) -# mycursor.execute(sql, val) -# mydb.commit() +def InsertLocation(lot, lat, dt, phoneid): + try: + con = pyodbc.connect(sCon) + mycursor = con.cursor() + sql = "INSERT INTO dbo.Location(Longitute, Latitude,dt,phoneid) VALUES (?,?,?,?) " + + mycursor.execute(sql, (lot, lat, dt, phoneid)) + con.commit() + con.close() + except Exception as ex: + print(ex) @app.route("/testconnection") @@ -30,6 +35,27 @@ def TestConnectio(): return "Works" +@app.route("/location", methods=['POST']) +def location(): + + data = request.get_data() + sData = data.decode('utf-8') + d = json.loads(sData) + x = 1 + Longitute = d['longitude'] + Latitude = d['latitude'] + dt = d['datetime'] + phoneid = d['phoneid'] + try: + date_time_obj = datetime. strptime(dt, '%d/%m/%y %H:%M:%S') + except Exception as ex: + print(ex) + + InsertLocation(Longitute, Latitude, date_time_obj, phoneid) + + x = 2 + + @app.route("/") def hello(): try: From 150d7d1dd31e52961ea737ce05307d8a168f34a9 Mon Sep 17 00:00:00 2001 From: avishenhav76 Date: Tue, 2 Nov 2021 13:52:25 +0200 Subject: [PATCH 07/35] return err --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index 7f46a5114..29d9fe0df 100644 --- a/app.py +++ b/app.py @@ -27,7 +27,7 @@ def InsertLocation(lot, lat, dt, phoneid): con.commit() con.close() except Exception as ex: - print(ex) + return str(ex) @app.route("/testconnection") From e5928ce5541619e1429e5d42bcab08e5493cc058 Mon Sep 17 00:00:00 2001 From: avishenhav76 Date: Tue, 2 Nov 2021 13:54:59 +0200 Subject: [PATCH 08/35] return value --- app.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index 29d9fe0df..ef791c497 100644 --- a/app.py +++ b/app.py @@ -26,6 +26,7 @@ def InsertLocation(lot, lat, dt, phoneid): mycursor.execute(sql, (lot, lat, dt, phoneid)) con.commit() con.close() + return "Succeded" except Exception as ex: return str(ex) @@ -51,9 +52,7 @@ def location(): except Exception as ex: print(ex) - InsertLocation(Longitute, Latitude, date_time_obj, phoneid) - - x = 2 + return InsertLocation(Longitute, Latitude, date_time_obj, phoneid) @app.route("/") From 11441bf2ccb3a57489ac6efa85dac0b1922b6a99 Mon Sep 17 00:00:00 2001 From: avishenhav76 Date: Thu, 4 Nov 2021 09:59:22 +0200 Subject: [PATCH 09/35] send speed and accuracy --- app.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app.py b/app.py index ef791c497..38c26faad 100644 --- a/app.py +++ b/app.py @@ -17,13 +17,13 @@ ';PORT=1433;DATABASE='+database+';UID='+username+';PWD=' + password -def InsertLocation(lot, lat, dt, phoneid): +def InsertLocation(lot, lat, dt, phoneid, accuracy, speed): try: con = pyodbc.connect(sCon) mycursor = con.cursor() - sql = "INSERT INTO dbo.Location(Longitute, Latitude,dt,phoneid) VALUES (?,?,?,?) " + sql = "INSERT INTO dbo.Location(Longitute, Latitude,dt,phoneid,accuracy,speed) VALUES (?,?,?,?,?,?) " - mycursor.execute(sql, (lot, lat, dt, phoneid)) + mycursor.execute(sql, (lot, lat, dt, phoneid, accuracy, speed)) con.commit() con.close() return "Succeded" @@ -47,12 +47,14 @@ def location(): Latitude = d['latitude'] dt = d['datetime'] phoneid = d['phoneid'] + accuracy = d['accuracy'] + speed = d['speed'] try: date_time_obj = datetime. strptime(dt, '%d/%m/%y %H:%M:%S') except Exception as ex: print(ex) - return InsertLocation(Longitute, Latitude, date_time_obj, phoneid) + return InsertLocation(Longitute, Latitude, date_time_obj, phoneid, accuracy, speed) @app.route("/") @@ -94,4 +96,4 @@ def hello(): # except Exception as ex: # print(ex) -# app.run() +app.run() From 186af02b5c6932795798adbf39e48843df205f62 Mon Sep 17 00:00:00 2001 From: avishenhav76 Date: Thu, 4 Nov 2021 10:34:12 +0200 Subject: [PATCH 10/35] sen accuration fix --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index 38c26faad..5e5a1578b 100644 --- a/app.py +++ b/app.py @@ -96,4 +96,4 @@ def hello(): # except Exception as ex: # print(ex) -app.run() +# app.run() From 8a3fbbce8d826f69098124c3d39dfe2fbfe68a65 Mon Sep 17 00:00:00 2001 From: avishenhav76 Date: Thu, 4 Nov 2021 15:13:18 +0200 Subject: [PATCH 11/35] wifi saved to azure --- app.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/app.py b/app.py index 5e5a1578b..b4c03f0ec 100644 --- a/app.py +++ b/app.py @@ -17,6 +17,20 @@ ';PORT=1433;DATABASE='+database+';UID='+username+';PWD=' + password +def InsertWifi(ssid, mac, level, phoneid, dt): + try: + con = pyodbc.connect(sCon) + mycursor = con.cursor() + sql = "INSERT INTO dbo.Wifi(ssid, mac, level, phoneid,dt) VALUES (?,?,?,?,?) " + + mycursor.execute(sql, (ssid, mac, level, phoneid, dt)) + con.commit() + con.close() + return "Succeded" + except Exception as ex: + return str(ex) + + def InsertLocation(lot, lat, dt, phoneid, accuracy, speed): try: con = pyodbc.connect(sCon) @@ -36,6 +50,23 @@ def TestConnectio(): return "Works" +@app.route("/wifi", methods=['POST']) +def wifi(): + data = request.get_data() + sData = data.decode('utf-8') + d = json.loads(sData) + ssid = d['ssid'] + mac = d['mac'] + level = d['level'] + phoneid = d['phoneid'] + dt = d['dt'] + try: + date_time_obj = datetime. strptime(dt, '%d/%m/%y %H:%M:%S') + except Exception as ex: + print(ex) + return InsertWifi(ssid, mac, level, phoneid, date_time_obj) + + @app.route("/location", methods=['POST']) def location(): @@ -57,6 +88,15 @@ def location(): return InsertLocation(Longitute, Latitude, date_time_obj, phoneid, accuracy, speed) +@app.route("/getName") +def getName(): + dic = {} + dic["name"] = "xxxx" + dic["age"] = 23 + data = json.dumps(dic) + return data + + @app.route("/") def hello(): try: From 70d7bd38c7dd18a69df11281392533d0e1e48719 Mon Sep 17 00:00:00 2001 From: iman300 <85990477+iman300@users.noreply.github.com> Date: Thu, 4 Nov 2021 15:17:42 +0200 Subject: [PATCH 12/35] Add or update the Azure App Service build and deployment workflow config --- .github/workflows/master_locatorwb.yml | 63 ++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 .github/workflows/master_locatorwb.yml diff --git a/.github/workflows/master_locatorwb.yml b/.github/workflows/master_locatorwb.yml new file mode 100644 index 000000000..eae2786ce --- /dev/null +++ b/.github/workflows/master_locatorwb.yml @@ -0,0 +1,63 @@ +# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy +# More GitHub Actions for Azure: https://github.com/Azure/actions +# More info on Python, GitHub Actions, and Azure App Service: https://aka.ms/python-webapps-actions + +name: Build and deploy Python app to Azure Web App - locatorwb + +on: + push: + branches: + - master + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python version + uses: actions/setup-python@v1 + with: + python-version: '3.7' + + - name: Create and start virtual environment + run: | + python -m venv venv + source venv/bin/activate + + - name: Install dependencies + run: pip install -r requirements.txt + + # Optional: Add step to run tests here (PyTest, Django test suites, etc.) + + - name: Upload artifact for deployment jobs + uses: actions/upload-artifact@v2 + with: + name: python-app + path: | + . + !venv/ + + deploy: + runs-on: ubuntu-latest + needs: build + environment: + name: 'Production' + url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} + + steps: + - name: Download artifact from build job + uses: actions/download-artifact@v2 + with: + name: python-app + path: . + + - name: 'Deploy to Azure Web App' + uses: azure/webapps-deploy@v2 + id: deploy-to-webapp + with: + app-name: 'locatorwb' + slot-name: 'Production' + publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_EE9E1236B07D4AE2804C03824425F86C }} From c1c75cb514687469f1a0e0c81c3596e37d4c7dec Mon Sep 17 00:00:00 2001 From: avishenhav76 Date: Thu, 4 Nov 2021 15:58:04 +0200 Subject: [PATCH 13/35] added num --- app.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app.py b/app.py index b4c03f0ec..ae91e79b8 100644 --- a/app.py +++ b/app.py @@ -93,7 +93,9 @@ def getName(): dic = {} dic["name"] = "xxxx" dic["age"] = 23 + dic["num"] = 17 data = json.dumps(dic) + return data From 73e8c134a80dbe3bb88b71dc3c31abf0e71a8b6f Mon Sep 17 00:00:00 2001 From: avishenhav76 Date: Tue, 9 Nov 2021 16:15:55 +0200 Subject: [PATCH 14/35] Bluetooth table works --- app.py | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/app.py b/app.py index ae91e79b8..4005d7cad 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,4 @@ -#from requests import request +# from requests import request import json from flask import Flask, request, jsonify from datetime import datetime @@ -31,6 +31,20 @@ def InsertWifi(ssid, mac, level, phoneid, dt): return str(ex) +def InsertBluetooth(name, code, address, rssi, phoneid, dt): + try: + con = pyodbc.connect(sCon) + mycursor = con.cursor() + sql = "INSERT INTO dbo.Bluetooth(namex, codex,addressx,rssi,phoneid,dt) VALUES (?,?,?,?,?,?) " + + mycursor.execute(sql, (name, code, address, rssi, phoneid, dt)) + con.commit() + con.close() + return "Succeded" + except Exception as ex: + return str(ex) + + def InsertLocation(lot, lat, dt, phoneid, accuracy, speed): try: con = pyodbc.connect(sCon) @@ -50,6 +64,24 @@ def TestConnectio(): return "Works" +@app.route("/bluetooth", methods=['POST']) +def bluetooth(): + data = request.get_data() + sData = data.decode('utf-8') + d = json.loads(sData) + name = d['name'] + code = d['code'] + address = d['address'] + rssi = d['rssi'] + phoneid = d['phoneid'] + dt = d['dt'] + try: + date_time_obj = datetime. strptime(dt, '%d/%m/%y %H:%M:%S') + except Exception as ex: + print(ex) + return InsertBluetooth(name, code, address, rssi, phoneid, date_time_obj) + + @app.route("/wifi", methods=['POST']) def wifi(): data = request.get_data() @@ -67,7 +99,7 @@ def wifi(): return InsertWifi(ssid, mac, level, phoneid, date_time_obj) -@app.route("/location", methods=['POST']) +@ app.route("/location", methods=['POST']) def location(): data = request.get_data() @@ -88,7 +120,7 @@ def location(): return InsertLocation(Longitute, Latitude, date_time_obj, phoneid, accuracy, speed) -@app.route("/getName") +@ app.route("/getName") def getName(): dic = {} dic["name"] = "xxxx" @@ -99,7 +131,7 @@ def getName(): return data -@app.route("/") +@ app.route("/") def hello(): try: con = pyodbc.connect(sCon) @@ -138,4 +170,4 @@ def hello(): # except Exception as ex: # print(ex) -# app.run() +app.run() From f56ed4773ed5ca9829c21149449612390fcf743a Mon Sep 17 00:00:00 2001 From: avishenhav76 Date: Tue, 9 Nov 2021 16:23:18 +0200 Subject: [PATCH 15/35] fix --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index 4005d7cad..a14ff3c3d 100644 --- a/app.py +++ b/app.py @@ -170,4 +170,4 @@ def hello(): # except Exception as ex: # print(ex) -app.run() +# app.run() From 67459a2b6c5ce50058568f413d2f8f4b20286130 Mon Sep 17 00:00:00 2001 From: avishenhav76 Date: Thu, 11 Nov 2021 15:58:00 +0200 Subject: [PATCH 16/35] Added insert phone --- app.py | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index a14ff3c3d..2b2e9c9e2 100644 --- a/app.py +++ b/app.py @@ -3,6 +3,7 @@ from flask import Flask, request, jsonify from datetime import datetime import pyodbc +import random app = Flask(__name__) @@ -31,6 +32,21 @@ def InsertWifi(ssid, mac, level, phoneid, dt): return str(ex) +def InsertPhoneInfo(phoneid, phonenumber, imei, serialNumber, simOperator, dt): + try: + con = pyodbc.connect(sCon) + mycursor = con.cursor() + sql = "INSERT INTO dbo.phone(phoneid, phonenumber, imei, serialNumber, simOperator,dt) VALUES (?,?,?,?,?,?) " + + mycursor.execute(sql, (phoneid, phonenumber, imei, + serialNumber, simOperator, dt)) + con.commit() + con.close() + return "Succeded" + except Exception as ex: + return str(ex) + + def InsertBluetooth(name, code, address, rssi, phoneid, dt): try: con = pyodbc.connect(sCon) @@ -75,6 +91,7 @@ def bluetooth(): rssi = d['rssi'] phoneid = d['phoneid'] dt = d['dt'] + try: date_time_obj = datetime. strptime(dt, '%d/%m/%y %H:%M:%S') except Exception as ex: @@ -99,6 +116,26 @@ def wifi(): return InsertWifi(ssid, mac, level, phoneid, date_time_obj) +@app.route("/setup", methods=['POST']) +def setup(): + data = request.get_data() + sData = data.decode('utf-8') + d = json.loads(sData) + serialNmber = d['serialNmber'] + imei = d['imei'] + phonenumber = d['phonenumber'] + simOperator = d['simOperator'] + phoneid = random.randint(100000, 200000) + dt = d['dt'] + try: + date_time_obj = datetime. strptime(dt, '%d/%m/%y %H:%M:%S') + except Exception as ex: + print(ex) + + InsertPhoneInfo(phoneid, phonenumber, imei, + serialNmber, simOperator, date_time_obj) + + @ app.route("/location", methods=['POST']) def location(): @@ -170,4 +207,4 @@ def hello(): # except Exception as ex: # print(ex) -# app.run() +app.run() From 27da1f3e276aea89f470894b823ec74f2cbe57e0 Mon Sep 17 00:00:00 2001 From: avishenhav76 Date: Thu, 11 Nov 2021 16:02:02 +0200 Subject: [PATCH 17/35] fix --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index 2b2e9c9e2..5fc2ccfa7 100644 --- a/app.py +++ b/app.py @@ -207,4 +207,4 @@ def hello(): # except Exception as ex: # print(ex) -app.run() +# app.run() From 56514481405bd427ba4da8d76fbc7202e3cba54a Mon Sep 17 00:00:00 2001 From: avishenhav76 Date: Thu, 11 Nov 2021 16:07:33 +0200 Subject: [PATCH 18/35] added succeed --- app.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index 5fc2ccfa7..f87929e52 100644 --- a/app.py +++ b/app.py @@ -132,8 +132,8 @@ def setup(): except Exception as ex: print(ex) - InsertPhoneInfo(phoneid, phonenumber, imei, - serialNmber, simOperator, date_time_obj) + return InsertPhoneInfo(phoneid, phonenumber, imei, + serialNmber, simOperator, date_time_obj) @ app.route("/location", methods=['POST']) @@ -206,5 +206,4 @@ def hello(): # # phoneid = request.form.get('phoneid') # except Exception as ex: # print(ex) - # app.run() From 154c644e6e8a2334c0b89600d0c5d397999357cc Mon Sep 17 00:00:00 2001 From: avishenhav76 Date: Thu, 11 Nov 2021 16:39:00 +0200 Subject: [PATCH 19/35] accept guid --- app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index f87929e52..bf86caaa4 100644 --- a/app.py +++ b/app.py @@ -121,11 +121,11 @@ def setup(): data = request.get_data() sData = data.decode('utf-8') d = json.loads(sData) - serialNmber = d['serialNmber'] + serialNmber = d['serialNumber'] imei = d['imei'] phonenumber = d['phonenumber'] simOperator = d['simOperator'] - phoneid = random.randint(100000, 200000) + phoneid = d['phoneid'] dt = d['dt'] try: date_time_obj = datetime. strptime(dt, '%d/%m/%y %H:%M:%S') From c557d13d0666f5dc1983474eadcf644107255280 Mon Sep 17 00:00:00 2001 From: avishenhav76 Date: Wed, 17 Nov 2021 11:37:17 +0200 Subject: [PATCH 20/35] works with inserting config --- app.py | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index bf86caaa4..41b6fe3ce 100644 --- a/app.py +++ b/app.py @@ -32,6 +32,27 @@ def InsertWifi(ssid, mac, level, phoneid, dt): return str(ex) +def InsertConfig(phoneid, wifiInterval, + BluetoothInterval, locationInterval, checkConfigInterval, StartTimeActivation, + StopTimeActivation, AllTime, ActivateWifi, ActivateBlueTooth, ActivateWifiDateTime, ActivateBlueToothDateTime, ActivateWifiDuration, ActivateBlueToothDuration): + try: + con = pyodbc.connect(sCon) + mycursor = con.cursor() + sql = "INSERT INTO dbo.config(phoneid, wifiInterval," + \ + "BluetoothInterval, locationInterval,checkConfigInterval,StartTimeActivation," +\ + "StopTimeActivation,AllTime,ActivateWifi,ActivateBlueTooth,ActivateWifiDateTime,ActivateBlueToothDateTime,ActivateWifiDuration,ActivateBlueToothDuration)" +\ + " VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?) " + + mycursor.execute(sql, (phoneid, wifiInterval, + BluetoothInterval, locationInterval, checkConfigInterval, StartTimeActivation, + StopTimeActivation, AllTime, ActivateWifi, ActivateBlueTooth, ActivateWifiDateTime, ActivateBlueToothDateTime, ActivateWifiDuration, ActivateBlueToothDuration)) + con.commit() + con.close() + return "Succeded" + except Exception as ex: + return str(ex) + + def InsertPhoneInfo(phoneid, phonenumber, imei, serialNumber, simOperator, dt): try: con = pyodbc.connect(sCon) @@ -98,6 +119,56 @@ def bluetooth(): print(ex) return InsertBluetooth(name, code, address, rssi, phoneid, date_time_obj) +# http://127.0.0.1:5000/config +# payload +# {"phoneid":"7406b194-a792-4bb2-9bfb-3a6d0ff74957","wifiInterval":1,"BluetoothInterval":2,"locationInterval":3,"checkConfigInterval":4,"StartTimeActivation":"16:31:19", +# "StopTimeActivation":"16:41:19","StartTimeActivation":13,"StopTimeActivation":14,"AllTime":1,"ActivateWifi":0,"ActivateBlueTooth":1, +# "ActivateWifiDateTime":"11/11/21 16:31:19","ActivateBlueToothDateTime":"11/11/21 17:31:19","ActivateWifiDuration":5,"ActivateBlueToothDuration":6} + + +@app.route("/config", methods=['POST']) +def config(): + data = request.get_data() + sData = data.decode('utf-8') + d = json.loads(sData) + phoneid = d['phoneid'] # guid identifying the phone + wifiInterval = d['wifiInterval'] # interval in minutes + BluetoothInterval = d['BluetoothInterval'] # interval in minutes + locationInterval = d['locationInterval'] # interval in minutes + checkConfigInterval = d['checkConfigInterval'] # interval in minutes + StartTimeActivation = d['StartTimeActivation'] # number: hour from 1-24 + StopTimeActivation = d['StopTimeActivation'] # number: hour from 1-24 + # boolean if true will activate all time no matter what StartTimeActivation and StopTimeActivation are. + AllTime = d['AllTime'] + # boolean if true will activate wifi from ActivateWifiDateTime (dateTime) for ActivateWifiDuration minutes + ActivateWifi = d['ActivateWifi'] + # boolean if true will activate wifi from ActivateBlueToothDateTime (dateTime) for ActivateBlueToothDuration minutes + ActivateBlueTooth = d['ActivateBlueTooth'] + # the datetime to start activate wifi if ActivateWifi is true + ActivateWifiDateTime = d['ActivateWifiDateTime'] + # the datetime to start activate blueTooth if ActivateWifi is true + ActivateBlueToothDateTime = d['ActivateBlueToothDateTime'] + # the duration of wifi activation + ActivateWifiDuration = d["ActivateWifiDuration"] + # the duration of bluetooth activation + ActivateBlueToothDuration = d["ActivateBlueToothDuration"] + + try: + wifiDate = datetime. strptime( + ActivateWifiDateTime, '%d/%m/%y %H:%M:%S') + blueToothDate = datetime. strptime( + ActivateBlueToothDateTime, '%d/%m/%y %H:%M:%S') + except Exception as ex: + print(ex) + + try: + ret = InsertConfig(phoneid, wifiInterval, + BluetoothInterval, locationInterval, checkConfigInterval, StartTimeActivation, + StopTimeActivation, AllTime, ActivateWifi, ActivateBlueTooth, wifiDate, blueToothDate, ActivateWifiDuration, ActivateBlueToothDuration) + return ret + except Exception as ex: + return str(ex) + @app.route("/wifi", methods=['POST']) def wifi(): @@ -206,4 +277,4 @@ def hello(): # # phoneid = request.form.get('phoneid') # except Exception as ex: # print(ex) -# app.run() +app.run() From 6bb9f2c5cd864b82a7d8667db891d41918271c81 Mon Sep 17 00:00:00 2001 From: avishenhav76 Date: Wed, 17 Nov 2021 11:37:40 +0200 Subject: [PATCH 21/35] x --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index 41b6fe3ce..d1bb15a5b 100644 --- a/app.py +++ b/app.py @@ -277,4 +277,4 @@ def hello(): # # phoneid = request.form.get('phoneid') # except Exception as ex: # print(ex) -app.run() +# app.run() From 7a5a761ea1edabbab0620c44a4d48b6dfa9bcf23 Mon Sep 17 00:00:00 2001 From: avishenhav76 Date: Wed, 17 Nov 2021 15:26:43 +0200 Subject: [PATCH 22/35] works with post and get config --- app.py | 131 +++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 89 insertions(+), 42 deletions(-) diff --git a/app.py b/app.py index d1bb15a5b..eaafb2927 100644 --- a/app.py +++ b/app.py @@ -32,6 +32,45 @@ def InsertWifi(ssid, mac, level, phoneid, dt): return str(ex) +def GetlastConfigLine(phoneid): + try: + con = pyodbc.connect(sCon) + mycursor = con.cursor() + sql = "SELECT top 1 * FROM config where phoneid='"+phoneid+"' order by id desc" + mycursor.execute(sql) + myresult = mycursor.fetchall() + dic = {} + for row in myresult: + dic['phoneid'] = row[1] + dic['wifiInterval'] = row[2] + dic['BluetoothInterval'] = row[3] + dic['locationInterval'] = row[4] + dic['checkConfigInterval'] = row[5] + dic['StartTimeActivation'] = row[6] + dic['StopTimeActivation'] = row[7] + dic['AllTime'] = row[8] + dic['ActivateWifi'] = row[9] + dic['ActivateBlueTooth'] = row[10] + try: + + ActivateWifiDateTime = row[11].strftime('%d/%m/%y %H:%M:%S') + ActivateBlueToothDateTime = row[12].strftime( + '%d/%m/%y %H:%M:%S') + dic['ActivateWifiDateTime'] = ActivateWifiDateTime + dic['ActivateBlueToothDateTime'] = ActivateBlueToothDateTime + + except Exception as ex: + return str(ex) + dic['ActivateWifiDuration'] = row[13] + dic['ActivateBlueToothDuration'] = row[14] + + con.close() + s = json.dumps(dic) + return s + except Exception as ex: + return str(ex) + + def InsertConfig(phoneid, wifiInterval, BluetoothInterval, locationInterval, checkConfigInterval, StartTimeActivation, StopTimeActivation, AllTime, ActivateWifi, ActivateBlueTooth, ActivateWifiDateTime, ActivateBlueToothDateTime, ActivateWifiDuration, ActivateBlueToothDuration): @@ -126,48 +165,57 @@ def bluetooth(): # "ActivateWifiDateTime":"11/11/21 16:31:19","ActivateBlueToothDateTime":"11/11/21 17:31:19","ActivateWifiDuration":5,"ActivateBlueToothDuration":6} -@app.route("/config", methods=['POST']) +@app.route("/config", methods=['GET', 'POST']) def config(): - data = request.get_data() - sData = data.decode('utf-8') - d = json.loads(sData) - phoneid = d['phoneid'] # guid identifying the phone - wifiInterval = d['wifiInterval'] # interval in minutes - BluetoothInterval = d['BluetoothInterval'] # interval in minutes - locationInterval = d['locationInterval'] # interval in minutes - checkConfigInterval = d['checkConfigInterval'] # interval in minutes - StartTimeActivation = d['StartTimeActivation'] # number: hour from 1-24 - StopTimeActivation = d['StopTimeActivation'] # number: hour from 1-24 - # boolean if true will activate all time no matter what StartTimeActivation and StopTimeActivation are. - AllTime = d['AllTime'] - # boolean if true will activate wifi from ActivateWifiDateTime (dateTime) for ActivateWifiDuration minutes - ActivateWifi = d['ActivateWifi'] - # boolean if true will activate wifi from ActivateBlueToothDateTime (dateTime) for ActivateBlueToothDuration minutes - ActivateBlueTooth = d['ActivateBlueTooth'] - # the datetime to start activate wifi if ActivateWifi is true - ActivateWifiDateTime = d['ActivateWifiDateTime'] - # the datetime to start activate blueTooth if ActivateWifi is true - ActivateBlueToothDateTime = d['ActivateBlueToothDateTime'] - # the duration of wifi activation - ActivateWifiDuration = d["ActivateWifiDuration"] - # the duration of bluetooth activation - ActivateBlueToothDuration = d["ActivateBlueToothDuration"] - - try: - wifiDate = datetime. strptime( - ActivateWifiDateTime, '%d/%m/%y %H:%M:%S') - blueToothDate = datetime. strptime( - ActivateBlueToothDateTime, '%d/%m/%y %H:%M:%S') - except Exception as ex: - print(ex) - - try: - ret = InsertConfig(phoneid, wifiInterval, - BluetoothInterval, locationInterval, checkConfigInterval, StartTimeActivation, - StopTimeActivation, AllTime, ActivateWifi, ActivateBlueTooth, wifiDate, blueToothDate, ActivateWifiDuration, ActivateBlueToothDuration) - return ret - except Exception as ex: - return str(ex) + if (request.method == 'POST'): + data = request.get_data() + sData = data.decode('utf-8') + d = json.loads(sData) + phoneid = d['phoneid'] # guid identifying the phone + wifiInterval = d['wifiInterval'] # interval in minutes + BluetoothInterval = d['BluetoothInterval'] # interval in minutes + locationInterval = d['locationInterval'] # interval in minutes + checkConfigInterval = d['checkConfigInterval'] # interval in minutes + # number: hour from 1-24 + StartTimeActivation = d['StartTimeActivation'] + StopTimeActivation = d['StopTimeActivation'] # number: hour from 1-24 + # boolean if true will activate all time no matter what StartTimeActivation and StopTimeActivation are. + AllTime = d['AllTime'] + # boolean if true will activate wifi from ActivateWifiDateTime (dateTime) for ActivateWifiDuration minutes + ActivateWifi = d['ActivateWifi'] + # boolean if true will activate wifi from ActivateBlueToothDateTime (dateTime) for ActivateBlueToothDuration minutes + ActivateBlueTooth = d['ActivateBlueTooth'] + # the datetime to start activate wifi if ActivateWifi is true + ActivateWifiDateTime = d['ActivateWifiDateTime'] + # the datetime to start activate blueTooth if ActivateWifi is true + ActivateBlueToothDateTime = d['ActivateBlueToothDateTime'] + # the duration of wifi activation + ActivateWifiDuration = d["ActivateWifiDuration"] + # the duration of bluetooth activation + ActivateBlueToothDuration = d["ActivateBlueToothDuration"] + + try: + wifiDate = datetime. strptime( + ActivateWifiDateTime, '%d/%m/%y %H:%M:%S') + blueToothDate = datetime. strptime( + ActivateBlueToothDateTime, '%d/%m/%y %H:%M:%S') + except Exception as ex: + print(ex) + + try: + ret = InsertConfig(phoneid, wifiInterval, + BluetoothInterval, locationInterval, checkConfigInterval, StartTimeActivation, + StopTimeActivation, AllTime, ActivateWifi, ActivateBlueTooth, wifiDate, blueToothDate, ActivateWifiDuration, ActivateBlueToothDuration) + return ret + except Exception as ex: + return str(ex) + else: + try: + phoneid = request.args["phoneid"] + ret = GetlastConfigLine(phoneid) + return ret + except Exception as ex: + return str(ex) @app.route("/wifi", methods=['POST']) @@ -277,4 +325,3 @@ def hello(): # # phoneid = request.form.get('phoneid') # except Exception as ex: # print(ex) -# app.run() From 7491d73f138a5433826ff65ced1854e3887783bf Mon Sep 17 00:00:00 2001 From: avishenhav76 Date: Sun, 21 Nov 2021 11:29:10 +0200 Subject: [PATCH 23/35] changed date format --- app.py | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/app.py b/app.py index eaafb2927..ed20f2b71 100644 --- a/app.py +++ b/app.py @@ -53,9 +53,9 @@ def GetlastConfigLine(phoneid): dic['ActivateBlueTooth'] = row[10] try: - ActivateWifiDateTime = row[11].strftime('%d/%m/%y %H:%M:%S') + ActivateWifiDateTime = row[11].strftime('%d-%m-%y %H:%M:%S') ActivateBlueToothDateTime = row[12].strftime( - '%d/%m/%y %H:%M:%S') + '%d-%m-%y %H:%M:%S') dic['ActivateWifiDateTime'] = ActivateWifiDateTime dic['ActivateBlueToothDateTime'] = ActivateBlueToothDateTime @@ -158,11 +158,16 @@ def bluetooth(): print(ex) return InsertBluetooth(name, code, address, rssi, phoneid, date_time_obj) +# Post # http://127.0.0.1:5000/config # payload # {"phoneid":"7406b194-a792-4bb2-9bfb-3a6d0ff74957","wifiInterval":1,"BluetoothInterval":2,"locationInterval":3,"checkConfigInterval":4,"StartTimeActivation":"16:31:19", # "StopTimeActivation":"16:41:19","StartTimeActivation":13,"StopTimeActivation":14,"AllTime":1,"ActivateWifi":0,"ActivateBlueTooth":1, # "ActivateWifiDateTime":"11/11/21 16:31:19","ActivateBlueToothDateTime":"11/11/21 17:31:19","ActivateWifiDuration":5,"ActivateBlueToothDuration":6} +# +# get +# https://locatorwb.azurewebsites.net/config?phoneid=7406b194-a792-4bb2-9bfb-3a6d0ff74957 +# in get version the function will get the last line of config that relates to the phoneid @app.route("/config", methods=['GET', 'POST']) @@ -306,22 +311,4 @@ def hello(): return (str(ex)) -# @app.route("/location", methods=['POST']) -# def Location(): -# try: -# content = request.get_json() -# lot = content["longitude"] -# lat = content["latitude"] -# sdt = content["datetime"] -# phoneid = content["phoneid"] -# dt = datetime.strptime(sdt, '%d/%m/%y %H:%M:%S') -# InsertLocation(lot, lat, phoneid, dt) - -# data = json.dumps(content) -# print(data) -# # datetime = request.form.get('datetime') -# # longitude = request.form.get('longitude') -# # Latitude = request.form.get('latitude') -# # phoneid = request.form.get('phoneid') -# except Exception as ex: -# print(ex) +# app.run() From bd9cb00c06bd618a1d3a54bf28e731b91973e116 Mon Sep 17 00:00:00 2001 From: avishenhav76 Date: Sun, 21 Nov 2021 17:06:00 +0200 Subject: [PATCH 24/35] include default config --- app.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index ed20f2b71..4b29d61f5 100644 --- a/app.py +++ b/app.py @@ -32,6 +32,26 @@ def InsertWifi(ssid, mac, level, phoneid, dt): return str(ex) +def GetDefaultConfigLine(phoneid): + dic = {} + dic['phoneid'] = phoneid + dic['wifiInterval'] = 10 + dic['BluetoothInterval'] = 10 + dic['locationInterval'] = 10 + dic['checkConfigInterval'] = 5 + dic['StartTimeActivation'] = 1 + dic['StopTimeActivation'] = 3 + dic['AllTime'] = "True" + dic['ActivateWifi'] = 0 + dic['ActivateBlueTooth'] = 0 + dic['ActivateWifiDateTime'] = "01/01/99 16:40:19" + dic['ActivateBlueToothDateTime'] = "01/01/99 16:40:19" + dic['ActivateWifiDuration'] = 0 + dic['ActivateBlueToothDuration'] = 0 + s = json.dumps(dic) + return s + + def GetlastConfigLine(phoneid): try: con = pyodbc.connect(sCon) @@ -220,6 +240,7 @@ def config(): ret = GetlastConfigLine(phoneid) return ret except Exception as ex: + # return GetDefaultConfigLine(phoneid) return str(ex) @@ -311,4 +332,4 @@ def hello(): return (str(ex)) -# app.run() +app.run() From 9e61100ce351acdeaa6491a100a03f2d5d971cd4 Mon Sep 17 00:00:00 2001 From: avishenhav76 Date: Sun, 21 Nov 2021 18:07:57 +0200 Subject: [PATCH 25/35] works with default config --- app.py | 7 +++++-- doc.txt | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 doc.txt diff --git a/app.py b/app.py index 4b29d61f5..f5d45dee2 100644 --- a/app.py +++ b/app.py @@ -238,10 +238,13 @@ def config(): try: phoneid = request.args["phoneid"] ret = GetlastConfigLine(phoneid) + if (ret == '{}'): + return GetDefaultConfigLine(phoneid) + return ret except Exception as ex: - # return GetDefaultConfigLine(phoneid) - return str(ex) + return GetDefaultConfigLine(phoneid) + # return str(ex) @app.route("/wifi", methods=['POST']) diff --git a/doc.txt b/doc.txt new file mode 100644 index 000000000..abc30590f --- /dev/null +++ b/doc.txt @@ -0,0 +1,2 @@ +Java applicatuion +D:\wifiscanjava\app\src\main\java\com\example\wifiscanapplication \ No newline at end of file From df0715b40400a0940eb2fa323a0ae1918acfb969 Mon Sep 17 00:00:00 2001 From: avishenhav76 Date: Sun, 21 Nov 2021 18:12:07 +0200 Subject: [PATCH 26/35] x1 --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index f5d45dee2..71cb9bb20 100644 --- a/app.py +++ b/app.py @@ -335,4 +335,4 @@ def hello(): return (str(ex)) -app.run() +# app.run() From eedaf561aa04796f49851cf3dfaefaa8acc76b4c Mon Sep 17 00:00:00 2001 From: avishenhav76 Date: Sun, 21 Nov 2021 18:17:08 +0200 Subject: [PATCH 27/35] x2 --- app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index 71cb9bb20..b6034409c 100644 --- a/app.py +++ b/app.py @@ -44,8 +44,8 @@ def GetDefaultConfigLine(phoneid): dic['AllTime'] = "True" dic['ActivateWifi'] = 0 dic['ActivateBlueTooth'] = 0 - dic['ActivateWifiDateTime'] = "01/01/99 16:40:19" - dic['ActivateBlueToothDateTime'] = "01/01/99 16:40:19" + dic['ActivateWifiDateTime'] = "01-01-99 16:40:19" + dic['ActivateBlueToothDateTime'] = "01-01-99 16:40:19" dic['ActivateWifiDuration'] = 0 dic['ActivateBlueToothDuration'] = 0 s = json.dumps(dic) From d9c5709b9368d0d7811a41070ff7e48ddc1ac770 Mon Sep 17 00:00:00 2001 From: avishenhav76 Date: Wed, 24 Nov 2021 11:12:47 +0200 Subject: [PATCH 28/35] add phone mode --- app.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index b6034409c..4458a5f39 100644 --- a/app.py +++ b/app.py @@ -112,14 +112,14 @@ def InsertConfig(phoneid, wifiInterval, return str(ex) -def InsertPhoneInfo(phoneid, phonenumber, imei, serialNumber, simOperator, dt): +def InsertPhoneInfo(phoneid, phonenumber, imei, serialNumber, simOperator, dt, manufacturer, model, version, versionRelease): try: con = pyodbc.connect(sCon) mycursor = con.cursor() - sql = "INSERT INTO dbo.phone(phoneid, phonenumber, imei, serialNumber, simOperator,dt) VALUES (?,?,?,?,?,?) " + sql = "INSERT INTO dbo.phone(phoneid, phonenumber, imei, serialNumber, simOperator,dt, manufacturer, model, version, versionRelease) VALUES (?,?,?,?,?,?,?,?,?,?) " mycursor.execute(sql, (phoneid, phonenumber, imei, - serialNumber, simOperator, dt)) + serialNumber, simOperator, dt, manufacturer, model, version, versionRelease)) con.commit() con.close() return "Succeded" @@ -275,13 +275,17 @@ def setup(): simOperator = d['simOperator'] phoneid = d['phoneid'] dt = d['dt'] + manufacturer = d["manufacturer"] + model = d["model"] + version = d["version"] + versionRelease = d["versionRelease"] try: date_time_obj = datetime. strptime(dt, '%d/%m/%y %H:%M:%S') except Exception as ex: print(ex) return InsertPhoneInfo(phoneid, phonenumber, imei, - serialNmber, simOperator, date_time_obj) + serialNmber, simOperator, date_time_obj, manufacturer, model, version, versionRelease) @ app.route("/location", methods=['POST']) From f1935f61bf2a83a380fcff673898edc03b995534 Mon Sep 17 00:00:00 2001 From: avishenhav76 Date: Wed, 24 Nov 2021 11:44:23 +0200 Subject: [PATCH 29/35] save logs --- app.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/app.py b/app.py index 4458a5f39..2053e5118 100644 --- a/app.py +++ b/app.py @@ -320,6 +320,35 @@ def getName(): return data +def InsertLoLog(phoneid, dt, msg): + try: + con = pyodbc.connect(sCon) + mycursor = con.cursor() + sql = "INSERT INTO dbo.Logs(phoneid, dt, msg) VALUES (?,?,?) " + + mycursor.execute(sql, (phoneid, dt, msg)) + con.commit() + con.close() + return "Succeded" + except Exception as ex: + return str(ex) + + +@app.route("/log", methods=['POST']) +def Log(): + data = request.get_data() + sData = data.decode('utf-8') + d = json.loads(sData) + dt = d['dt'] + phoneid = d['phoneid'] + msg = d["msg"] + try: + date_time_obj = datetime. strptime(dt, '%d/%m/%y %H:%M:%S') + except Exception as ex: + print(ex) + InsertLoLog(phoneid, date_time_obj, msg) + + @ app.route("/") def hello(): try: From e26c573744e624be05817661a5565b195390508a Mon Sep 17 00:00:00 2001 From: avishenhav76 Date: Wed, 24 Nov 2021 11:50:51 +0200 Subject: [PATCH 30/35] fix add return --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index 2053e5118..9997c3dee 100644 --- a/app.py +++ b/app.py @@ -346,7 +346,7 @@ def Log(): date_time_obj = datetime. strptime(dt, '%d/%m/%y %H:%M:%S') except Exception as ex: print(ex) - InsertLoLog(phoneid, date_time_obj, msg) + return InsertLoLog(phoneid, date_time_obj, msg) @ app.route("/") From 3ee0329d47596637ee22fd761b2d5d4b10767117 Mon Sep 17 00:00:00 2001 From: avishenhav76 Date: Mon, 6 Dec 2021 10:50:06 +0200 Subject: [PATCH 31/35] added sendTime to location --- app.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index 9997c3dee..3c70c7dd1 100644 --- a/app.py +++ b/app.py @@ -141,13 +141,14 @@ def InsertBluetooth(name, code, address, rssi, phoneid, dt): return str(ex) -def InsertLocation(lot, lat, dt, phoneid, accuracy, speed): +def InsertLocation(lot, lat, dt, phoneid, accuracy, speed, sendTime): try: con = pyodbc.connect(sCon) mycursor = con.cursor() - sql = "INSERT INTO dbo.Location(Longitute, Latitude,dt,phoneid,accuracy,speed) VALUES (?,?,?,?,?,?) " + sql = "INSERT INTO dbo.Location(Longitute, Latitude,dt,phoneid,accuracy,speed,SendTime) VALUES (?,?,?,?,?,?,?) " - mycursor.execute(sql, (lot, lat, dt, phoneid, accuracy, speed)) + mycursor.execute(sql, (lot, lat, dt, phoneid, + accuracy, speed, sendTime)) con.commit() con.close() return "Succeded" @@ -301,12 +302,19 @@ def location(): phoneid = d['phoneid'] accuracy = d['accuracy'] speed = d['speed'] + sendTime = d['sendTime'] + try: date_time_obj = datetime. strptime(dt, '%d/%m/%y %H:%M:%S') except Exception as ex: print(ex) - return InsertLocation(Longitute, Latitude, date_time_obj, phoneid, accuracy, speed) + try: + sendTimeStr = datetime. strptime(sendTime, '%d/%m/%y %H:%M:%S') + except Exception as ex: + print(ex) + + return InsertLocation(Longitute, Latitude, date_time_obj, phoneid, accuracy, speed, sendTimeStr) @ app.route("/getName") From 101370e2575b83b931749e4d438c69dfc722e138 Mon Sep 17 00:00:00 2001 From: avishenhav76 Date: Mon, 6 Dec 2021 14:43:34 +0200 Subject: [PATCH 32/35] changed default times --- app.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index 3c70c7dd1..08de19cbc 100644 --- a/app.py +++ b/app.py @@ -35,10 +35,10 @@ def InsertWifi(ssid, mac, level, phoneid, dt): def GetDefaultConfigLine(phoneid): dic = {} dic['phoneid'] = phoneid - dic['wifiInterval'] = 10 - dic['BluetoothInterval'] = 10 - dic['locationInterval'] = 10 - dic['checkConfigInterval'] = 5 + dic['wifiInterval'] = 2 + dic['BluetoothInterval'] = 2 + dic['locationInterval'] = 1 + dic['checkConfigInterval'] = 3 dic['StartTimeActivation'] = 1 dic['StopTimeActivation'] = 3 dic['AllTime'] = "True" From e8bcefd584f40f9e053435b47c15c772fc9451bf Mon Sep 17 00:00:00 2001 From: avishenhav76 Date: Tue, 14 Dec 2021 14:20:37 +0200 Subject: [PATCH 33/35] xx --- app.py | 1 + 1 file changed, 1 insertion(+) diff --git a/app.py b/app.py index 08de19cbc..efc77c2c3 100644 --- a/app.py +++ b/app.py @@ -49,6 +49,7 @@ def GetDefaultConfigLine(phoneid): dic['ActivateWifiDuration'] = 0 dic['ActivateBlueToothDuration'] = 0 s = json.dumps(dic) + # xx return s From 178face2e58a1fabc9a05f3d27f27e7c886cc5e8 Mon Sep 17 00:00:00 2001 From: avishenhav76 Date: Thu, 16 Dec 2021 13:40:08 +0200 Subject: [PATCH 34/35] seceeded1 --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index efc77c2c3..62f319706 100644 --- a/app.py +++ b/app.py @@ -152,7 +152,7 @@ def InsertLocation(lot, lat, dt, phoneid, accuracy, speed, sendTime): accuracy, speed, sendTime)) con.commit() con.close() - return "Succeded" + return "Succeded1" except Exception as ex: return str(ex) From 0465c78f41ff05876782f329ec55e5b850459aae Mon Sep 17 00:00:00 2001 From: avishenhav76 Date: Mon, 20 Dec 2021 10:46:53 +0200 Subject: [PATCH 35/35] test --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index 62f319706..6dd2c5f32 100644 --- a/app.py +++ b/app.py @@ -152,7 +152,7 @@ def InsertLocation(lot, lat, dt, phoneid, accuracy, speed, sendTime): accuracy, speed, sendTime)) con.commit() con.close() - return "Succeded1" + return "Succeded2" except Exception as ex: return str(ex)