
On 26 June 2012 09:27, Martin Chiteri <martin.chiteri@gmail.com> wrote:
Hello Wilson,
On Mon, Jun 25, 2012 at 5:14 PM, Thuo Wilson <lixton@gmail.com> wrote:
Hello Python coders,
Analyze this;
#!/usr/bin/env python # sample script to show how to same SMS to multiple recipients
import gammu import sys
# Check parameters count if len(sys.argv) < 3 or sys.argv[1] in ['--help', '-h', '-?']: print 'Usage: mass-sms <TEXT> [number]...' sys.exit(1)
# Configure Gammu sm = gammu.StateMachine() sm.ReadConfig() sm.Init()
# Prepare SMS template message = {'Text': sys.argv[1], 'SMSC': {'Location': 1}} # HELP ME HERE
# Send SMS to all recipients on command line for number in sys.argv[1:]: #and here i guess message['Number'] = number try: sm.SendSMS(message) except Exception, exc: print 'Sending to %s failed: %s' % (number, exc)
My issue is simple but not sure how to work on it;
I have some texts here;
/usr/bin/python mass-sms.py "*we are smart people*" `cat /root/numbers.txt`
I want to send the message "We are smart people" to the number in numbers.txt (some cellphone)
My problem is i can only read the first word "we" when i have sys.argv[1], which is OK, sys.argv[1:], i have anything later than and so on...
I think the problem is, as you have figured out, that the parameters collected from the command line are taken in as tuples and accessing them by indexes only gives a part of the string required and not the entire input.
I will suggest you try out the package *argparse* for the job [ http://docs.python.org/dev/library/argparse.html ]. I have used it before and it is pretty easy to specify the data types of arguments expected from the user terminal (ints, floats, strings). I can try it out later on in the day and see if it will work with your problem.
Martin.
Thanks, looking forward.
How can i read a file using this and output texts like "*we are smart
people"* to the above eg;
/usr/bin/python mass-sms.py `cat sometext` `cat /root/numbers.txt`
Hope am clear.
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke ------------ List info, subscribe/unsubscribe http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------
Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke ------------ List info, subscribe/unsubscribe http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------
Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke