<commit_before>import pytumblr, ConfigParser, re

config = ConfigParser.RawConfigParser()
config.read('settings.cfg')

class API(object):
    # initialize Tumblr client
    def __init__(self):
        self.t = pytumblr.TumblrRestClient(
            config.get('tumblr', 'consumerKey'),
            config.get('tumblr', 'consumerSecret'),
            config.get('tumblr', 'oauthToken'),
            config.get('tumblr', 'oauthSecret')
        )
        self.blogName = config.get('tumblr', 'blogName')
        
    # create a Tumblr post of type audio
    def createAudioPost(self, post):
        # build caption for post with available data
        audioCaption = post['artist'] + ' - ' + post['songTitle']
        if(post['genres'] is not None):
            audioCaption += ' [' + " / ".join(post['genres']) + ']' 
        if(post['songYear'] is not None):
            audioCaption += ' (' + post['songYear'] + ')'
        audioCaption = audioCaption.encode("utf-8")
        
        try:
            self.t.create_audio(self.blogName, caption=audioCaption, tags=post['genres'], external_url=post['url'])
        except:
            print "failed to create audio post"
        
    # create a Tumblr post for youtube video
    def createYoutubePost(self, post):
        # build caption for post with available data
        videoCaption = post['artist'] + ' - ' + post['songTitle']
        if(post['genres'] is not None):
            videoCaption += ' [' + " / ".join(post['genres']) + ']' 
        if(post['songYear'] is not None):
            videoCaption += ' (' + post['songYear'] + ')'
        videoCaption = videoCaption.encode("utf-8")
        
        # get video ID from URL
        regex = re.compile("v\=([\-\w]+)")
        videoId = regex.search(post['url'])
        try:
            videoId = videoId.groups()[0]
        except:
            return
        
        # create embed code string using video ID
        embedString = '<iframe id="ytplayer" type="text/html" width="640" height="390" src="http://www.youtube.com/embed/' + videoId + '?frameborder="0"/>'
            
        try:
            self.t.create_video(self.blogName, caption=videoCaption, tags=post['genres'], embed=embedString)
        except:
            print "failed to create youtube post"
        
    # create a Tumblr post for vimeo video
    def createVimeoPost(self, post):
        # build caption for post with available data
        videoCaption = post['artist'] + ' - ' + post['songTitle']
        if(post['genres'] is not None):
            videoCaption += ' [' + " / ".join(post['genres']) + ']' 
        if(post['songYear'] is not None):
            videoCaption += ' (' + post['songYear'] + ')'
        videoCaption = videoCaption.encode("utf-8")
        
        # get video ID from URL
        regex = re.compile("vimeo.com\/([\-\w]+)")
        videoId = regex.search(post['url'])
        try:
            videoId = videoId.groups()[0]
        except:
            return
        
        # create embed code string using video ID
        embedString = '<iframe src="//player.vimeo.com/video/' + videoId + '" width="640" height="390" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>'
            
        try:
            self.t.create_video(self.blogName, caption=videoCaption, tags=post['genres'], embed=embedString)
        except:
            print "failed to create vimeo post"
        
    # create a Tumblr post of type link
    def createLinkPost(self, post):
        # build title for post with available data
        linkTitle = post['artist'] + ' - ' + post['songTitle']
        if(post['genres'] is not None):
            linkTitle += ' [' + " / ".join(post['genres']) + ']' 
        if(post['songYear'] is not None):
            linkTitle += ' (' + post['songYear'] + ')'
        linkTitle = linkTitle.encode("utf-8")
        
        try:
            self.t.create_link(self.blogName, title=linkTitle, tags=post['genres'], url=str(post['url']))
        except:
            print "failed to create link post"<commit_msg>added context to error messages<commit_after>import pytumblr, ConfigParser, re, sys

config = ConfigParser.RawConfigParser()
config.read('settings.cfg')

