diff --git a/README.md b/README.md index 813b208..71b4605 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Python Script to Recive and Decode German BOS Information with rtl_fm and multim - Filtering double alarms with adjustable time - FMS and ZVEI validation (plausibility test) - MySQL Database Support for FMS and ZVEI +- simple HTTP request at alarm to URL you want - All configurations in seperate File "config.ini" - simple Web Frontend with Data Parsing diff --git a/boswatch.py b/boswatch.py index 824d95a..464bc91 100644 --- a/boswatch.py +++ b/boswatch.py @@ -14,12 +14,12 @@ import subprocess #import os import mysql import mysql.connector +import httplib import argparse #for parse the args import ConfigParser #for parse the config file import re #Regex - def curtime(format="%Y-%m-%d %H:%M:%S"): return time.strftime(format) @@ -126,6 +126,12 @@ try: tableFMS = config.get("MySQL", "tableFMS") tableZVEI = config.get("MySQL", "tableZVEI") tablePOC = config.get("MySQL", "tablePOC") + + #HTTPrequest config + useHTTPrequest = int(config.get("Module", "useHTTPrequest")) #use HTTPrequest support? + if useHTTPrequest: #only if HTTPrequest is active + url = config.get("HTTPrequest", "url") + except: stop_script("config reading error") exit(0) @@ -212,10 +218,18 @@ try: fms_time_old = timestamp #save last time if useMySQL: #only if MySQL is active + if args.verbose: print "FMS to MySQL" cursor = connection.cursor() cursor.execute("INSERT INTO "+tableFMS+" (time,service,country,location,vehicle,status,direction,tsi) VALUES (%s,%s,%s,%s,%s,%s,%s,%s)",(curtime(),fms_service,fms_country,fms_location,fms_vehicle,fms_status,fms_direction,fms_tsi)) cursor.close() connection.commit() + + if useHTTPrequest: #only if HTTPrequest is active + httprequest = httplib.HTTPConnection(url) + httprequest.request("HEAD", "/") + httpresponse = httprequest.getresponse() + if args.verbose: print httpresponse.status, httpresponse.reason + elif args.verbose: #Invalid error only in verbose mode print "No valid FMS: "+fms_id elif args.verbose: #crc error only in verbose mode @@ -238,14 +252,22 @@ try: zvei_time_old = timestamp #save last time if useMySQL: #only if MySQL is active + if args.verbose: print "ZVEI to MySQL" cursor = connection.cursor() cursor.execute("INSERT INTO "+tableZVEI+" (time,zvei) VALUES (%s,%s)",(curtime(),zvei_id)) cursor.close() connection.commit() - + + if useHTTPrequest: #only if HTTPrequest is active + httprequest = httplib.HTTPConnection(url) + httprequest.request("HEAD", "/") + httpresponse = httprequest.getresponse() + if args.verbose: print httpresponse.status, httpresponse.reason + elif args.verbose: #Invalid error only in verbose mode print "No valid ZVEI: "+zvei_id - except KeyboardInterrupt: - stop_script("Keyboard Interrupt") \ No newline at end of file + stop_script("Keyboard Interrupt") +except: + stop_script("other Error") \ No newline at end of file diff --git a/config.ini b/config.ini index 561ddf8..98969de 100644 --- a/config.ini +++ b/config.ini @@ -3,26 +3,35 @@ ######################## [FMS] -#time to ignore same alarm in a row in seconds +#time to ignore same alarm in a row (sek) double_ignore_time = 10 [ZVEI] -#time to ignore same alarm in a row in seconds +#time to ignore same alarm in a row (sek) double_ignore_time = 5 #can take on or off the modules (0|1) [Module] useMySQL = 0 #useAudiorecord = 0 -#useHTTPrequest = 0 +useHTTPrequest = 0 -#Data for MySQL connection [MySQL] +#Data for MySQL connection dbserver = localhost dbuser = root dbpassword = root database = boswatch +#tables in the database tableFMS = bos_fms tableZVEI = bos_zvei -tablePOC = bos_pocsag \ No newline at end of file +tablePOC = bos_pocsag + +#[Audiorecord] +#recording time (sek) +#record_time = 30 + +[HTTPrequest] +#url without http:// ! +url = www.google.de \ No newline at end of file