Where do I get this module? http://sourceforge.net/projects/sydewynder/ Click on “Download Sydewynder” Download the zip file (as of now, it's sydewynder-0.1.1.zip)
What's in the zip file? some directories lib, doc (not important right now) data (good place to put text files, etc.) some files asktom.py piglatin.py roundrobin.py wefeelfine.py arcade.py (ignore this one for now)
What are those files? They are examples you can follow for building your own work
Oh, you LIAR! This is CHOCK FULL of weird code! Some, yeah, but you can ignore almost all of it First, let's start messing with this by changing the name and the title Anywhere you see AskTom, change it to a new name
What kind of name? I mean, what is this? asktom.py is like a Magic 8 Ball The script pulls a random quote from a file and returns it to anyone who sends a message
And have it return quotes from Hollywood's power couple? Well, yeah, I guess. It's up to you.
Sweet! What else? After you change any text in the file from AskTom to AskBrangelina... (3 in the code, 6 if you count comments),... look for the title variable It should be on line 39 Change that to “Ask Brangelina.” Or, you know, maybe “Ask Sven Travis”
Why does that string have a u in front of it? You mean like this? u“Ask Brangelina” The u stands for Unicode Unicode text is compatible everywhere We use it to make sure our strings work on all phones But, otherwise, it is not different from any other string
Done. And now? Go into the data directory and open the quotes.txt file. Drop in your favorite Sven Travis quotes.
So... I don't have one of those fancy Nokia phones Not a problem. Be sure to save the new script as askbrangelina.py And run it with: python askbrangelina.py
Hey! What's all this? It's an emulator An emulator is software that pretends to be another kind of system. Here, the emulator pretends to be Sydewynder running on a phone
What am I seeing here? Any line beginning with: SYDEWYNDER is just the system talking to you STATUS and LOG are what the screens on the Nokia phone show CELL PHONE is what the person with the regular phone should be doing EMULATOR is the result returned from Sydewynder to the users
Is it really sending SMS messages? No, it's faking them. But, when you move this file up onto your instructor's phone, it will work just like it does here With real SMS messages coming in and going out
Magic 8 Ball applications are not really my thing Okay, but at least you can see where to start out. Let's try doing something cooler with the text users send us. Open up piglatin.py
Huh. Looks like asktom.py Yup. Most Sydewynder apps have the same guts Let's take a closer look at those before we move on
Yeah, what is a “class”? On line 37, you'll see a class being defined It's kind of like how a function is defined, with class instead of def
What does a class do? A class is a collection of variables and functions Except we call them properties and methods when they're in a class
Why? A variable in a class is called a property because it describes the class If we made a class called Car we might have properties for: color make model year
And methods? Think of methods as things that the class can do. So, for a Car class, methods might be: GoForward() GoBack() TurnLeft() TurnRight()
Okay, but what do we do with classes? Classes are just complex variable types that you can build from scratch You can assign them to variables For example mycar = Car() The mycar variable is now a Car “object”
What do you do with the mycar object? You can assign values to its properties mycar.make = “Ford” mycar.model = “Pinto” mycar.color = “yellow” And execute its methods mycar.GoForward() mycar.TurnLeft()
Enough of this Car business. Back to the application Okay. So, when you make a Sydewynder application, you're making your own special class The class does all the things a Sydewynder application needs to do to run
So, what is this __init__ method? That's a special method in every Python class. It gets run the first time we make an object with this class. It does all the setup stuff, like setting the title property
And what is the responder method? That gets run automatically when someone sends a message to the phone It always has three parameters passed to it: self address message_text
Does it have to be called responder? No, you can make your own name for it Just be sure also to change the name in this line inside the __init__ method: super(YourApp,self).__init__(self.title,self.responder) Don't worry about what that does for now. Just change the name, if you need to.
What do those parameters mean? address is the phone number of the person who sent the message. That can be handy for all kinds of stuff message_text is the message they sent self is standard in all class methods. It stands for the object created using this class
So, self.title means? The title of object itself Any property of the class will need to have self. in front of it It's just our way of saying who this property belongs to
Okay, that seems to make sense. What else do I need? That's it as far as properties and methods You can make more properties and methods, if you need them But these alone will make things work It's up to you
So, how do messages get sent back to people? We make two lists reply_addresses = [address] responses = [SydewynderMessage(response_text,reply_addresses)] And then return the responses list
And the lists do what? reply_addresses is just a list of phone number strings you want to send a message to if the list is [address], that means you're only sending back a reply to the one original sender But you can have whatever list of phone number strings you want in there Those numbers will the recipients of the message you are sending back
And the responses list? This is a list of SydewynderMessage objects Each object gets two parameters passed to it when it is created response_text reply_addresses Which are just the text you want to send and the list of recipients
How many of these can you send out? As many as you want. If we just do this... responses = [SydewynderMessage(response_text,reply_addresses)]...we're sending one message to one person But we can make this list as long as we like
So I could spam everyone I know with this? Yes. Yes, you could. Not that you should. But, yes, you could.
Mighty! So... pig latin? There's some code in responder that messes with words and makes new strings It's not all that great or that original The point is, it can be done And it can be done better By you!
Okay. What else can I do? You can use the power of these Nokia phones to talk to the Web Open up wefeelfine.py
More of the same. Where's the Web stuff? Look at line 53 and line 60 line 53 makes a URL line 60 uses that url variable, pulls its content from the net, and assigns it to a variable
That's it? Yup. Of course, you need to find a site that will work with what you're doing, like wefeelfine.org It just returns a little bit of text with that url and not a whole web page But, with some research, you can find one... or make your own!
Nice! What if I want to make a multiplayer game? Take a look at roundrobin.py It has examples for how you can get multiple people storing data, sending commands, retrieving messages, etc. Not very useful on its own, but a good starting place for you Check out how it deals with commands And how it stores and sends messages
Okay, so, if I write something, how do I know it works? Remember, if you run it like any other Python script on your computer, it will run the emulator automatically Just make sure your script is in the same directory as the syde_emu.py module That's the module that makes the emulator run Just run, in your terminal: python yourscript.py
And if I get it to work, it will run on the phone? Yup! We'll test your applications out later in the semester For now, just keep working with them using the emulator and you'll be fine
Okay, thanks for the info. I'm off! Not so fast! There's homework to be done!
Curses! What do I need to do? Three things Make a Magic 8 Ball application like asktom.py Make an application that does something cool with messages received and sends them back out, like in piglatin.py Make an application that can respond to commands and send to multiple people like roundrobin.py does Bonus: try getting data from the Web, like in wefeelfine.py, and sending the data out in messages
That's a lot Sort of. The examples in the zip file are a good starting place, so use those as a guide Then make them much MUCH crazier
Okay, can do. Anything else? If you have any problems with getting Sydewynder to do what you want, post bugs here: http://sourceforge.net/projects/sydewynder/ http://sourceforge.net/projects/sydewynder/ Find the Bug Tracker at the bottom of the page. You'll need to create a SourceForge account, but that's handy to have anyway