Anvil: Web Apps With Nothing but Python Transcripts
Chapter: Consuming the API with Fitnessd Local app
Lecture: Refactoring the client app

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Now, I don't know if you picked it up in my voice, but I was cringing a little bit while writing this because it's like
0:06 ugh, it's really just piling it all together and it's not writing really great apps. So, let's first, quickly save this to Github.
0:14 Let's save it so you can go back and sort of view the history. First version of the client, save that. And now we're going to rearrange stuff.
0:22 So, what I want to do is take the stuff that works with the API, like this save measurement or this authorize one
0:31 which one, authenticate one, I want to move those somewhere else, so let's go and create a new file, Python file
0:37 called svc, rob a few of these things over there let's go like that, and, I go that and we also need those things, the top
0:56 whoo, okay, so let's just look through this and see it's hanging together, one up a little. Yeah, so we have our authenticate and
1:03 we have our save measurement over here and those are the things that we need. Now, this, we want to say svc.
1:09 And PyCharm will happily import that up at the top there. And then we come down here, say svc.save_measurement and we say dot, right, there's our
1:19 server bits that we're going to do. And create now, if we clean this up I think that's looking really good just run it, make sure it still saves stuff.
1:34 Yep, it still saves things, great. So, we haven't broken it, we've just move it around so, if you want to work with the server stuff
1:40 you go over simply here, and you look at it and you're like, yeah, here's my server stuff. Well, that cleans it up, that moves our server side
1:46 code to one place and our user interaction code to another.


Talk Python's Mastodon Michael Kennedy's Mastodon