Created
November 11, 2013 02:33
-
-
Save Fingel/7406859 to your computer and use it in GitHub Desktop.
Python script to determine if a song has dirty language
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import urllib2 | |
import urllib | |
import re | |
import getopt, sys, argparse | |
def getSongLyrics(artist, song): | |
songUrl = 'http://api.chartlyrics.com/apiv1.asmx/SearchLyricDirect?artist=%s&song=%s' % (urllib.quote_plus(artist), urllib.quote_plus(song)) | |
data = urllib2.urlopen(songUrl).read(); | |
p = re.compile('<Lyric>[a-zA-z].*?<\/Lyric>', re.DOTALL) | |
lyrics = p.search(data).group(); | |
return lyrics | |
def getCleanLyrics(lyrics): | |
print SWEARS.sub('****', lyrics) | |
def containsSwear(lyrics): | |
if (SWEARS.search(lyrics)): | |
print 'dirty' | |
return True; | |
else: | |
print 'clean' | |
return False; | |
if __name__ == "__main__": | |
SWEARS = re.compile('fuck|shit') | |
parser = argparse.ArgumentParser(prog="pyswear", description='given an artist and song, determine if it contains swear words') | |
parser.add_argument('artist', help='name of the artist') | |
parser.add_argument('song', help='Title of the song') | |
args = parser.parse_args() | |
song = args.song | |
artist = args.artist | |
print 'Fetching lyrics for %s - %s' % (artist, song) | |
containsSwear(getSongLyrics(artist, song)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment