Форум сайта python.su
Читаю смс таким кодом с установленным sl4a
import android droid = android.Android() msgs = droid.smsGetMessages(False) print(msgs.result)
Офлайн
А гугл сейчас не в моде?
Вот пример
'''MODULE: loggers.py This module is special logger handler for sending emails and SMS on logger event. For use on android. needs testing. Please edit Usage: handler=maillog.Notifier()''' import logging import time import logging.handlers as handlers from threading import Thread from logging.handlers import TimedRotatingFileHandler import multiprocessing as mp email = 'yo...@gmail.com' topic = '[TOPIC]' phonenumber= '+38063000000' class SizedTimedRotatingFileHandler(handlers.TimedRotatingFileHandler): """ Handler for logging to a set of files, which switches from one file to the next when the current file reaches a certain size, or at certain timed intervals """ def __init__(self, filename, mode='a', maxBytes=1000000, backupCount=0, encoding=None, delay=0, when='h', interval=1, utc=False): # If rotation/rollover is wanted, it doesn't make sense to use another # mode. If for example 'w' were specified, then if there were multiple # runs of the calling application, the logs from previous runs would be # lost if the 'w' is respected, because the log file would be truncated # on each run. if maxBytes > 0: mode = 'a' handlers.TimedRotatingFileHandler.__init__( self, filename, when, interval, backupCount, encoding, delay, utc) self.maxBytes = maxBytes def shouldRollover(self, record): """ Determine if rollover should occur. Basically, see if the supplied record would cause the file to exceed the size limit we have. """ if self.stream is None: # delay was set... self.stream = self._open() if self.maxBytes > 0: # are we rolling over? msg = "%s\n" % self.format(record) self.stream.seek(0, 2) #due to non-posix-compliant Windows feature if self.stream.tell() + len(msg) >= self.maxBytes: return 1 t = int(time.time()) if t >= self.rolloverAt: return 1 return 0 def sendmail(record): try: import android droid = android.Android() droid.sendEmail(email, topic+str(record)[0:30], record)#sending first 30 chars of message in topic except Exception as err: logging.exception(err) def sendsms(record): try: import android droid = android.Android() droid.smsSend(phonenumber ,record) except Exception as err: logging.exception(err) class Notifier(logging.Handler): def emit(self, record): try: '''PUT HERE YOUR CODE TO WRITE LOG AND THEN OPEN LOG IN FILE OR TO SHOW POPUP USING KIVY OR P4A FACADE. IF USING MULTIPROCESSING IT'S MUCH HARDER TO KILL YOUR PROGRAM BY UNHANDLED ERROR IF ERROR IS NOT IN MAIN THREAD.''' thread = Thread(target=sendmail, args=(record)) thread.start() thread = Thread(target=sendsms, args=(record)) thread.start() except (KeyboardInterrupt, SystemExit): raise except: self.handleError(record) class loopchekerFilter(logging.Filter): '''prevents from logoverflow on continuous error log''' oldrecord = None i = None def filter(self, record): if self.i > 10: return False if self.i == 10: # I use another optional handler here to record message (you can put your own action) you need to create "critical" handler before using next line: critical.error('Entered logger continuous loop..aborting logging') self.i+=1 return False if str(record) == str(self.oldrecord): self.i+=1 self.oldrecord = record return True if str(record) != str(self.oldrecord): self.i=0 self.oldrecord = record return True logger = mp.log_to_stderr(logging.DEBUG) hdlr1 = SizedTimedRotatingFileHandler('logs/program.log', when='d', backupCount=7, maxBytes=1000000)#filename, interval = each day, delete 7 days old files format1 = logging.Formatter('%(asctime)s--- %(processName)-12s %(levelname)-8s>> %(message)s') hdlr1.setFormatter(format1) logger.addHandler(hdlr1) logger.addFilter(loopchekerFilter())
Отредактировано terabayt (Март 2, 2014 00:31:12)
Офлайн
1.видел
2.не отличается от моего кода
Офлайн
На форуме написано что под Kivy.
Офлайн
Вернулся на sl4a
Офлайн
Ну что получилось читать ?
Офлайн
Kivy умеет общаться с андроид через библиотеку plyer, вот документация http://plyer.readthedocs.org/en/latest/
Офлайн
sanodin
Читаю смс таким кодом с установленным sl4a
Офлайн
Жители форума, может кто поможет. Думал протестить Python на смски с модема GSM, но не получается, с библиотеками не лады - http://goo.gl/SGmUyc. Кто, что знает про gammu-smsd?
Офлайн