Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
html
/
MeteorologicalBureau
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
3fa51d37
authored
Mar 16, 2020
by
hank
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
python状态统一
parent
641fdddc
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
73 additions
and
64 deletions
+73
-64
.gitignore
+2
-0
c.py
+4
-2
center.py
+13
-2
osc.py
+7
-60
test.txt
+14
-0
utils_log.py
+33
-0
No files found.
.gitignore
View file @
3fa51d37
...
@@ -3,3 +3,4 @@ node_modules
...
@@ -3,3 +3,4 @@ node_modules
node_modules
node_modules
log/*
log/*
.DS_Store
.DS_Store
__pycache__/*
\ No newline at end of file
c.py
View file @
3fa51d37
...
@@ -11,12 +11,12 @@ if __name__ == "__main__":
...
@@ -11,12 +11,12 @@ if __name__ == "__main__":
def
sendUdp
(
data
):
def
sendUdp
(
data
):
print
(
data
.
encode
(
'utf-16be'
),
'utf-16be'
)
print
(
data
.
encode
(
'utf-16be'
),
'utf-16be'
)
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_DGRAM
)
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_DGRAM
)
s
.
sendto
(
data
.
encode
(
'utf-16be'
),
(
'127.0.0.1'
,
700
0
))
s
.
sendto
(
data
.
encode
(
'utf-16be'
),
(
'127.0.0.1'
,
700
1
))
s
.
close
()
s
.
close
()
parser
=
argparse
.
ArgumentParser
()
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"--ip"
,
default
=
"127.0.0.1"
,
parser
.
add_argument
(
"--ip"
,
default
=
"127.0.0.1"
,
help
=
"The ip of the OSC server"
)
help
=
"The ip of the OSC server"
)
parser
.
add_argument
(
"--port"
,
type
=
int
,
default
=
700
0
,
parser
.
add_argument
(
"--port"
,
type
=
int
,
default
=
700
1
,
help
=
"The port the OSC server is listening on"
)
help
=
"The port the OSC server is listening on"
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
...
@@ -32,3 +32,4 @@ if __name__ == "__main__":
...
@@ -32,3 +32,4 @@ if __name__ == "__main__":
arr
[
index
+
4
]
=
b
[
index
]
arr
[
index
+
4
]
=
b
[
index
]
client
.
send_message
(
"/route"
,
[
bytes
(
arr
)])
client
.
send_message
(
"/route"
,
[
bytes
(
arr
)])
client
.
send_message
(
"/首页/全国"
,
[
0
,
1
])
client
.
send_message
(
"/首页/全国"
,
[
0
,
1
])
client
.
send_message
(
"/state"
,
[
0
])
\ No newline at end of file
center.py
View file @
3fa51d37
from
flask
import
Flask
,
request
,
jsonify
,
make_response
from
flask
import
Flask
,
request
,
jsonify
,
make_response
from
flask_cors
import
CORS
from
flask_cors
import
CORS
from
utils_log
import
handler
import
random
import
random
import
socket
import
socket
import
os
import
os
import
argparse
import
argparse
import
json
import
json
import
logging
from
pythonosc
import
osc_message_builder
from
pythonosc
import
osc_message_builder
from
pythonosc
import
udp_client
from
pythonosc
import
udp_client
# localIP = socket.gethostbyname(socket.gethostname()) # 得到本地ip
# localIP = socket.gethostbyname(socket.gethostname()) # 得到本地ip
localIP
=
'0.0.0.0'
localIP
=
'0.0.0.0'
app
=
Flask
(
__name__
)
app
=
Flask
(
__name__
)
CORS
(
app
,
supports_credentials
=
True
)
CORS
(
app
,
supports_credentials
=
True
)
app
.
logger
.
addHandler
(
handler
)
books
=
[
books
=
[
dict
(
id
=
1
,
isdn
=
random
.
randrange
(
1
,
1000
),
title
=
'a python book'
,
author
=
dict
(
dict
(
id
=
1
,
isdn
=
random
.
randrange
(
1
,
1000
),
title
=
'a python book'
,
author
=
dict
(
name
=
'l0set'
,
city
=
'hunan'
name
=
'l0set'
,
city
=
'hunan'
...
@@ -96,8 +99,9 @@ def create_slider():
...
@@ -96,8 +99,9 @@ def create_slider():
if
(
result
[
'index'
]
==
2
):
if
(
result
[
'index'
]
==
2
):
sendMessage
([{
"page"
:
"bi"
}])
# BIM
sendMessage
([{
"page"
:
"bi"
}])
# BIM
return
jsonify
(
code
=
0
,
message
=
'success'
)
return
jsonify
(
code
=
0
,
message
=
'success'
)
@app.route
(
'/api/
ctr
'
,
methods
=
[
'POST'
])
@app.route
(
'/api/
route
'
,
methods
=
[
'POST'
])
def
create_ctr
():
def
create_ctr
():
app
.
logger
.
info
(
str
(
request
))
# data = json.loads(request.json)
# data = json.loads(request.json)
print
(
request
.
json
[
'arguments'
],
len
(
request
.
json
[
'arguments'
]))
print
(
request
.
json
[
'arguments'
],
len
(
request
.
json
[
'arguments'
]))
# print(data)
# print(data)
...
@@ -110,5 +114,12 @@ def create_ctr():
...
@@ -110,5 +114,12 @@ def create_ctr():
# sendMessage('/route',[getBigUnicode(request.json['path']), 0 ,1])
# sendMessage('/route',[getBigUnicode(request.json['path']), 0 ,1])
sendMessage
(
'/route'
,
message
)
sendMessage
(
'/route'
,
message
)
return
jsonify
(
code
=
0
,
message
=
'success'
,
data
=
request
.
json
)
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__'
:
if
__name__
==
'__main__'
:
app
.
run
(
host
=
localIP
,
port
=
8900
)
app
.
run
(
host
=
localIP
,
port
=
8900
)
osc.py
View file @
3fa51d37
# -*- coding: UTF-8 -*-
import
argparse
import
argparse
import
math
import
math
import
json
import
json
...
@@ -11,62 +12,6 @@ print(socket.gethostname())
...
@@ -11,62 +12,6 @@ print(socket.gethostname())
# localIP = socket.gethostbyname(socket.gethostname()) # 得到本地ip
# localIP = socket.gethostbyname(socket.gethostname()) # 得到本地ip
print
(
'127.0.0.1'
)
print
(
'127.0.0.1'
)
def
print_volume_handler
(
unused_addr
,
args
,
volume
):
print
(
volume
.
decode
(
'utf-8'
))
print
(
"[{0}] ~ {1}"
.
format
(
args
[
0
],
volume
))
def
print_compute_handler
(
unused_addr
,
args
,
volume
):
print
(
args
)
try
:
print
(
"[{0}] ~ {1}"
.
format
(
args
[
0
],
args
[
1
](
volume
)))
except
ValueError
:
pass
def
ctrLamp
(
id
,
open
):
url
=
"http://iotadmin.bgycc.com/v2/diagnosis/device/set/"
+
id
payload
=
"{
\r\n\"
datapoint
\"
:[
\r\n\r\n\r\n
{
\r\n\"
index
\"
:0,
\r\n\"
value
\"
:"
+
open
+
"
\r\n\r\n
}
\r\n
]
\r\n
}"
headers
=
{
'Content-Type'
:
"application/json"
,
'Access-Token'
:
"OTZDOEQwREZBN0Y4RjY0NUFGRkY0NzQwMUU1NjFDNjQxNUM3MEE4QzY4N0E1QjBFQTNBM0U2QzU5OUVGNENGQw=="
}
response
=
''
print
(
response
.
text
)
def
pot1open
(
p
):
print
(
'pot1open'
)
ctrLamp
(
'1684316145'
,
'1'
)
def
pot1close
(
p
):
print
(
'pot1close'
)
ctrLamp
(
'1684316145'
,
'0'
)
def
pot2open
(
p
):
print
(
'pot2open'
)
ctrLamp
(
'1684315223'
,
'1'
)
def
pot2close
(
p
):
print
(
'pot2close'
)
ctrLamp
(
'1684315223'
,
'0'
)
def
pot3open
(
p
):
print
(
'pot3open'
)
ctrLamp
(
'1684311829'
,
'1'
)
def
pot3close
(
p
):
print
(
'pot3close'
)
ctrLamp
(
'1684311829'
,
'0'
)
def
goPage
(
p
):
def
goPage
(
p
):
url
=
"http://127.0.0.1:8089/"
+
\
url
=
"http://127.0.0.1:8089/"
+
\
str
(
json
.
loads
(
p
)[
'p'
])
+
"/"
+
str
(
json
.
loads
(
p
)[
'n'
])
str
(
json
.
loads
(
p
)[
'p'
])
+
"/"
+
str
(
json
.
loads
(
p
)[
'n'
])
...
@@ -76,8 +21,10 @@ def goPage(p):
...
@@ -76,8 +21,10 @@ def goPage(p):
def
section
(
unused_addr
,
args
):
def
section
(
unused_addr
,
args
):
print
(
args
)
print
(
args
.
decode
(
'utf-16be'
))
goPage
(
args
)
str
=
args
.
decode
(
'utf-16be'
)
.
replace
(
'䉅啃'
,
''
)
with
open
(
'test.txt'
,
mode
=
'w'
,
encoding
=
"UTF-8"
)
as
f
:
f
.
write
(
str
)
...
@@ -86,14 +33,14 @@ if __name__ == "__main__":
...
@@ -86,14 +33,14 @@ if __name__ == "__main__":
parser
.
add_argument
(
"--ip"
,
parser
.
add_argument
(
"--ip"
,
default
=
'127.0.0.1'
,
help
=
"The ip to listen on"
)
default
=
'127.0.0.1'
,
help
=
"The ip to listen on"
)
parser
.
add_argument
(
"--port"
,
parser
.
add_argument
(
"--port"
,
type
=
int
,
default
=
9000
,
help
=
"The port to listen on"
)
type
=
int
,
default
=
7001
,
help
=
"The port to listen on"
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
dispatcher
=
dispatcher
.
Dispatcher
()
dispatcher
=
dispatcher
.
Dispatcher
()
# dispatcher.map("/Page", print)
# dispatcher.map("/Page", print)
# dispatcher.map("/section", print)
# dispatcher.map("/section", print)
dispatcher
.
map
(
"/
待机"
,
print
)
dispatcher
.
map
(
"/
state"
,
section
)
print
(
args
)
print
(
args
)
server
=
osc_server
.
ThreadingOSCUDPServer
(
server
=
osc_server
.
ThreadingOSCUDPServer
(
...
...
test.txt
0 → 100644
View file @
3fa51d37
{
"ip" : "192.168.1.110",
"route" : "/首页/全国",
"volume" : 50,
"brightness" : 50,
"enableTouch" : true,
"music" : {
"isPlay" : true,
"fileIndex" : 2,
"repeat" : -1,
"volume" : 20
}
}
\ No newline at end of file
utils_log.py
0 → 100644
View file @
3fa51d37
import
os
import
time
import
logging
# log配置,实现日志自动按日期生成日志文件
def
make_dir
(
make_dir_path
):
"""
文件生成
:param make_dir_path:
:return:
"""
path
=
make_dir_path
.
strip
()
if
not
os
.
path
.
exists
(
path
):
os
.
makedirs
(
path
)
return
path
log_dir_name
=
"logs"
log_file_name
=
'logger-'
+
time
.
strftime
(
'
%
Y-
%
m-
%
d'
,
time
.
localtime
(
time
.
time
()
)
)
+
'.log'
log_file_folder
=
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
os
.
pardir
,
os
.
pardir
)
)
+
os
.
sep
+
log_dir_name
make_dir
(
log_file_folder
)
log_file_str
=
log_file_folder
+
os
.
sep
+
log_file_name
log_level
=
logging
.
INFO
handler
=
logging
.
FileHandler
(
log_file_str
,
encoding
=
'UTF-8'
)
handler
.
setLevel
(
log_level
)
logging_format
=
logging
.
Formatter
(
'
%(asctime)
s -
%(levelname)
s -
%(filename)
s -
%(funcName)
s -
%(lineno)
s -
%(message)
s'
)
handler
.
setFormatter
(
logging_format
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment