in reply to Re^2: Next 50 array elements during each loop?
in thread Next 50 array elements during each loop?

Ive been programmatically watching my view counts since 2007. Since they just changed the API yet again and I had to modify the code again it stood out. I am currently checking about 1000 videos a few times an hour.

Since you dont use LWP::UserAgent and so dont have access to the return code you need to test for valid json, i do that via the eval to trap the die signal. It is not uncommon for the api to barf or timeout and return improper json.

For the same reasons you also need to test for the error case where no items array gets returned. While not as common as barfing there have been times the api seems to have forgotten that statistics was a valid part for a while.

And if a video gets deleted or marked private there will be no entry in the items array for that video, so the hash containing the id and count is useful. And as i pointed out at times the order of the items array has also gotten changed from the order i asked for, so the id/viewcount hash is also useful in that case rather than rely on a 1-1 correspondence to the asking order that your counts array only provides.

Another thing to be aware of is negative deltas on the view count. It seems at times they will back out some update and the delta will be negative, then an hour or so later they will reapply that transaction set and cancel it out. Negative deltas can also happen if they decide views were programmatically generated somehow.

In regards to versioning you may wish to consider some versioning system instead of relying on copies. They made me use CVS at work about 17 years ago, so ive been using it at home since then as well. I dont do fancy things with it so i havent felt any need to move to one of the more fancy systems like git and loose my prior history. I commit whenever i have decently working code and that allows me to back out changes or see what i have changed since the last commit. It also allows me to test on one box and then easily roll out the updates to the "production" box when i am finished. And as i have a mixture of linuxen and win boxes it also takes care of the proper \n for the architecture when i checkout or update.

  • Comment on Re^3: Next 50 array elements during each loop?