Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6803183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:18:49+00:00 2026-05-26T19:18:49+00:00

This is my script and I want it to print and subtract 1 :

  • 0

This is my script and I want it to print and subtract 1:

for eachNumber in range(counter, 0, -1):
print(eachNumber)

from counter for each loop it does. When I try to place it in the for loop I currently have it prints all full numbers until it reaches counter I want it to count down from counter for each for video_id in ids: does in the script.

#!/usr/bin/env python
"""Download video meta-info for a given video urls from input file.

Input files is in Firefox'es bookmarks export file
"""
import csv
import re
import sys
import urlparse
from BeautifulSoup import BeautifulSoup
from gdata.youtube.service import YouTubeService

# parse bookmarks.html
with open(sys.argv[1]) as bookmark_file:
    soup = BeautifulSoup(bookmark_file.read())

# extract youtube video urls
video_url_regex = re.compile('http://www.youtube.com/watch')
urls = [link['href'] for link in soup('a', href=video_url_regex)]

# extract video ids from the urls
ids = []
for video_url in urls:
    url = urlparse.urlparse(video_url)
    video_id = urlparse.parse_qs(url.query).get('v')
    if not video_id: continue # no video_id in the url
    ids.append(video_id[0])

# remove duplicates
ids = list(set(ids))

# print total number of video_ids
counter = len(ids)
print counter

# get some statistics for the videos
yt_service = YouTubeService()
yt_service.developer_key = 'AI39si4yOmI0GEhSTXH0nkiVDf6tQjCkqoys5BBYLKEr-PQxWJ0IlwnUJAcdxpocGLBBCapdYeMLIsB7KVC_OA8gYK0VKV726g'
#NOTE: you don't need to authenticate for readonly requests
yt_service.ssl = True #NOTE: it works for readonly requests
#yt_service.debug = True # show requests

writer = csv.writer(open(sys.argv[2], 'wb'))
for video_id in ids:
    try:
        entry = yt_service.GetYouTubeVideoEntry(video_id=video_id)
        dir(entry.rating)
        ['FindExtensions', 'ToString', '_AddMembersToElementTree', '_BecomeChildElement', '_ConvertElementAttributeToMember', '_ConvertElementTreeToMember', '_HarvestElementTree', '_ToElementTree', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_attributes', '_children', '_namespace', '_tag', 'average', 'extension_attributes', 'extension_elements', 'max', 'min', 'num_raters', 'text']
        comments = yt_service.GetYouTubeVideoCommentFeed(video_id=video_id)
    except Exception, e:
        print >>sys.stderr, "Failed to retrieve entry video_id=%s: %s" %(
            video_id, e)
    else:
        title = entry.media.title.text
        print "Title:", title
        view_count = entry.statistics.view_count
        print "View count:", view_count
        favorites = entry.statistics.favorite_count
        print "Favorite Count:", favorites
        comments = comments.total_results.text
        print "Comment Count:", comments
        if entry.rating is None: # skip it
            average = 0
        else:
            average = entry.rating.average
        print "Average Rating:", average
        if entry.rating is None: # skip it
            num_raters = 0
        else:
            num_raters = entry.rating.num_raters
        print "Number of Raters:", num_raters
        author = entry.author[0].name.text
        print "Autor:", author
        published = entry.published.text
        print "Published on:", published
        tags = entry.media.keywords.text
        print "Tags:", tags
        print "#########################################################"
        writer.writerow((video_id, title, view_count, favorites, comments, average, num_raters, author, published, tags))
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:18:50+00:00Added an answer on May 26, 2026 at 7:18 pm

    It’s hard to tell what you mean, but I think the problem is that you’ve nested one for loop in another, when you don’t actually want to do this. Try adding this inside your ids loop:

    print counter, "videos remaining"
    counter -= 1
    

    This just decreases the counter once per Id, rather than running over the full range for each one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this script that collects data from users and I want to check
I created this script and I want to print the outputs on one line,
In this script , I want awk to print the variables $file , $f
I want to execute this script (view source) that uses Google Translate AJAX API
I want help on this script I am making... I want my website to
What I want to do with this script is to copy a file in
I want to start up my Rails development server like this: script/server OFFLINE_MODE=1 and
I have a file hosting site that's using this script MFHS . I want
in my site i want to set default page to open, using this script
I want something like this: <msxsl:script language=C#> ??? getNodes() { ... return ... }

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.