Pages

Friday 29 March 2013

Modifying multiple files in one stroke



The other day, I was working on code and felt that I had to change the date creation function and make use of SQLAlchemy's server_default = text("sysdate") from a rather bizare default = datetime.now()

so I run this;

sed -e 's/default = datetime.now()/server_default = text("sysdate")/g' -i models/*.py

and all python files were updated

Note: the letter g at the after the replacement text ensures that all instances of the
text to be replaced are actually replaced and not only the first instance if the g (global) were left out

Wednesday 6 March 2013

How to install rapidsms in Ubuntu (12.10)



RapidSMS is a free and open-source framework for dynamic data collection, logistics coordination and communication, leveraging basic short message service (SMS) mobile phone technology (according to rapidsms.org). RapidSMS is a python program built on top of django. This is a quick "how to" to have rapidsms quickly set up on an Ubuntu machine. It is seven step process.

Step 1: install python-django, python-pip.

$sudo apt-get install python-django
$sudo apt-get install python-pip

Step 2: Install rapidsms from the cheeseshop.

$sudo pip install rapidsms

If you have rapidsms installed already, then you can upgrade it:
$sudo pip install -U rapidsms

Step 3: Next install the http router

$sudo pip install rapidsms-httprouter

Step 4: Now that all is set, create a new project like so:

$cd
$rapidsms-admin.py startproject my_project

Please replace the my_project with the appropriate/desired name of your project.
Django will notice that you do not have a super user/admin account for the new project that you are creating so it will suggest that you create one. Enter the user name you desire and password. I suggest you oblige and enter these!

Step 5: Now create the db. If the name of the project in Step 4 was my_project, then;

$cd my_project

Else $cd name_of_your_newly_created_project

Now create/sync the db.
$python manage.py syncdb

Step 6: Try accessing the webUI of your newly created installation. Personally, I prefer running programs that capture my prompt using screen
So part (a) of this process is optional

(a) $screen

(b) $python manage.py runserver 0.0.0.0:8000
       or
       $python manage.py runserver

     $ Ctrl - A + D (to exit screen----you may need to read the screen manual pages)

       The first Option allows you to acess the rapidsms WebUI both locally and remotely and the second    allows you to access the rapidsms WebIU locally only. Personally, I prefer the first option because I develop most apps in VMs (Virtual Machines)

(c)  $python manage.py runrouter


You can access the admin interface that django assisted to create for you by typing this: http://your_ip_address:8000/admin. Enter the user name and password you created in Step 4.

There you are!!! You now have a barebones rapidsms installation.!!!