Posts

Showing posts from June, 2013

Python Code to Search Youtube Comments

Today I am sharing a code that I wrote few months ago. It searches the comments in youtube video and stores those in a database (postgresql in my code). I used the youtube api . Instead of describing the code in detail, I think posting the code should be enough. If you have any queries or any suggestion to improve the code, feel free to comment. import gdata.youtube import gdata.youtube.service import psycopg2 import sys from datetime import datetime import time import re try: # you should read these from a config file conn = psycopg2.connect(host='localhost', database='databae_name', user='user', password='pass') conn.autocommit = True cursor = conn.cursor() except psycopg2.DatabaseError, e: print 'Error %s' % e sys.exit(1) def since_epoch(date_string): return int(time.mktime(datetime.strptime(date_string, "%Y-%m-%dT%H:%M:%S.%fZ").timetuple(