Presentation is loading. Please wait.

Presentation is loading. Please wait.

You've heard the rumors. You've read the gossip And now, it's time...

Similar presentations

Presentation on theme: "You've heard the rumors. You've read the gossip And now, it's time..."— Presentation transcript:

1 You've heard the rumors

2 You've read the gossip

3 And now, it's time...


5 So... what? Sydewynder lets you write applications that  receive text messages  process the text  create a response  send text messages to anyone else in response

6 How? Sydewynder is a Python module You can import it like anything else It handles all the phone stuff You just write the application

7 C'mon, it's not that easy Okay, fair enough. There are some things you need to know beforehand.

8 Like what? How to read and write from a file How to use lists How to write functions How to piece together strings How to use modules

9 But we already know how to do that Yup

10 Oh

11 So, let's get down to brass tacks

12 Where do I get this module? Click on “Download Sydewynder” Download the zip file (as of now, it's‏

13 What's in the zip file? some directories  lib, doc (not important right now)‏  data (good place to put text files, etc.)‏ some files      (ignore this one for now)‏

14 What are those files? They are examples you can follow for building your own work

15 Shall we start with Yes, lets.

16 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

17 What kind of name? I mean, what is this? is like a Magic 8 Ball The script pulls a random quote from a file and returns it to anyone who sends a message

18 So, I can change it to AskBrangelina? Uh...

19 And have it return quotes from Hollywood's power couple? Well, yeah, I guess. It's up to you.

20 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”

21 “Ask Brangelina” It Is! Fine. Whatever.

22 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

23 Done. And now? Go into the data directory and open the quotes.txt file. Drop in your favorite Sven Travis quotes.

24 Brangelina quotes. Fine. Whatever.

25 So... I don't have one of those fancy Nokia phones Not a problem. Be sure to save the new script as And run it with: python

26 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

27 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

28 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

29 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

30 Huh. Looks like Yup. Most Sydewynder apps have the same guts Let's take a closer look at those before we move on

31 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

32 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

33 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

34 And methods? Think of methods as things that the class can do. So, for a Car class, methods might be: GoForward()‏ GoBack()‏ TurnLeft()‏ TurnRight()‏

35 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”

36 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()‏

37 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

38 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

39 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

40 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.

41 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

42 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

43 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

44 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

45 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

46 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

47 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

48 So I could spam everyone I know with this? Yes. Yes, you could. Not that you should. But, yes, you could.

49 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!

50 Okay. What else can I do? You can use the power of these Nokia phones to talk to the Web Open up

51 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

52 That's it? Yup. Of course, you need to find a site that will work with what you're doing, like 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!

53 Nice! What if I want to make a multiplayer game? Take a look at 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

54 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 module That's the module that makes the emulator run Just run, in your terminal: python

55 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

56 Okay, thanks for the info. I'm off! Not so fast! There's homework to be done!

57 Curses! What do I need to do? Three things  Make a Magic 8 Ball application like  Make an application that does something cool with messages received and sends them back out, like in  Make an application that can respond to commands and send to multiple people like does Bonus:  try getting data from the Web, like in, and sending the data out in messages

58 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

59 Okay, can do. Anything else? If you have any problems with getting Sydewynder to do what you want, post bugs here:  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

60 Fine. Now I really AM leaving! Good luck!

Download ppt "You've heard the rumors. You've read the gossip And now, it's time..."

Similar presentations

Ads by Google