title: Python program to send the input of text file to youtube search api?
body: <p>I have a text file file1.txt that contains a list of keywords.</p>
  
  <pre><code>python
  dictionary
  list
  process
  program
  </code></pre>
  
  <p>and so on.</p>
  
  <p>I'm using the official python youtube api to search for these keywords; which at present I'm doing manually. How to automate this such that the program can search for these keywords one after another automatically.</p>
  
  <pre><code>from apiclient.discovery import build
  from apiclient.errors import HttpError
  from oauth2client.tools import argparser
  DEVELOPER_KEY = "BIzaSyCwzkEAWUFXvWq0u1hybEK3ZdlQw-YRg2w"
  YOUTUBE_API_SERVICE_NAME = "youtube"
  YOUTUBE_API_VERSION = "v3"
  
  def youtube_search(options):
    youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION,
      developerKey=DEVELOPER_KEY)
  
  # Call the search.list method to retrieve results matching the specified query term.
  search_response = youtube.search().list(
    q=options.q,
    part="id,snippet",
    maxResults=options.max_results
  ).execute()
  videos = []
  for search_result in search_response.get("items", []):
    if search_result["id"]["kind"] == "youtube#video":
      videos.append("%s (%s)" % (search_result["snippet"]["title"],
                               search_result["id"]["videoId"]))
  print "Videos:\n", "\n".join(videos), "\n"
  keyword=raw_input("Enter the keyword you want to search video's for:")
  
  if __name__ == "__main__":
    argparser.add_argument("--q", help="Search term", default=keyword)
    argparser.add_argument("--max-results", help="Max results", default=5)
    args = argparser.parse_args()
  
   try:
     youtube_search(args)
   except HttpError, e:
     print "An HTTP error %d occurred:\n%s" % (e.resp.status, e.content)
  </code></pre>
  
  <p>Edit 1:
  I did as you asked.</p>
  
  <pre><code>words = open('D:\keywordq.txt', 'r').read().split("\n")
  for w in words:
    #keyword=raw_input("Enter the keyword you want to search video's for:")
    if __name__ == "__main__":
      argparser.add_argument("--q", help="Search term", default=w)
      argparser.add_argument("--max-results", help="Max results", default=5)
      args = argparser.parse_args()
  </code></pre>
  
  <p>Now in the output i get 5 blank lines instead of results.</p>