From the course: Python Scripting Using the ArcGIS API for Python
An example script: Calculate the size of content
From the course: Python Scripting Using the ArcGIS API for Python
An example script: Calculate the size of content
- [Presenter] I'm going to walk you through a tiny script here that uses some of the objects and methods that we've learned about for managing users and user content. It's a really short script that calculates the size of all the items in my ArcGIS online account. I'm not going to put much error trapping in here, so this is just the core code. If I were going to share this with my organization, I'd really need to flesh it out a little bit, right? We're just focusing on the ArcGIS API here. So I'm going to add a cell and go out and grab my user account and hold it in a variable. I'll name that variable U g.users.me returns my account, right? Just to make sure I got it, I'll print out the username property of U. So I got my account. Now I'll go and grab all the items in my account for each item in U.items. Remember, dot items will retrieve all of the items in my account, and I'll just print each item, see that we got it. Remember, I could also just display them instead of printing them if I wanted to so I could see the little thumbnail and their item details. But really what I want is the size. Let me clear this output. So I'm going to go back up here and instead of displaying the item, I'm going to print each item and get to its top size property. Okay, so now that we can see we get the size of the items, I'll just add them up. And that's just basic Python, right? I'm going to set total size equals zero for each item in U.items. Go get that list of items. Total size plus equal each item dot size. And then I finished looping through them. So I'll just print out the total size. Right? So I'll run this, and there you go. You can see the size of all the items in my user account. This is just the tiniest script. It really doesn't go into all the details, okay? Be aware that you are only going to be seeing the size of content that's in your main highest level of your content. You're not going to see the size of content in sub folders. That's going to require a little bit more work where we put in a loop that loops through all the folders and pulls out the size of the items in those folders, which can be done. You've learned enough to do that. But I just wanted to make sure you're aware of that. Always check the ArcGIS API Help, make sure you understand exactly what these methods are going to return so you don't mislead yourself with your results.