Commit 2490986f by hanjixin

readme

parent 194cbd56
# -*- coding: UTF-8 -*-
import argparse
import math
import json
from pythonosc import dispatcher
from pythonosc import osc_server
# import requests
import socket
import os
print(socket.gethostname())
# localIP = socket.gethostbyname(socket.gethostname()) # 得到本地ip
print('127.0.0.1')
def goPage(p):
url = "http://127.0.0.1:8089/" + \
str(json.loads(p)['p'])+"/"+str(json.loads(p)['n'])
print(url)
response = requests.request("GET", url)
print(response.text)
def section(unused_addr, args):
print(args.decode('utf-16be'))
str = args.decode('utf-16be').replace('䉅啃', '')
with open('test.txt',mode = 'w' , encoding = "UTF-8" ) as f:
f.write(str)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--ip",
default='127.0.0.1', help="The ip to listen on")
parser.add_argument("--port",
type=int, default=7001, help="The port to listen on")
args = parser.parse_args()
dispatcher = dispatcher.Dispatcher()
# dispatcher.map("/Page", print)
# dispatcher.map("/section", print)
dispatcher.map("/state", section)
print(args)
server = osc_server.ThreadingOSCUDPServer(
(args.ip, args.port), dispatcher)
print("Serving on {}".format(server.server_address))
server.serve_forever()
\ No newline at end of file
from flask import Flask, request, jsonify, make_response
from flask_cors import CORS
from utils_log import handler
import random
import socket
import os
import argparse
import json
import logging
from pythonosc import osc_message_builder
from pythonosc import udp_client
# localIP = socket.gethostbyname(socket.gethostname()) # 得到本地ip
localIP = '0.0.0.0'
app = Flask(__name__)
CORS(app, supports_credentials=True)
app.logger.addHandler(handler)
books = [
dict(id=1, isdn=random.randrange(1, 1000), title='a python book', author=dict(
name='l0set', city='hunan'
)),
dict(id=2, isdn=random.randrange(1, 1000), title='a golang book', author=dict(
name='zwhset', city='beijing'
))
]
def getBigUnicode(str):
b = bytes(str,'utf-8').decode().encode('utf-16be')
arr = [[0]*(4+len(b))][0]
arr[0] = 66
arr[1] = 69
arr[2] = 85
arr[3] = 67
for index in range(len(b)):
arr[index+4] = b[index]
return bytes(arr)
def sendMessage(path, message):
parser = argparse.ArgumentParser()
parser.add_argument("--ip", default="127.0.0.1",
help="The ip of the OSC server")
parser.add_argument("--port", type=int, default=7000,
help="The port the OSC server is listening on")
args = parser.parse_args()
client = udp_client.SimpleUDPClient(args.ip, args.port)
print(path, message)
client.send_message(path, message)
# error action
@app.errorhandler(405)
def page_not_found(e):
return jsonify(dict(code=1, message='method error.')), 405
# get all books
@app.route('/api/slider')
def handle_books():
return jsonify(books)
# get a book
@app.route('/api/slider/<int:id>')
def handle_book(id):
for i, book in enumerate(books):
if book['id'] == id:
return jsonify(book)
return jsonify(dict(code=2, message="don't fund the book"))
# create a new book
# 综合页 [{"page":"0"}]
# 丹寨热力 [{"page":"1"}]
# 动线 [{"page":"2"}]
# 客群画像 [{"page":"3"}]
# 客群来源 [{"page":"4"}]
# 丹寨实景 [{"page":"5"}]
# 客流销售 [{"page":"6"}]
# 万达bi [{"page":"bi"}]
# 万达视频 [{"page":"vid"}]
# 自动播放 [{"page":"bi"},{"page":"vid"},{"page":"1"}...]
@app.route('/api/slider', methods=['POST'])
def create_slider():
print(request.json)
result = request.json
if(result['index'] == 0):
sendMessage([{"page": "6"}]) # 客流销售
if(result['index'] == 1):
if (result['type'] == 'slider'):
sendMessage([{"page": "0"}]) # 丹寨综合
if (result['type'] == 'home'):
sendMessage([{"page": "0"}]) # 丹寨综合
if (result['type'] == 'homeSence'):
sendMessage([{"page": "5"}]) # 丹寨场景
if(result['index'] == 2):
sendMessage([{"page": "bi"}]) # BIM
return jsonify(code=0, message='success')
@app.route('/api/route', methods=['POST'])
def create_ctr():
app.logger.info(str(request))
# data = json.loads(request.json)
print(request.json['arguments'], len(request.json['arguments']))
# print(data)
result = request.json
message = [getBigUnicode(request.json['path'])]
if(len(request.json['arguments'])):
for index in range(len(request.json['arguments'])):
message.append(getBigUnicode(request.json['arguments'][index]))
# print(message)
# sendMessage('/route',[getBigUnicode(request.json['path']), 0 ,1])
sendMessage('/route',message)
return jsonify(code=0, message='success', data = request.json)
@app.route('/api/getState', methods=['get'])
def handle_route():
with open('test.txt',mode = 'r' , encoding = "UTF-8" ) as f:
str = f.read()
f.close()
return jsonify(code=0, message='success', data = str)
if __name__ == '__main__':
app.run(host=localIP, port=8900)
后台管理系统 admin vue
/admin
控制端 ipad
/dva react-dva
控制端 H5
/??
ventuz H5
/map
OSC Python server
/osc
启动文件夹/startup/??.bat
用途:接收ventuz 同步路由状态写文件存储
todo 改pyx
http代理 python center
/pyhttp
启动文件夹/startup/??.bat
作用:1.接收控制端http转osc
2.接收控制端查询路由状态接口,然后读取test.txt路由状态,然后返回
todo 改pyx
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment