smsghussd Documentation

Similar documents
Roman Numeral Converter Documentation

Python wrapper for Viscosity.app Documentation

Python Project Example Documentation

TPS Documentation. Release Thomas Roten

Python simple arp table reader Documentation

Aircrack-ng python bindings Documentation

PyCRC Documentation. Release 1.0

chatterbot-weather Documentation

Simple libtorrent streaming module Documentation

I2C LCD Documentation

sainsmart Documentation

Release Nicholas A. Del Grosso

django-idioticon Documentation

google-search Documentation

django-reinhardt Documentation

Redis Timeseries Documentation

Django Wordpress API Documentation

Release Fulfil.IO Inc.

Google Domain Shared Contacts Client Documentation

Poulpe Documentation. Release Edouard Klein

Simple Binary Search Tree Documentation

Python Schema Generator Documentation

DNS Zone Test Documentation

django-cas Documentation

Pykemon Documentation

dj-libcloud Documentation

OpenUpgrade Library Documentation

Poetaster. Release 0.1.1

Python State Machine Documentation

smartfilesorter Documentation

gunny Documentation Release David Blewett

withenv Documentation

PyZillow Documentation

eventbrite-sdk-python Documentation

Mantis STIX Importer Documentation

Frontier Documentation

Game Server Manager Documentation

pydrill Documentation

open-helpdesk Documentation

django-users2 Documentation

Python AMT Tools Documentation

doconv Documentation Release Jacob Mourelos

nacelle Documentation

AnyDo API Python Documentation

API Wrapper Documentation

Python AutoTask Web Services Documentation

Python State Machine Documentation

django CMS Export Objects Documentation

lazy-object-proxy Release 1.3.1

yardstick Documentation

PyCon APAC 2014 Documentation

django-responsive2 Documentation

Python data pipelines similar to R Documentation

Gearthonic Documentation

Python Finite State Machine. Release 0.1.5

django-telegram-bot Documentation

e24paymentpipe Documentation

pyldavis Documentation

django-private-chat Documentation

Aldryn Installer Documentation

Release Ralph Offinger

Job Submitter Documentation

xmljson Documentation

dublincore Documentation

gpib-ctypes Documentation

cwmon-mysql Release 0.5.0

ejpiaj Documentation Release Marek Wywiał

django-stored-messages Documentation

pytest-benchmark Release 2.5.0

Release Manu Phatak

Dragon Mapper Documentation

CID Documentation. Release Francis Reyes

syslog-ng Apache Kafka destination

django-composite-foreignkey Documentation

pvl Documentation Release William Trevor Olson

invenio-formatter Documentation

django-composite-foreignkey Documentation

xmodels Documentation

invenio-groups Documentation

Airoscript-ng Documentation

OTX to MISP. Release 1.4.2

Archan. Release 2.0.1

django-bootstrap3 Documentation

Microlab Instruments Documentation

dicompyler-core Documentation

Connexion Sqlalchemy Utils Documentation

Infoblox Client Documentation

MT940 Documentation. Release Rick van Hattem (wolph)

ProxySQL Tools Documentation

Durga Documentation. Release dev2. transcode

redis-lock Release 3.2.0

Django MFA Documentation

Lazarus Documentation

mlpy Documentation Release Astrid Jackson

timegate Documentation

django simple pagination Documentation

python-hologram-api Documentation

otree Virtual Machine Manager Documentation

Face Recognition Documentation

Regressors Documentation

Transcription:

smsghussd Documentation Release 0.1.0 Mawuli Adzaku July 11, 2015

Contents 1 How to use 3 2 Author 7 3 LICENSE 9 3.1 Contents:................................................. 9 3.2 Feedback................................................. 13 i

ii

Python library for writing USSD applications that run on the SMSGH USSD platform. Contents 1

2 Contents

CHAPTER 1 How to use To use smsghussd in a project import os import sys import datetime from flask import Flask, request, jsonify from smsghussd import ( Ussd, UssdHandler, UssdResponse, UssdTypes, UssdStore, UssdMenu, UssdMenuItem, UssdForm, UssdOption, UssdInput ) class UssdGreeting(UssdHandler): def session_start(self): menu = UssdMenu(header="Welcome", footer="by SMSGH") \.add_item("greet me", "greeting_form") \.add_item("what's the time?", "time") \.add_zero_item("exit", "exit") return self.render_menu(menu) def greeting_form(self): form = UssdForm("Greet Me!", "greeting")\.add_input(ussdinput("name")) \.add_input(ussdinput("sex")) \.option("m", "Male") \.option("f", "Female") return self.render_form(form) def greeting(self): dt = datetime.datetime.now() hour = dt.hour if hour < 12: greeting = "Good Morning" elif hour >= 12: greeting = "Good Afternoon" elif hour >= 18: greeting = "Good Evening" name = self.form_data["name"] 3

prefix = "Master" if self.form_data["sex"] == "M" else "Madam" return self.render("{0}, {1} {2}!".format(greeting, prefix, name)) def time(self): now = datetime.datetime.now() return self.render("{0}".format(now)) def exit(self): return self.render("bye bye!") app = Flask( name ) # instantiate the handler ussd_service = Ussd(handler=UssdGreeting) @app.route("/ussd", methods=["post"]) def ussd_handler(): ussd_response = ussd_service.process( request.get_json(force=true) ) resp = jsonify(ussd_response.to_dict()) return resp if name == ' main ': app.run(host='0.0.0.0', port=8080, debug=true) @app.route("/ussd", methods=["post"]) def ussd_handler(): ussd_response = ussd_service.process( request.get_json(force=true) ) resp = jsonify(ussd_response.to_dict()) return resp if name == ' main ': app.run(host='0.0.0.0', port=8080, debug=true) Save the code as hello.py and run it $ python hello.py * Running on http://localhost:8080/ TODO [x] Implement core USSD processing pipeline [x] USSD menu and input rendering [x] USSD form processing [x] Data store for sessions etc [] Tests with USSD mocker and automated tests [x] Documentation [x] Example app 4 Chapter 1. How to use

[x] Upload to PyPi [x] USSD base controller Add support for using an switching between different handlers and callbacks 5

6 Chapter 1. How to use

CHAPTER 2 Author Mawuli Adzaku <mawuli.ypa@gmail.com> 7

8 Chapter 2. Author

CHAPTER 3 LICENSE MIT 3.1 Contents: 3.1.1 Installation At the command line either via easy_install or pip: $ easy_install smsghussd $ pip install smsghussd Or, if you have virtualenvwrapper installed: $ mkvirtualenv smsghussd $ pip install smsghussd 3.1.2 Usage To use smsghussd in a project: import os import sys import datetime from flask import Flask, request, jsonify BASE_PATH = os.path.abspath(os.path.dirname( file )) sys.path.append(os.path.dirname(base_path)) from smsghussd import ( Ussd, UssdHandler, UssdResponse, UssdTypes, UssdStore, UssdMenu, UssdMenuItem, UssdForm, UssdOption, UssdInput ) class UssdGreeting(UssdHandler): def session_start(self): menu = UssdMenu(header="Welcome", footer="by SMSGH") \.add_item("greet me", "greeting_form") \ 9

.add_item("what's the time?", "time") \.add_zero_item("exit", "exit") return self.render_menu(menu) def greeting_form(self): form = UssdForm("Greet Me!", "greeting")\.add_input(ussdinput("name")) \.add_input(ussdinput("sex")) \.option("m", "Male") \.option("f", "Female") return self.render_form(form) def greeting(self): dt = datetime.datetime.now() hour = dt.hour if hour < 12: greeting = "Good Morning" elif hour >= 12: greeting = "Good Afternoon" elif hour >= 18: greeting = "Good Evening" name = self.form_data["name"] prefix = "Master" if self.form_data["sex"] == "M" else "Madam" return self.render("{0}, {1} {2}!".format(greeting, prefix, name)) def time(self): now = datetime.datetime.now() return self.render("{0}".format(now)) def exit(self): return self.render("bye bye!") app = Flask( name ) # instantiate the handler ussd_service = Ussd(handler=UssdGreeting) @app.route("/ussd", methods=["post"]) def ussd_handler(): ussd_response = ussd_service.process( request.get_json(force=true) ) resp = jsonify(ussd_response.to_dict()) return resp if name == ' main ': app.run(host='0.0.0.0', port=8080, debug=true) Save the code as hello.py and run it: 10 Chapter 3. LICENSE

$ python hello.py * Running on http://localhost:8080/ 3.1.3 Contributing Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given. You can contribute in many ways: Types of Contributions Report Bugs Report bugs at https://github.com/mawuli/smsghussd/issues. If you are reporting a bug, please include: Your operating system name and version. Any details about your local setup that might be helpful in troubleshooting. Detailed steps to reproduce the bug. Fix Bugs Look through the GitHub issues for bugs. Anything tagged with bug is open to whoever wants to implement it. Implement Features Look through the GitHub issues for features. Anything tagged with feature is open to whoever wants to implement it. Write Documentation smsghussd could always use more documentation, whether as part of the official smsghussd docs, in docstrings, or even on the web in blog posts, articles, and such. Please follow the Google Style Python DocStrings Submit Feedback The best way to send feedback is to file an issue at https://github.com/mawuli/smsghussd/issues. If you are proposing a feature: Explain in detail how it would work. Keep the scope as narrow as possible, to make it easier to implement. Remember that this is a volunteer-driven project, and that contributions are welcome :) 3.1. Contents: 11

Get Started! Ready to contribute? Here s how to set up smsghussd for local development. 1. Fork the smsghussd repo on GitHub. 2. Clone your fork locally: $ git clone git@github.com:your_name_here/smsghussd.git 3. Create a branch for local development: $ git checkout -b name-of-your-bugfix-or-feature Now you can make your changes locally. 4. When you re done making changes, check that your changes pass style and unit tests, including testing other Python versions with tox: $ tox To get tox, just pip install it. 5. Commit your changes and push your branch to GitHub: $ git add. $ git commit -m "Your detailed description of your changes." $ git push origin name-of-your-bugfix-or-feature 6. Submit a pull request through the GitHub website. Pull Request Guidelines Before you submit a pull request, check that it meets these guidelines: 1. The pull request should include tests. 2. If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst. 3. The pull request should work for Python 2.6, 2.7, and 3.3, and for PyPy. Check https://travisci.org/mawuli/smsghussd under pull requests for active pull requests or run the tox command and make sure that the tests pass for all supported Python versions. Tips To run a subset of tests: $ py.test test/test_smsghussd.py 3.1.4 History 0.1.0 (2015-06-16) First release on PyPI. 12 Chapter 3. LICENSE

3.2 Feedback If you have any suggestions or questions about smsghussd feel free to email me at mawuli.ypa@gmail.com. If you encounter any errors or problems with smsghussd, please let me know! Open an Issue at the GitHub http://github.com/mawuli/smsghussd main repository. 3.2. Feedback 13