Compare commits
No commits in common. "37f8fe580d813474afe89d3aaf19ea0d4de8b759" and "531fff4c10e1e6a2be5b20f79061d4d03b3c692c" have entirely different histories.
37f8fe580d
...
531fff4c10
@ -1,7 +1,7 @@
|
||||
## connect via SSH
|
||||
|
||||
|
||||
# Useful commands
|
||||
#
|
||||
- see connected usb devices
|
||||
- lsusb
|
||||
- arecord -l
|
||||
@ -24,10 +24,3 @@ pcm.mic {
|
||||
pcm "hw:1,0"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
44200 sampling rate
|
||||
5 secs
|
||||
230000 array length
|
||||
|
||||
|
||||
|
@ -1,15 +1,15 @@
|
||||
from numpy import*
|
||||
from scipy.io.wavfile import read
|
||||
from scipy.io.wavfile import write
|
||||
# import matplotlib.pyplot as plt
|
||||
import matplotlib.pyplot as plt
|
||||
import scipy
|
||||
import sounddevice as sd
|
||||
import time
|
||||
|
||||
# a = read("/home/jreinking/Projekte/doorbell/raspberry-pi-projects/res/klingel_aufnahme_microphne_cut.wav")
|
||||
a = read("/home/jreinking/Projekte/doorbell/raspberry-pi-projects/res/klingel_aufnahme_microphne_cut.wav")
|
||||
# print(a)
|
||||
# print(len(a[1]))
|
||||
# a = a[1]
|
||||
a = a[1]
|
||||
|
||||
def chunks(lst, n):
|
||||
"""Yield successive n-sized chunks from lst."""
|
||||
|
@ -1,18 +0,0 @@
|
||||
import telegram_notifier
|
||||
import logging
|
||||
|
||||
# telegram bot ---
|
||||
TELEGRAM_TOKEN_ID = '1150602533:AAGSmPC0nGDYwiLQkkIlDheMzwR4TGv--sU' # token-id
|
||||
TELEGRAM_CHAT_ID = '291512617' # chat-id
|
||||
# ----------------
|
||||
|
||||
def send_notifaction(timestamp):
|
||||
# - - - - - - - - - -
|
||||
# Telegram notification:
|
||||
msg = "Es hat geklingelt um {}".format(timestamp)
|
||||
telegram_notifier.basic_notifier(logger_name='training_notifier',
|
||||
token_id=TELEGRAM_TOKEN_ID,
|
||||
chat_id=TELEGRAM_CHAT_ID,
|
||||
message=msg,
|
||||
level=logging.INFO)
|
||||
|
@ -1,14 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import unittest
|
||||
|
||||
import telegram_bot
|
||||
import datetime
|
||||
|
||||
class TestGetDataFromRKI(unittest.TestCase):
|
||||
|
||||
def test_send_notifaction(self):
|
||||
timestamp = datetime.datetime.now()
|
||||
telegram_bot.send_notifaction(timestamp)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
@ -1,92 +0,0 @@
|
||||
# Copyright 2019 Gabriele Valvano
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""
|
||||
Inspired by: https://www.marcodena.it/blog/telegram-logging-handler-for-python-java-bash/
|
||||
|
||||
1) Search the "BotFather" on Telegram. This is the official bot that allows you to create other bots.
|
||||
2) Create new bot: /newbot
|
||||
3) Choose a name for your bot: ScriptNotifier
|
||||
4) Choose a username for your bot that must end with "_bot": script_notifier_bot
|
||||
5) Once the bot is created, you will have a long string that is the TOKENID
|
||||
6) The bot will send you messages on a specific chat, that you need to create. Go to Telegram search bar, on your
|
||||
smartphone, and search your bot. Then, start the bot: /start
|
||||
7) Now you are ready to use a command line code to send your first notification:
|
||||
"curl -s -X POST https://api.telegram.org/bot[TOKENID]/sendMessage -d chat_id=[ID] -d text="Hello world" "
|
||||
|
||||
|
||||
- - - - - - -
|
||||
bot page:
|
||||
https://api.telegram.org/bot[TOKENID]/getUpdates
|
||||
- - - - - - -
|
||||
bot info:
|
||||
curl -X GET https://api.telegram.org/bot[TOKENID]/getMe
|
||||
- - - - - - -
|
||||
send message to the bot:
|
||||
curl -s -X POST https://api.telegram.org/bot[TOKENID]/sendMessage -d chat_id=[ID] -d text="Hello world"
|
||||
|
||||
"""
|
||||
|
||||
import requests
|
||||
from logging import Handler, Formatter
|
||||
import logging
|
||||
|
||||
|
||||
class RequestsHandler(Handler):
|
||||
|
||||
def __init__(self, token_id, chat_id):
|
||||
super().__init__()
|
||||
self.token_id = token_id
|
||||
self.chat_id = chat_id
|
||||
|
||||
def emit(self, record):
|
||||
log_entry = self.format(record)
|
||||
payload = {
|
||||
'chat_id': self.chat_id,
|
||||
'text': log_entry,
|
||||
'parse_mode': 'HTML'
|
||||
}
|
||||
return requests.post("https://api.telegram.org/bot{token}/sendMessage".format(token=self.token_id),
|
||||
data=payload).content
|
||||
|
||||
|
||||
class LogstashFormatter(Formatter):
|
||||
def __init__(self):
|
||||
super(LogstashFormatter, self).__init__()
|
||||
|
||||
def format(self, record):
|
||||
# time = strftime("%d/%m/%Y, %H:%M:%S")
|
||||
# return "<b>{datetime}</b>\n{message}".format(datetime=time, message=record.msg)
|
||||
return "{message}".format(message=record.msg)
|
||||
|
||||
|
||||
def basic_notifier(logger_name, token_id, chat_id, message, level=logging.INFO):
|
||||
logger = logging.getLogger(logger_name)
|
||||
logger.setLevel(level)
|
||||
|
||||
handler = RequestsHandler(token_id=token_id, chat_id=chat_id)
|
||||
formatter = LogstashFormatter()
|
||||
handler.setFormatter(formatter)
|
||||
logger.addHandler(handler)
|
||||
|
||||
logger.setLevel(level)
|
||||
logger.info(message)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
l_name = 'trymeApp'
|
||||
l_msg = 'We have a problem'
|
||||
t_id = 'insert here your token id'
|
||||
c_id = 'insert here your chat id'
|
||||
basic_notifier(logger_name=l_name, token_id=t_id, chat_id=c_id, message=l_msg)
|
||||
|
Loading…
x
Reference in New Issue
Block a user