gnuradionetwork/parrot.py

48 lines
1.2 KiB
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import with_statement
from frn.protocol.client import FRNClient, FRNClientFactory
class FRNParrot(FRNClient):
def on_SMS(self, msg):
print "Messaggio %s da %s: %s" % (msg[2], msg[0], msg[1])
if msg[2][0] == 'P': # Risponde solo ai messaggi privati
self.send_SMS(msg[0], msg[1])
def on_AUDIO(self, from_id, frames):
print "AUDIO from %d (%d bytes)" % (from_id, len(frames))
with file('rx-%d.gsm' % from_id, 'ab') as f:
f.write(frames)
class FRNParrotFactory(FRNClientFactory):
protocol = FRNParrot
if __name__ == '__main__':
import sys
from ConfigParser import ConfigParser
from twisted.internet import reactor
cfg = ConfigParser()
cfg.read('stations.conf')
if len(sys.argv) > 1:
station = sys.argv[1]
else:
stations = cfg.sections()
stations.sort()
station = cfg.sections()[0]
print "Profile not specified: using '%s'" % station
station_conf = dict(cfg.items(station))
reactor.connectTCP('master.freeradionetwork.it', 10024,
FRNParrotFactory(**station_conf))
reactor.run()
# vim: set et ai sw=4 ts=4 sts=4: