Exemplo n.º 1
0
    def updateTweets(self):
        db_access = MongoDBUtils()
        cont = 0
        for user in db_access.get_users("users"):
            cont = cont + 1
            if (len(user['tweets']) == 0):
                print cont
                oldTweets = len(user['tweets'])
                try:
                    userToSave = self.getUserTweets(user)
                except Exception as e:
                    print "Usuario con perfil restringido"
                    userToSave = populate_mentions_hashtags_urls(user)
                #print "ANTES:",oldTweets , "- AHORA: ", len(userToSave['tweets'])

                if oldTweets != len(userToSave['tweets']):
                    try:
                        db_access.save_user_tweets(user["screen_name"],
                                                   userToSave['tweets'])
                    except pymongo.errors.DocumentTooLarge as e:
                        while True:
                            print "********* Doc muy grande, eliminando 50 tweets..."
                            try:
                                userToSave['tweets'] = userToSave[
                                    'tweets'][:len(userToSave['tweets']) - 50]
                                db_access.save_user_tweets(
                                    user["screen_name"], userToSave['tweets'])
                                break
                            except pymongo.errors.DocumentTooLarge as e:
                                pass
Exemplo n.º 2
0
    def updateOtherNetworks(self):
        db_access = MongoDBUtils()
        cont = 0
        for user in db_access.get_users("users"):
            cont = cont + 1
            if (cont > 0):
                print cont

                try:
                    userToSave = self.populateOtherNetworks(user)
                    db_access.save_other_network(userToSave['screen_name'],
                                                 'facebook',
                                                 userToSave['facebook'])
                except Exception as e:
                    print "error"
Exemplo n.º 3
0
def getAgeGenderFromProfilePicture(screen_name, image):
    db_access = MongoDBUtils()
    users = db_access.get_users('users')
    KEY = '80420a0d0de14f4d9fa2f1c6027afc38'  # Replace with a valid subscription key (keeping the quotes in place).
    CF.Key.set(KEY)
    #KEY: https://azure.microsoft.com/en-us/try/cognitive-services/?apiSlug=face-api&country=Uruguay&allowContact=true
    #TEST ONLINE: https://westcentralus.dev.cognitive.microsoft.com/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236/console
    #TUTORIAL: https://docs.microsoft.com/en-us/azure/cognitive-services/face/tutorials/faceapiinpythontutorial

    BASE_URL = 'https://westcentralus.api.cognitive.microsoft.com/face/v1.0/'
    CF.BaseUrl.set(BASE_URL)

    # You can use this example JPG or replace the URL below with your own URL to a JPEG image.
    img_url = image
    resultAge = -1
    resultGender = -1

    try:
        faces = CF.face.detect(img_url, False, False, 'age,gender')
        #print faces
        #print "age: ", faces[0]['faceAttributes']['age']
        if len(faces) > 0:
            resultAge = int(round(faces[0]['faceAttributes']['age'], 0))
            resultGender = faces[0]['faceAttributes']['gender']
    except Exception as ex:
        print "User: "******" - Error while calculating age from profile pic: ", image
        print ex

    if resultAge == -1:
        streamer = TwitterStreamer(Twython)
        newProfilePic = streamer.getLatestProfilePic(screen_name, image)
        isNew = image != newProfilePic
        print "profile pic updated: ", isNew

        if isNew:
            resultAge = getAgeGenderFromProfilePicture(screen_name,
                                                       newProfilePic)
            print resultAge

    db_access.set_profilePic_age_gender_user(screen_name, resultAge,
                                             resultGender)
    return resultAge