My code searches youtube video link for every line in file using 'for loop', and youtube api.
File line looks like this 'video_id name'. I am passing this video_id value to my function with 'argparser function' that fails. After first iteration code fails when trying to launch this args = argparser.parse_args()
Is there a way to maybe clear argparser? I googled for that, but it seems like there is no solution for my particular constantly changing value of argparser argument. This link Disable/Remove argument in argparse suggests creating parent parser, but I don't understand how it could help my problem.
def ytSearchLaunch(video_id):
argparser.add_argument("--q", help="Search term", default=video_id)
argparser.add_argument("--max-results", help="Max results", default=25)
args = argparser.parse_args()
youtube_search(args)
This is whole code.
def youtube_search(options):
youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION,
developerKey=DEVELOPER_KEY)
search_response = youtube.search().list(
q=options.q,
type="video",
part="id,snippet",
maxResults=options.max_results
).execute()
def ytSearchLaunch(video_id):
argparser.add_argument("--q", help="Search term", default=video_id)
argparser.add_argument("--max-results", help="Max results", default=25)
args = argparser.parse_args()
youtube_search(args)
def checkDateFunction():
fname = 'file'
f = open(fname,'r')
for l in f:
video_id = l.split()[0]
ytSearchLaunch(video_id)