#!/usr/bin/python import time import datetime import os import subprocess import telepot from telepot.loop import MessageLoop import json import urllib2 import socket # ici remplir les indicatifs de votre relais. S'il y a deux modules spécifiez les. S'il n'y en a qu'un seul laisser vide le champ correspondant. relay = "F1ZXX " relayC = "F1ZXX C" relayB = "F1ZXX B" # Pour avoir une clé gratuite API, rendez vous sur le site : https://www.wunderground.com/weather/api/ APIwunderground = "a-remplir" # Rentrez ci-après les coordonnées de votre relais APIgps = "45.7749,4.6633" # Le token est à obtenir auprès de BotFather, suivre le tuto sur : http://www.instructables.com/id/Set-up-Telegram-Bot-on-Raspberry-Pi/ # Si vous rencontrez un problème dans la commande "Sudo pip install telepot " faire la commande "sudo pip install telepot --index-url=https://pypi.python.org/simple/" token="a-remplir-token-de-BotFather" # Suivant votre distribution, les fichiers log peuvent se trouver dans d'autres répertoires.... A vérifier. log_file="/var/log/opendv/Headers.log" links_file="/var/log/opendv/Links.log" last_in='' chan='' monitor=False def ip(): ip_address = ''; s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(("8.8.8.8",80)) ip_address = s.getsockname()[0] s.close() return ip_address def wx(): wxurl = "http://api.wunderground.com/api/"+APIwunderground+"/conditions/lang:FR/q/"+APIgps+".json" f = urllib2.urlopen(wxurl) json_string = f.read() parsed_json = json.loads(json_string.decode('UTF-8')) temp_c = parsed_json['current_observation']['temp_c'] pression = parsed_json['current_observation']['pressure_mb'] humidite = parsed_json['current_observation']['relative_humidity'] weather = parsed_json['current_observation']['weather'] weather = weather.lower() wind_kph = parsed_json['current_observation']['wind_kph'] wind_dir = parsed_json['current_observation']['wind_dir'] return "T="+str(temp_c)+"C, P="+str(pression)+" mB, Hum="+humidite+" RH, "+str(wind_kph)+' km/h '+wind_dir+' '+weather def forecast(): wx_forecast='' wxurl = "http://api.wunderground.com/api/"+APIwunderground+"/forecast10day/lang:FR/q/"+APIgps+".json" f = urllib2.urlopen(wxurl) json_string = f.read() parsed_json = json.loads(json_string.decode('UTF-8')) for i in range(0,7): wx_forecast = wx_forecast + parsed_json['forecast']['txt_forecast']['forecastday'][i]['title']+': '+ parsed_json['forecast']['txt_forecast']['forecastday'][i]['fcttext_metric']+'\r\n' return wx_forecast def dstar_links(): with open(links_file) as f: refl = 'Not' s_refl = 'Linked' rptr = 'Module' s_rptr = 'module letter' lines='' for line in f: list_of_words = line.split() refl = list_of_words[list_of_words.index('Refl:') + 1] s_refl=list_of_words[list_of_words.index('Refl:') + 2] rptr = list_of_words[list_of_words.index('Rptr:') + 1] s_rptr = list_of_words[list_of_words.index('Rptr:') + 2] lines=lines+'\n'+rptr+' '+s_rptr+' connected to : '+refl+' '+s_refl return lines def log(n): i=0 if(n==0):n=1 last_heard='' if os.path.exists(log_file): for line in reversed(open(log_file).readlines()): last=line.rstrip() words=last.split() if 'header' in words: indicativ_from=words[1+words.index('My:')] if i