Blogs

Python: Introduction for Absolute Beginners

Submitted by interdocserv@ya... on Wed, 03/18/2009 - 05:26.

Excellent tutorial from the University of Cambridge for the non-tech savvy minded:

http://www-uxsup.csx.cam.ac.uk/courses/PythonAB/

USSD - alternative technology to SMS

Submitted by koit@mit.edu on Tue, 03/17/2009 - 21:45.

The alternative to SMS that I just mentioned in class is called USSD - Unstructured Supplementary Service Data, see the Wikipedia entry. Unfortunately, I didn't find anything meaningful about it in freeswitch manuals.

SMS through email, and checking your gmail account in python

Submitted by pokharel@fas.ha... on Tue, 03/17/2009 - 18:49.

Our team dealt with text messages by using the email gateways that providers provide in the US to text messages. (Look here for info: http://en.wikipedia.org/wiki/SMS_gateway)

The idea is this: you can send email from a text, and the email comes in as being from an email address that is tied to a phone. If you just reply to this address, then you will get a text message on the phone the first message was sent from. From my t-mobile phone, I text the number 500 with the message "cfa.baddate@gmail.com/no subject/some text" and the gmail account receives an email from 9703146388@tmomobile.com. When I reply to 9703146388@tmomobile.com, I get a text sent to my phone.

So really, you can treat txts as short emails, and just use a library like libgmail (libgmail.sourceforge.net) to deal with gmail. Posted is selected parts of my code that you should be able to use once you have libgmail to send emails, also known as texts if you have the right numbers.


class some_class:
def __init__(self,using_gmail = False):
self.db = load_db()
self.using_gmail = using_gmail
if self.using_gmail:
self.ga = libgmail.GmailAccount('cfa.baddate@gmail.com','CsikNadav')
self.ga.login()

def recheck_gmail(self):
if not self.using_gmail:
print "Not using gmail. Stop being absurd."
else:
print "Checking gmail for messages..\n"
folder = self.ga.getUnreadMessages()
for thread in folder:
for msg in thread:
content = self.process_email(msg.source)
send_number = msg.sender
self.process(content,send_number,datetime.datetime.now())

def text(self,number,msg):
if self.using_gmail:
gmsg = libgmail.GmailComposedMessage(number, "CFA Bad Date Report", msg)
if self.ga.sendMessage(gmsg):
print "Message sent to ",number,"\n--\n",msg,"\n--\n"
else:
print "Unable to send message to",number,"\n--\n",msg,"\n--\n"
else:
print "pretend to send message to",number,"\n--\n",msg,"\n--\n"

And here's a simple outer loop using the code (for python 2.5 "from __future__ import with_statement", should work without any mods for python 2.6)

sa = some_class(using_gmail = True)
while(True):
sa.recheck_gmail()
sa.save()
time.sleep(60)

Note: this code probably won't just work. This are just snippets of my code. Attached is the complete code. Needs a db.txt with a python dictionary.

Protecting sex-workers from violence in Tanzania

Submitted by alajous@mit.edu on Tue, 03/17/2009 - 18:37.

Description of the project

The present project has the objective of establishing a pilot experiment where two kinds of applications involving the use of cell phone technology would be used in a cohort of sex-workers in the city of Mwanza Tanzania.

The two applications are designed to provide sex workers with a private co-sex worker’s list that would benefit each member by exchanging information about their physical location when they are confronted with violent clients.

1. The system has a phone side component that is based on a count-down application which prompts the user to enter the location and number of hours she will be with the client. The information would only be distributed to a network of friends in the event that the application is not stopped. The phone would send an emergency SMS directly to a list of friends alerting them in real time about a possible danger situation.
2. The second phone side component is based on an application that allows users to send data on potential dangerous individuals to be stored in a server and the information can be retrieved by subscribers to the server list. Both types of applications require secure distribution of the information and are not designed to be used by the government services, but are available to NGOs that may provide support.

Rationale

It is well established that government based support to prevent violence is scarce and sub-optimal in Tanzania, and that community based organization is required to solve many of the problems faced in this society including violence prevention. Information regarding violence against women is hard to standardize because of underreporting. In the case of Tanzania 19% of the women in Dar es Salaam reported being subject of physical violence by someone other than their partner.(WHO, 2004). Although the information is not particular to women related to the sex industry, it does tell us something about the general context of women in the country.

According to the WHO there are several factors that increase the risk of being subjects of violence. Among them are:

− financial autonomy,
− level of empowerment and social support,
− employment status,
− the degree of economic inequality between men and women,
− and attitudes toward gender roles.

Considering these risk factors, sex-workers appear to be in a continuously precarious situation. Because of the structure of their occupation all this risks seem to be augmented by being present at the same time. Although a full-scale solution for violence would have to go deeper into the causes and solutions for these risk factors, empowerment and social support can be increased by the creation of networks and the enhancement of information sharing in the short term. We believe that the use of wireless technology can achieve this and help sex-workers reduce the risk of being subjected to gender-based violence.

Materials and Methods

We built three applications, two phone-based, and one server-based.

The server-based application is a cell-phone based social network that takes in “bad date reports” from sex workers. The bad date reports are then sent out immediately (in real time) to members of the reporter's friends (as defined by the social network—coming soon), and also logged in a database. Newcomers, and those already in the system, can make use of the database by searching it for keywords. The idea is that sex workers will enter client violence information in free-form, for example by sending a text message saying “Australian blonde named Steve tried to hit me at Joe's Bar. He was refusing to wear condoms, and got unhappy when I insisted. Joe's wife helped me sneak out the back.” A new sex worker can then come along, and search the database for this message by any of the key words, for example, “getinfo Steve” or “getinfo Australian” will get him/her the previous message that was entered.

SMS interface: Since SMS's are packaged up, and delivered via email, the server-based application is currently email based. In our tests, we were able to email to the programmer's cell-phone, by using the email gateway address of his cellphone “XXX@tmomobile.com” for a cell-phone XXX and t-mobile service carrier. The current reporting system uses cfa.baddate@gmail.com as it's sms recipient. In a field deployment, the system would want to use an actual number. This can be fed in through a GSM modem into python, and python can call a simple “process” function in our server in order to process these text messages.

Database: As the application is built as a proof of concept, the database used is a simple python dictionary that is saved in a file using the cPickle library. The cPickle library simply generates text encodings of objects. In a real implementation, one would want to use a real database like SQL to do operations.

“Social Network”: In order to determine who your friends are, there needs to be some sort of “social network” that needs to be built up on the server. The social network can be of differing varieties, and we explored three possibilities, which we can call the list-serve variety, the twitter variety, and the facebook variety. In the list-serve variety, there are entities which we can call list-serves that people can sign up to. Whenever somebody signs up to a list-serve, they become “friends” with everybody else on the list-serve. The facebook idea is that people can sign up friends directly, rather than using a list-serve as an intermediary. However, since this idea assumes that friendships are reciprocal, we would need a confirmation process. The third idea is that I can decide who's friend I am, but not who is my friend. This is the twitter idea—in that I can decide who to listen to, but not (directly) who listens to me. No confirmation is ostensibly required, but more user control needs to be built into the system.
The current system is based on the list-serve idea, again as proof of concept. The code is easy to modify into a twitter style friend network, or even a facebook-style friend network, even though that is more complicated. Two types of messages “add X” and “lists” are devoted to the implementation of the social network. “add X” adds you the sender to listserve X, and “lists” returns the list-serves that you currently belong to.

Feedback: The motivation for the server app is that it can store information that sex workers put in, and deliver it back to them in the future. The way to relay back information is again complicated, and calls for some ingenuity and experimentation. The current system simply searches all text messages for the user's query, and returns back the latest-by-date text message that has that query string in it. Other ideas could be: return the last N text messages sent regarding this query, use technologies such as SMS find to find appropriate answers, or have NGO curators looking at the database, and for each keyword (example: Australian, Steve, skinny, etc), make a summary text message that sex workers would get back when that keyword was queried. Again, the program is built to be easily modifiable to do any of the above things.

Phone-based Applications

The two phone-based applications are meant to further strengthen the sex worker community and encourage them to work together for their safety.

Emergency Callback

The first phone-based application is an Emergency Callback system modeled on a mobile phone system in use on some university campuses in the US. For example when the user is about to walk home to their dorm from a night out they enter into the mobile application the amount of time it should reasonably take them to get there. If the timer reaches the preset time limit and the user has not canceled the countdown then the system notifies campus security with their number and location and they try to call the user to see if they are alright. If no response then they go looking for the user. Our system operates in a similar manner based on a simple timer countdown. It can be used when a sex worker is walking home for the night or can be used to estimate how long they should reasonably be with a client before someone should check in on them. Because the local police are at best ignoring sex workers and at worse contributing to their abuse and exploitation our system notifies the users “social network” sending an SMS to all their friends either added locally on the phone from their list of contacts or via an SMS to the bad date reporting server which would then send out the message to the “social network”. In addition, since we cannot rely on sex workers’ cell-phones to be GPS enabled or network provided cell ID information we decided to use a simple prompt when entering the countdown time to also ask for their probable location.

Bad Date Reporting

The second phone-based application is to work in conjunction with the bad date reporting server. The open manner in which the bad date server receives reports is very useful in keeping the system flexible. However, victims of physical and sexual assault can be emotionally traumatized and have difficulty providing useful information in a strictly voluntary unprompted manner. For this reason we developed a simple cell-phone-based application that prompts the user for pertinent information about the incident.

1. Name of the client
2. Nationality of the client
3. Physical description (long hair, tattoos, etc.)
4. Location of assault
5. Date and time of assault
6. Was a weapon used? If so what kind

The above information is consolidated into an SMS with each answer separated by a delineator that is then sent to the bad date reporting server. Five or six questions seemed the appropriate number to ask, asking too many or too detailed questions can actually cause the victim to re-live the incident which can be difficult and potentially turn victims off from completing a report or using the system again in the future. Having a formatted series of questions with the answers delineated in the SMS makes the information easier to parse on the server side.

Cell phone penetration and providers in Tanzania

In Tanzania, the teledensity has been increasing from one per cent in 2000 to 25 per cent in 2008. Currently, there are six licensed mobile phone operators — Tanzania Telecommunications Company Ltd (TTCL), Zantel, Zain, Tigo, Vodacom and Benson.

Cell phones are ideal tools for a mobile team and the equipment is less likely to be stolen compared with laptops or personal digital assistants. Cell phones don’t stick out in the field because from an outside observer, it looks like a sex-workers is just making a phone call. Therefore protecting this group from possible police investigation of retaliation from violent clients.

However, there is a limitation to the use of cell phones because of the cost of the service in relation to the per capita income of the country. In fact Tanzania is one of the countries with the most expensive services according to the ITU, which calculated the cost of 25 monthly calls and 30 SMS at around 33% of the per capita income. In consequence cellphone penetration is not very high at 24 lines per 100 inhabitants.
Review of the literature on using cell phones for health interventions

Applications involving the phone and the Internet have been described previously in literature. For example, Voxiva developed Alerta, a system that involves the phone and the Internet for communication and disease surveillance. Alerta was piloted initially in health clinics of the Ministry of Health in Peru, and later in October, 2002 http://www.prevenperu.org Voxiva platform for health solutions have been deployed in Latin America, Africa, Iraq, and India. For example, in Africa, Voxiva created a national HIV/AIDS information system for eight countries that monitors current data for national and global reporting requirements, and manages the use of antiretrovirals to reduce the spread of viral resistance. In India, Voxiva created, within a month, a surveillance system for Japanese encephalitis http://www.voxiva.net/. In South Africa, the project Cell Life http://www.cell-life.org/ is using cell phones to monitor adherence for the management of HIV/AIDS in patients on antiretroviral therapy. Some of the platforms Cell Life is using include a global system for mobile communications (GSM), wireless Internet gateway (WIG), and a geographical information system (GIS) database. Karras et al. reported in the procedures of the AMIA Symposium that a Java-enabled wireless phone could be potentially used in disaster response and public health informatics. They emphasized that the technology was inherently deployable, portable and that minimal orientation to new hardware was needed since everyone was comfortable with entering numbers on a phone keypad and pushing the send button. But not often these applications in data collection emphasize that communities should have access to the data generated nor there are sufficient planning in implementing the use of the data by the communities.

Alternativa: Overcoming obstacles for non-party politics in Mexico

Submitted by alajous@mit.edu on Tue, 03/17/2009 - 17:04.

Alternativa is a political organization in Mexico that is trying to do politics outside of the party system

1. A closed political system

Although Mexico has regular elections where there is some degree of competition since the mid-nineties, access to the political system for non-professional politicians is very limited. For example to compete in any election you have to be supported by a political party, and the prerequisites to form a political party are very high. (you need around 200,000 signatures plus territorial organization in 2/3 of the country).
A the national level only political parties can legally buy access to electronic media, organizations or individuals that are not parties cannot buy time for political ads. In print media, it costs around 25, 000 dollars to buy ad space. At the local level participation in politics is inhibited by decentralized political violence and clientelism.
Three big parties control most elections throughout the country, and the few small parties that have some regional presence become appendixes of the three big parties.
Internet is not used in particularly creative ways for politics. Around 20 million people in Mexico have access to the internet, out of a 105 million. Although there are 75 million cellphone lines.

2. Alternativa

Alternativa was a political party that participated in the 2006 presidential elections with the only woman running for president, Patricia Mercado. Unexpectedly her campaign had some degree of success because it managed to link local mobilization with national politics. The campaign had very limited resources in comparison to the three big parties, but still it was able to get almost 3% of the national vote and some representation in congress.
a) In this link you can see the type of campaigning that was done. Mostly in plazas and universities with little equipment and without resources for mobilizing supporters.
http://video.google.com/videoplay?docid=952559187931430179&hl=es
b) In this other link you can se the tv ad that was made after the presidential debate. It was a famous ad because it was really cheap to make, and it used the participation of the other candidates to make a point.
http://www.youtube.com/watch?v=h8HGzV9H2_4
(If you don't speak Spanish: Patricia Mercado says, "Mexico is ready for having a woman as president" and then all the other candidates say "I agree with Patricia" all phrases which were taken from the debate where they said it regarding different topics).

3. Kicked-out!

Exactly a year ago (march 16) during a party convention to elect the new chair-person of the party, a minority in the party allied with the big parties, hired a group a thugs and beat up the group that opposed these alliances. The expelled group was not only the majority of activists, but also most of the founders including Patricia Mercado.
(If you understand Spanish you can look at the following videos made by a newspaper using images from cellphones. These videos were very important because they link the party officials with mercenaries.
http://www.youtube.com/watch?v=9IgybGM78g0
http://www.youtube.com/watch?v=GGI0Mvu6F1Q ). After they took control of the party they kicked out everyone linked to the founders of the party, and changed its name. Now these guys get the public funding.

4. What’s next?

After leaving the party, some of the founders decided to reorganize to participate in politics, but outside of the party system. In Mexico there are few examples of this, but the ones that have been done have been fairly effective (i.e. the Zapatistas). This image alternativa is of an event made by Alternativa where the “monument for the revolution” was covered on “revolution day” to represent the urge to leave traditional politics in the past. The main message was: “less partyocracy, more citizenship” (To appreciate the size of the thing, compare the size of a person, to the monument).

5. Three projects to link local mobilization with national politics.

At the moment Alternativa is trying to develop three projects centered in accountability before july 5, when mid-term elections will take place:

a) Open-space debates between candidates in some districits.
b) A public evaluation and “negative campaigning” of the worst candidates (regarding either, their past careers linked to corruption chareges, or on some particular proposals like death penalty).
c) 500 citizens, following 500 congressmen for a year. Each citizen would commit to generate and share information about a single congressman during a year.

Get it while it's hot! Free Switch!

Submitted by csik on Tue, 03/17/2009 - 05:27.

Dan has just uploaded his freeswitch tutorial:
http://src.media.mit.edu/cfa/wiki/FreeSwitchInfo

The character 'Switch' from the Matrix.

Sending SMS via Skype w/ only 6 lines of code

Submitted by hellyeah@mit.edu on Tue, 03/17/2009 - 01:44.

Hey folks,
Skype and Python got a thing going on. Here's how you start it up.
1. Download and install the Skype client.
2. Create a Skype account and buy some Skype credit (like, $10 worth).
3. Download and install Python from python.org
3. Download and install Skype4Py from Sourceforge http://sourceforge.net/projects/skype4py/
3a. Skype4Py reference is here: https://developer.skype.com/wiki/Skype4Py
4. Start Skype and log in.
5. In your Skype client, add a phone number as a SkypeOut contact.
6. Create a python file with the code below.
7. In the code below, replace the dummy phone number (+16175551212) with the number you added in step 5.
8. Run your script! Under Linux, run with superuser permissions.

[ note: for code examples, see the attached files. I just wasted an hour trying to force Drupal (this blogging software) to preserve whitespace so it doesn't destroy all python code posted. Can the admin for this blog change the whitespace settings so we can share python code here? ]


import sys, Skype4Py
api = Skype4Py.Skype() # create a Skype API instance
api.Attach() # connect to Skype
message = api.CreateSms(Skype4Py.smsMessageTypeOutgoing, '+16175551212') # create SMS object. CHANGE THE PHONE NUMBER
message.Body = "Hello World!" # set value of body
message.Send() # send message

The Skype API under Linux has one complication: it will not run when invoked by other programs such as chron or mod_python. This is because it needs access to the XServer environment variables. My solution to this is to create a little Skype relay server that is invoked on the command line and runs perpetually. Other programs can send SMS messages by sending message data to the relay server via a UDP socket. The example below simply receives a message body (via UDP) and sends it (via the Skype API) to a hard-coded phone number list.

SkypeRelayServer.py:

import sys
import Skype4Py
import socket
api = Skype4Py.Skype() # create a Skype API instance
api.Attach() # connect to Skype
HOST = 'localhost' # The remote host
PORT = 52007 # The same port as used by the client
ipSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # create network socket
ipSock.bind((HOST, PORT)) # bind socket to host/port
ipSock.listen(1) # start listenin'
while 1: # do this forever (until program is terminated)
ipConn, ipAddr = ipSock.accept() # wait here until remote client program connects
body_str = ipConn.recv(160) # receive up to 160 characters from remote client program. this will be the SMS message body
pNums_l = ['+16175551212'] # list of phone numbers to send SMS to. in this case, only one number
for pNum_str in pNums_l: # loop through phone number list
message = api.CreateSms(Skype4Py.smsMessageTypeOutgoing, pNum_str) # create SMS object
message.Body = body_str # set value of body
message.Send() # send message
s.shutdown(socket.SHUT_RDWR) # do some network socket housekeeping.
s.close() # housekeeping

Here is an example of a client script that uses SkypeRelayServer.py to send SMS messages. It's a python script in the mod_python environment that reads an SMS message string submitted from a Web form and sends the data to SkypeRelayServer.py to be broadcast via SMS.


from mod_python import apache
from mod_python import util
import sys
import os
import socket
import time
def handler(req):
HOST = 'localhost' # The remote host
PORT = 52007 # The same port as used by the server
ipSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # create network socket
ipSock.settimeout(600)
ipSock.connect((HOST, PORT)) # connect to SkypeRelayServer.py
body_str = util.FieldStorage(req).list[0].value # get the value of the submitted SMS message body
ipSock.send(body_str) # send SMS message body to SkypeRelayServer.py
ipSock.shutdown(socket.SHUT_RDWR) # housekeeping
ipSock.close() # housekeeping
util.redirect(req, "send.html") # redirect the browser back to the Web form
return apache.OK # tell Apache this script is finished

Liberia’s Blackboard Blogger

Submitted by hellyeah@mit.edu on Tue, 03/17/2009 - 00:07.

Great article: http://www.afrigadget.com/2009/03/13/liberias-blackboard-blogger/

Alfred Sirleaf is an analog blogger. He take runs the “Daily News”, a news hut by the side of a major road in the middle of Monrovia. He started it a number of years ago, stating that he wanted to get news into the hands of those who couldn’t afford newspapers, in the language that they could understand.

Alfred serves as a reminder to the rest of us, that simple is often better, just because it works. The lack of electricity never throws him off. The lack of funding means he’s creative in ways that he recruits people from around the city and country to report news to him. He uses his cell phone as the major point of connection between him and the 10,000 (he says) that read his blackboard daily.

Brilliant response to censorship

Submitted by shyamprasads@cdm.com on Fri, 03/13/2009 - 04:21.

Though NYT doesn’t really tell you the dirty part, a bit of googling does!

http://www.nytimes.com/2009/03/12/world/asia/12beast.html?scp=1&sq=mud%2...