コード例 #1
0
def dispatchTweet(p, tweet, objectId):
    ''' Takes the tweet from the options in main and dispatches it'''
    
    try:
        entities = tweet['entities']
    except:
        return None
    
    # If the tweet contains media
    if entities.has_key('media') == True:
        mediaOut = cf.processMedia(objectId, tweet)
    
        # Dump the tweet to a string for the jms
        try:
            tweet = json.dumps(mediaOut, ensure_ascii=True)
            success = 1
            #tFile.write("4. Media Event Making it Through"+"\n")
        except:
            logging.error('Failed to dump out the tweet to string.', exc_info=True)
            success = None 
    
        try:
            success = cf.postTweet(p, tweet)
            success = 1
            #tFile.write("5. Media Event Being Posted: %s\n" %success)
        except:
            logging.error('Failed to POST the tweet.', exc_info=True)
            success = None
            #tFile.write("5. Media Failed POST\n")
    else:
        success = -1
        
    return success
コード例 #2
0
def dispatchTweet(p, tweet, objectId):
    ''' Takes the tweet from the options in main and dispatches it'''

    try:
        entities = tweet['entities']
    except:
        return None

    # If the tweet contains media
    if entities.has_key('media') == True:
        mediaOut = cf.processMedia(objectId, tweet)

        # Dump the tweet to a string for the jms
        try:
            tweet = json.dumps(mediaOut, ensure_ascii=True)
            success = 1
            #tFile.write("4. Media Event Making it Through"+"\n")
        except:
            logging.error('Failed to dump out the tweet to string.',
                          exc_info=True)
            success = None

        try:
            success = cf.postTweet(p, tweet)
            success = 1
            #tFile.write("5. Media Event Being Posted: %s\n" %success)
        except:
            logging.error('Failed to POST the tweet.', exc_info=True)
            success = None
            #tFile.write("5. Media Failed POST\n")
    else:
        success = -1

    return success
コード例 #3
0
def main(p, event, bbox=None, tag=None, people=None, mediaOnly=None):
    ''' Coordinates a new twitter stream connection'''

    if tag:
        tag = [tag]

    # Build an appropriate bounding box
    bbox = cf.buildBoundingBox(bbox)
    # track=tag, follow=people, 
    
    try:
        with tweetstream.FilterStream(p.sourceUser, p.sourcePassword, locations=bbox) as stream:
            for tweet in stream:
                
                # If we're only after those with media in
                if mediaOnly:
                    entities = tweet['entities']
                    
                    # If the tweet contains media
                    if entities.has_key('media'):
                        mediaOut = cf.processMedia(tweet)
                        mediaOut['objectId'] = event
                    else:
                        continue
                
                # Dump the tweet to a string for the jms
                try:
                    tweet = json.dumps(mediaOut, ensure_ascii=True)
                except Exception, e:
                    print 'FAILED to dump out'
                    print e
                    continue
            
                try:
                    success = cf.postTweet(tweet)
                except Exception, e:
                    print e
                    print success
コード例 #4
0
def main(p, event, bbox=None, tag=None, people=None, mediaOnly=None):
    """ Coordinates a new twitter stream connection"""

    if tag:
        tag = [tag]

    # Build an appropriate bounding box
    bbox = cf.buildBoundingBox(bbox)
    # track=tag, follow=people,

    try:
        with tweetstream.FilterStream(p.sourceUser, p.sourcePassword, locations=bbox) as stream:
            for tweet in stream:

                # If we're only after those with media in
                if mediaOnly:
                    entities = tweet["entities"]

                    # If the tweet contains media
                    if entities.has_key("media"):
                        mediaOut = cf.processMedia(tweet)
                        mediaOut["objectId"] = event
                    else:
                        continue

                # Dump the tweet to a string for the jms
                try:
                    tweet = json.dumps(mediaOut, ensure_ascii=True)
                except Exception, e:
                    print "FAILED to dump out"
                    print e
                    continue

                try:
                    success = cf.postTweet(tweet)
                except Exception, e:
                    print e
                    print success