Lesson 10 of 18
Reusable Action Lists and Action Groups
In this lesson
To download several websites without copying actions, Roy Osherove extracts the download action into an action list, a function with a URL string parameter, and calls it with run action list actions for cnn.com and google.com, which he renames with F2 to make them more readable. He wraps the calls in an action group, a hierarchical placeholder for several actions, and notes that action lists let him maintain things in one place and see what the script does rather than how it does it.
Transcript
[00:02] (external link, opens in new tab) Okay, let's take a look at making things a bit more maintainable and scalable. I want to now get multiple websites, not just CNN. So, I could control Ctrl + C and Ctrl +V multiple times and each time to change the website here and then the website there. But each time I would also have to remember to change the name of the file here, etc. Maybe there's a better way. And the way we're going to look at is called action list or functions. So action list or function. I can right click underneath here and say create or add action list.
[00:35] (external link, opens in new tab) But I could also rightclick on this action here and say right click refactor extract actions to new action list. We'll call it download a page. Now in download a page what I'd like to do is I'd like to have two parameters. Right click add or action list parameters. Maybe just one parameter. The parameter would be the URL.
[01:07] (external link, opens in new tab) It would be of type string. So you can sorry right click action list parameters. You can see maybe I'll give it a better name PC URL. That way I have a naming convention just for the things that this action list needs. Now I'll double click the action to say okay I'll just download stuff from P URL and you could say maybe I'll I'll just replace the whole thing. I'll just assume it's always HTTP and the HTTP get only works with HTTP.
[01:39] (external link, opens in new tab) So we can assume it's always HTTP. If you want HTTPS there are other actions for downloading stuff like that but for now this is good enough for us. And I want to save it for anything called important. And again, the P URL string here. If I now save this, all that's left for me now is to go here and you see I when I refactor, I got a new run action list action.
[02:10] (external link, opens in new tab) I can find it here again. Action list. Run action list. And I can double click it. And now I have the list of variables that I can send in. So let's say CNN.com. And let's copy and send that. This time we'll say google.com. Now I can of course sorry I pressed F1 and nobody likes F1.
[02:40] (external link, opens in new tab) But I can press F2 and edit this and say this is CNN. F2 here and say this is Google to make things a bit more readable. And now if I actually try to run this, we might get a behavior that looks like oh this is running in parallel or it's running in a weird way. If you if you see that those actions are running after they should have run, you can rightclick again these two actions and say refactor
[03:11] (external link, opens in new tab) Wrap with action group. An action group is a group of actions that have to run before you finish. So if you run this now, it's just a placeholder basically. So now if we run this again, you'll see HTTP gets and then only then things run. So an action group is nothing but a placeholder, a hierarchical placeholder for us to capture multiple things. So I can for example rename this and say download web pages
[03:42] (external link, opens in new tab) And each one of them calls this function twice which just happens to have a single action in it to download a file but it uses the variables in multiple places to do things. So now I download these places, all these files and I can sorry I can rightclick on favorites. Let's go to FB demo and here I have the new files and I have new file.txt. We should have all the text here from two sites.
[04:14] (external link, opens in new tab) This is the Google stuff. This is where CNN ends. You can see that Cena is using clicktail and now we have Google. So now what we've seen is that we can use functions or action lists to reuse a piece of code and call it multiple times to make things a bit more readable and understandable.
[04:50] (external link, opens in new tab) And so we'll only have to maintain things in one place. And we there's more to this, but this is a very powerful feature of FinalBuilder. And notice that in terms of readability, I can still figure out what's going on because I can just see the what things do instead of instead of just watching how they do it. So it's very easy for me to parse things and enable or disable them as needed.