class API(object):
    # initialize Tumblr client
    def __init__(self):
        self.t = pytumblr.TumblrRestClient(
            config.get('tumblr', 'consumerKey'),
            config.get('tumblr', 'consumerSecret'),
            config.get('tumblr', 'oauthToken'),
            config.get('tumblr', 'oauthSecret')
        )
        self.blogName = config.get('tumblr', 'blogName')
        
    # create a Tumblr post of type audio
    def createAudioPost(self, post):
        # build caption for post with available data
        audioCaption = post['artist'] + ' - ' + post['songTitle']
        if(post['genres'] is not None):
            audioCaption += ' [' + " / ".join(post['genres']) + ']' 
        if(post['songYear'] is not None):
            audioCaption += ' (' + post['songYear'] + ')'
        audioCaption = audioCaption.encode("utf-8")
        
        try:
            print self.t.create_audio(self.blogName, caption=audioCaption, tags=post['genres'], external_url=post['url'])
        except:
            print "failed to create audio post:", sys.exc_info()[0]
        
    # create a Tumblr post for youtube video
    def createYoutubePost(self, post):
        # build caption for post with available data
        videoCaption = post['artist'] + ' - ' + post['songTitle']
        if(post['genres'] is not None):
            videoCaption += ' [' + " / ".join(post['genres']) + ']' 
        if(post['songYear'] is not None):
            videoCaption += ' (' + post['songYear'] + ')'
        videoCaption = videoCaption.encode("utf-8")
        
        # get video ID from URL
        regex = re.compile("v\=([\-\w]+)")
        videoId = regex.search(post['url'])
        try:
            videoId = videoId.groups()[0]
        except:
            return
        
        # create embed code string using video ID
        embedString = '<iframe id="ytplayer" type="text/html" width="640" height="390" src="http://www.youtube.com/embed/' + videoId + '?frameborder="0"/>'
            
        try:
            print self.t.create_video(self.blogName, caption=videoCaption, tags=post['genres'], embed=embedString)
        except:
            print "failed to create youtube post:", sys.exc_info()[0]
        
    # create a Tumblr post for vimeo video
    def createVimeoPost(self, post):
        # build caption for post with available data
        videoCaption = post['artist'] + ' - ' + post['songTitle']
        if(post['genres'] is not None):
            videoCaption += ' [' + " / ".join(post['genres']) + ']' 
        if(post['songYear'] is not None):
            videoCaption += ' (' + post['songYear'] + ')'
        videoCaption = videoCaption.encode("utf-8")
        
        # get video ID from URL
        regex = re.compile("vimeo.com\/([\-\w]+)")
        videoId = regex.search(post['url'])
        try:
            videoId = videoId.groups()[0]
        except:
            return
        
        # create embed code string using video ID
        embedString = '<iframe src="//player.vimeo.com/video/' + videoId + '" width="640" height="390" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>'
            
        try:
            print self.t.create_video(self.blogName, caption=videoCaption, tags=post['genres'], embed=embedString)
        except:
            print "failed to create vimeo post:", sys.exc_info()[0]
        
    # create a Tumblr post of type link
    def createLinkPost(self, post):
        # build title for post with available data
        linkTitle = post['artist'] + ' - ' + post['songTitle']
        if(post['genres'] is not None):
            linkTitle += ' [' + " / ".join(post['genres']) + ']' 
        if(post['songYear'] is not None):
            linkTitle += ' (' + post['songYear'] + ')'
        linkTitle = linkTitle.encode("utf-8")
        
        try:
            print self.t.create_link(self.blogName, title=linkTitle, tags=post['genres'], url=str(post['url']))
        except:
            print "failed to create link post"
{'fraction_non_alphanumeric': 0.14658415240868827, 'fraction_numerical': 0.0052178133721635725, 'mean_word_length': 2.227094753328113, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1945079', 'n_tokens_mistral': 2517, 'n_tokens_neox': 2380, 'n_words': 555}