GithubHelp home page GithubHelp logo

rtulke / sms.py Goto Github PK

View Code? Open in Web Editor NEW

This project forked from herval/sms.py

0.0 2.0 0.0 98 KB

GSM Modem Adapter for Python (send and receive SMS using a regular GSM Modem)

Home Page: http://pypi.python.org/pypi/sms

sms.py's Introduction

SMS
===

The sms package provides sms capabilities for Enfora gsm modems, and
probably others. I developed this package for my location-specific
nature haiku by sms project N8R TXT (http://n8rtxt.org/).

The sms package provides Modem and Message classes for sending and
receiving sms message.

The `sms.server` module provides two servers that allow you to
dispatch incoming sms messages. The `sms.echo` module is an example
that works with the `sms.server.subprocess_server`.

Usage
-----

Create a modem object passing it the serial device ID. On windows this
would be something like 'COM1'. The example below is for mac and
linux:

    >>> import sms
    >>> m = sms.Modem('/dev/ttyS0')

You can have use several modem objects concurrently if you have more
than one modem attached to different serial ports.

To send a sms message call the send method, passing a phone number
string and a message string.

    >>> m.send('14161234567', 'This is a message')

If an error occurs a ModemError will be raised with the error message.

    >>> m.send('14161234567', 'This is a message')
    Traceback (most recent call last):
    ...
    ModemError: ['ERROR']

You can retrieve sms messages with the messages() method. It returns a
sequence of message objects.

    >>> m.messages()
    [<sms.Message object at 0x...>]

Message objects have a couple attributes: number, date, and text.

    >>> msgs = m.messages()
    >>> msgs[0].number
    '+16476186676'

    >>> msgs[0].date
    datetime.datetime(2008, 7, 11, 11, 2, 11)

    >>> msgs[0].text
    'Activation code 63966 Go 2 www.ipipi.com and signin with  your username and pwd, enter 63966 to activate your mobile/account\n\nWelcome 2 ipipi.com'

After you receive messages you'll want to delete them from the SIM
card. This is done by calling the delete method on the messages.

    >>> msgs[0].delete()

Rather than polling the modem to find messages you can call the wait()
method, which blocks until a message is received. The wait method
takes an optional timeout argument.

    >>> m.wait(1) # waiting with 1 timeout

    >>> m.wait() # waiting with no timeout

The wait message doesn't return anything. You should call the
messages() method after it returns to receive the messages. Note that
it's possible that there may in fact be no messages available after
the wait method returns.

sms.py's People

Contributors

herval avatar

Watchers

Robert Tulke avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.