Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
D
domotikad
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
domotika
domotikad
Commits
dcd83891
Commit
dcd83891
authored
8 years ago
by
Franco (nextime) Lanza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix openweathermap API and add commands to messenger bot
parent
2479dbd1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
64 additions
and
2 deletions
+64
-2
weather.py
domotika/clouds/openweathermap/weather.py
+1
-0
dmdb.py
domotika/db/dmdb.py
+10
-0
domotika.py
domotika/domotika.py
+6
-0
bot.py
domotika/web/bot.py
+47
-2
No files found.
domotika/clouds/openweathermap/weather.py
View file @
dcd83891
...
...
@@ -59,6 +59,7 @@ class OWMWeather(object):
page
=
"http://api.openweathermap.org/data/2.5/weather?q="
+
str
(
self
.
city
)
+
"&units=metric"
else
:
page
=
"http://api.openweathermap.org/data/2.5/weather?lat="
+
str
(
self
.
lat
)
+
"&lon="
+
str
(
self
.
lon
)
+
"&mode=json&units=metric"
page
+=
"&APPID="
+
str
(
self
.
owmid
)
cb
=
wu
.
getPage
(
page
,
headers
=
{
'x-api-key'
:
str
(
self
.
owmid
)})
.
addCallbacks
(
self
.
onData
,
self
.
onError
)
def
updateDatabase
(
self
):
...
...
This diff is collapsed.
Click to expand it.
domotika/db/dmdb.py
View file @
dcd83891
...
...
@@ -929,3 +929,13 @@ def getChartSeries(chartname):
return
StatsChartsSeries
.
find
(
where
=
[
"name='
%
s'"
%
str
(
chartname
)])
def
getScreenshotList
(
screenshot
=
False
):
qstring
=
"SELECT button_name FROM mediasources WHERE (websection='camera' OR websection='citophone')"
if
screenshot
:
qstring
+=
" AND screenshot IS NOT NULL"
return
runQuery
(
qstring
)
def
getVoiceCommandList
():
qstring
=
"SELECT speech_string FROM speech_actions WHERE active=1"
return
runQuery
(
qstring
)
This diff is collapsed.
Click to expand it.
domotika/domotika.py
View file @
dcd83891
...
...
@@ -2449,6 +2449,12 @@ class domotikaService(service.Service):
return
dmdb
.
getChartSeries
(
chartname
)
.
addCallback
(
self
.
parseChartSeries
,
resdata
,
chartname
)
return
defer
.
fail
(
'No chart with the name '
+
str
(
chartname
))
def
web_on_getVoiceCommandList
(
self
):
return
dmdb
.
getVoiceCommandList
()
def
web_on_getScreenshotList
(
self
,
screenshot
=
True
):
return
dmdb
.
getScreenshotList
(
screenshot
=
screenshot
)
def
web_on_getChartData
(
self
,
chartname
):
log
.
debug
(
'GET CHART DATA FOR '
+
str
(
chartname
))
return
dmdb
.
getChartData
(
chartname
)
.
addCallback
(
self
.
getChartData
,
chartname
)
...
...
This diff is collapsed.
Click to expand it.
domotika/web/bot.py
View file @
dcd83891
...
...
@@ -179,7 +179,7 @@ class MessengerBot(BotCore, MessengerCore):
if
len
(
res
)
>
0
:
if
res
[
0
]
==
'Ok'
and
len
(
res
)
>
1
:
try
:
result
=
'ho eseguito "'
+
" "
.
join
(
res
[
1
][
'clean'
]
+
'"'
)
result
=
'ho eseguito "'
+
" "
.
join
(
res
[
1
][
'clean'
]
)
+
'"'
except
:
pass
else
:
...
...
@@ -210,10 +210,17 @@ class MessengerBot(BotCore, MessengerCore):
self
.
sendMessage
(
senderid
,
'Ok, devo ancora implementare l
\'
aiuto!'
)
elif
txt
==
u'logout'
:
self
.
sendMessage
(
senderid
,
'Ok, devo ancora implementare anche il logout'
)
elif
txt
==
u'command list'
:
self
.
sendCommandList
(
senderid
)
elif
txt
==
u'screenshot list'
:
self
.
sendScreenshotList
(
senderid
)
elif
txt
.
startswith
(
'screenshot '
):
self
.
sendScreenshot
(
senderid
,
" "
.
join
(
txt
.
split
()[
1
:]))
else
:
self
.
sendMessage
(
senderid
,
'Io ci provo a dare questo comando...'
)
self
.
core
.
voiceReceived
(
txt
,
confidence
=
1.0
,
lang
=
"it"
)
.
addCallback
(
voiceResult
)
def
receivedDeliveryConfirmation
(
self
,
msg
):
log
.
info
(
"Messenger bot received delivery confirmation: "
+
str
(
msg
))
...
...
@@ -232,6 +239,28 @@ class MessengerBot(BotCore, MessengerCore):
if
status
==
u'linked'
:
self
.
core
.
add_messenger_psid
(
senderid
,
authcode
)
def
sendCommandList
(
self
,
senderid
):
def
pushList
(
res
):
for
r
in
res
:
self
.
sendMessage
(
senderid
,
" * "
+
str
(
r
[
0
]))
self
.
sendMessage
(
senderid
,
"Target list for string/voice commands (call them with the right action like up,down,open,close and so on.):"
)
self
.
core
.
getVoiceCommandList
()
.
addCallback
(
pushList
)
def
sendScreenshotList
(
self
,
senderid
):
def
pushList
(
res
):
for
r
in
res
:
self
.
sendMessage
(
senderid
,
" * "
+
str
(
r
[
0
]))
self
.
sendMessage
(
senderid
,
"Cam list:"
)
self
.
core
.
getScreenshotList
()
.
addCallback
(
pushList
)
def
sendScreenshot
(
self
,
senderid
,
target
):
def
pushImage
(
res
):
self
.
sendImageMessage
(
recipient_id
,
res
)
self
.
core
.
getScreenshot
(
target
)
.
addCallback
(
pushImage
)
def
sendMessage
(
self
,
recipient_id
,
message
):
payload
=
{
'recipient'
:
{
...
...
@@ -243,6 +272,22 @@ class MessengerBot(BotCore, MessengerCore):
}
return
self
.
sendAPI
(
payload
)
def
sendImageMessage
(
self
,
recipient_id
,
imageuri
):
payload
=
{
'recipient'
:
{
'id'
:
recipient_id
},
'message'
:
{
'attachment'
:
{
'type'
:
'image'
,
'payload'
:
{
'url'
:
imageuri
}
}
}
}
return
self
.
sendAPI
(
payload
)
def
sendAuthRequest
(
self
,
recipient_id
):
payload
=
{
'recipient'
:
{
...
...
This diff is collapsed.
Click to expand it.
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