Coder Social home page Coder Social logo

sunilkpokkalla / shawk Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hawkins/shawk

0.0 1.0 0.0 1.03 MB

Library to Send & Receive SMS for Free using Email or Your Phone Number

Home Page: https://shawk.now.sh/

License: MIT License

Python 24.08% CSS 64.54% JavaScript 6.62% HTML 4.77%

shawk's Introduction

Shawk Logo Shawk - Free SMS with Python using SMTP and IMAP

A Python smtplib and imapclient wrapper to send and receive SMS messages through SMS gateways with a Gmail login. Perfect for Internet of Things projects that use a Raspberry Pi to text you.

Disclaimer

This project is a work in progress, and as such, the API may change drastically before version 1.0 is reached. This repo may be out-of-sync with the PyPi version, so if you're interested in using the bleeding-edge features added since last tag, clone the repo and import locally. Tags will reflect PyPi published versions.

Installation

Shawk is available on PyPi as such:

pip install -U shawk

Documentation

To see full documentation and a more detailed Getting Started page, see here.

Contributing

I welcome all sorts of contributions - code, docs, tests, bugs, etc. If you'd like to contribute code, please make sure your tests continue to pass after making your changes. Additionally, if your new code requires any testing, please write your tests in the appropriate file.

Testing

Tests can be run with Pytest.

  1. Run pip install -U pytest to install pytest
  2. Locally install this Shawk package with pip install -e .
  3. Then simply run pytest in the root directory to execute tests

Simple Usage Example

Sending Messages

Create a Client:

Simply import shawk and define a Client by providing a Gmail username and password.

import shawk
client = shawk.Client('[email protected]', 'password')

(Optionally) Add Contacts:

Use the add_contact() function to add a contact's number as string or integer, carrier, and (optionally) a name.

some_contact = client.add_contact("5551234567", 'Carrier', 'Name')

Send SMS:

Shawk can send texts either by providing a Contact object, phone number, or name.

client.send("Message content to send", some_contact) # or contact=some_contact
client.send("Message content to send", name="Name")
client.send("Message content to send", number="5551234567")

Receiving Messages Automatically

Shawk clients can be configured to automatically refresh their inbox and report back with new messages. In this mode, Shawk will poll the IMAP server periodically and check for new messages.

To do this, create your client with the auto=True parameter, or see the docs for other methods.

client = Shawk.Client('[email protected]', 'password')
client.setup_inbox('password', auto=True)

You can also change how frequently the server is queried:

client.set_refresh_interval(30) # Period time in seconds

Each time Shawk encounters a new message, it will pass its Message object to the handler function. You can define new behaviors by creating functions with the @client.text_handler(regex, flags) or @client.contact_handler(contact) decorators.

This allows you to define certain behaviors based on who texted you or what was in the message without complicating your actual behavior logic.

For a small example:

@client.text_handler()
def handler(client, msg):
    print("Hey, we're popular! {} texted us!".format(msg.sender))
    client.send("Hello, world!", msg.sender)

You can define more complicated text_handlers and contact_handlers, but we'll save that for the docs.

shawk's People

Contributors

hawkins avatar

Watchers

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.