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
0:01 in my voice, but I was cringing a little bit
0:04 while writing this because it's like
0:05 ugh, it's really just piling it all together
0:08 and it's not writing really great apps.
0:10 So, let's first, quickly save this to Github.
0:13 Let's save it so you can go back
0:14 and sort of view the history.
0:16 First version of the client, save that.
0:19 And now we're going to rearrange stuff.
0:21 So, what I want to do is take the stuff
0:22 that works with the API, like
0:26 this save measurement or this authorize one
0:30 which one, authenticate one, I want to
0:32 move those somewhere else, so let's go
0:34 and create a new file, python file
0:36 called svc, rob a few of these things over there
0:40 let's go like that, and, I go that
0:49 and we also need those things, the top
0:55 whoo, okay, so let's just look through this
0:57 and see it's hanging together, one up a little.
1:00 Yeah, so we have our authenticate and
1:02 we have our save measurement over here
1:04 and those are the things that we need.
1:06 Now, this, we want to say svc.
1:08 And PyCharm will happily import that up at the top there.
1:13 And then we come down here, say svc.save_measurement
1:16 and we say dot, right, there's our
1:18 server bits that we're going to do.
1:21 And create now, if we clean this up
1:22 I think that's looking really good
1:25 just run it, make sure it still saves stuff.
1:33 Yep, it still saves things, great.
1:35 So, we haven't broken it, we've just move it around
1:37 so, if you want to work with the server stuff
1:39 you go over simply here, and you look at it
1:41 and you're like, yeah, here's my server stuff.
1:43 Well, that cleans it up, that moves our server side
1:45 code to one place and our user interaction code to another.