Example #1
0
def confirmations(product_url,user_mail,user_firstName,user_lastName,tweet_id,tweet_message,product_id,size,date_tweet,user):

    print "confirmation function"
    #Confirmation tweet
    if product_url:
        if size:
            print ' size '
            #api.update_status('Votre achat a ete enregistre, taille %s'%(size),tweet_id)
        else:
            print 'no size'
            #api.update_status('Votre achat a ete enregistre',tweet_id)
    if not size:
        size='none'

    #Confirmation mail
    message = mail.EmailMessage(sender="Admin <%s>"%( os.environ['admin_mail'] ),
    subject="%s new command"%( os.environ['hashtag'] ))
    message.to = "%s <%s>" %( user_firstName,user_mail )
    message.body = """ Hi %s
    Your tweet has been taken in consideration and added tou your %s Cart
     """ %( user_firstName, os.environ['website_name'] )
    message.send()
    mail_sent = True

    #Obtain today's date
    today = datetime.datetime.today()

    #Add the operation to the datastore
    operation = Operation(
        tweet_id=int(tweet_id),
        tweet_message = tweet_message,
        iceberg_product_id = int(product_id),
        iceberg_offer_id = 0,
        iceber_variation = size,
        mail_sent=mail_sent,
        time_stamp=today,
        date=date_tweet,
        user=user
    )
    operation.put()
Example #2
0
def analyseTweet(tweet):

    #env variables
    admin_mail = os.environ['admin_mail']
    hashtag = os.environ['hashtag']
    website_name = os.environ['website_name'] 
    application_name = os.environ['application_name'] 

    # Tweet variables   
    date_tweet = tweet.created_at
    twitter_username = tweet._json['user']['screen_name']
    tweet_id = tweet.id
    tweet_message =  tweet.text
    mail_sent = False         

    print twitter_username

    user = None
    user_mail = False

    # determine if user exists
    users = db.GqlQuery("SELECT * FROM User WHERE twitterUsername ='******'" %(twitter_username) )

    for res in users:

        user_exists = True
        user = res
        user_mail = res.mail
        user_firstName = res.firstName

    if not user:
        print "user doesn't exists"
        return

    if not user.active:
        print 'account desactivated'
        return


    print "The user exists, great "

    #determine if operation has already been treated
    operations = db.GqlQuery("SELECT * FROM Operation WHERE tweet_id =%s" %(tweet_id) )
    for operation in operations:
        print 'tweet has already been taken into consideration'
        return

    #Obtain url from parent tweet
    product_url = False
    parent_id = tweet.in_reply_to_status_id
    parent_status = api.get_status(str(parent_id))
    for url in parent_status.entities['urls']:
        link = url['expanded_url']
        if application_name in link:
            product_url = link
    product_id = product_url.split('/')[-2]

    #Obtain size id there is one
    size = False
    for hashtag in tweet.entities['hashtags']:
        if hashtag['text'][0] == 'T' or hashtag['text'][0] == 't':
            size =  hashtag['text'].split('_')
            size = size[1]

    #Confirmation tweet
    if product_url:
        if size:
            print ' size '
            #api.update_status('Votre achat a ete enregistre, taille %s'%(size),tweet_id)
        else:
            print 'no size'
            #api.update_status('Votre achat a ete enregistre',tweet_id)
    if not size:
        size='none'

    #obtain today's date
    today = datetime.datetime.today()
    print today

    #Confirmation mail
    message = mail.EmailMessage(sender="Admin <%s>"%(admin_mail),
    subject="%s new command"%(hashtag))
    message.to = "%s <%s>" %(user_firstName,user_mail)
    message.body = """ Hi %s
    Your tweet has been taken in consideration and added tou your %s Cart
     """ %(user_firstName, application_name)
    message.send()
    mail_sent = True

    AddFunction=addToCart()
    AddFunction.add(52,"*****@*****.**", "Florian", "Poullin") 


    #add the operation to the datastore
    operation = Operation(
        tweet_id=int(tweet_id),
        tweet_message = tweet_message,
        iceberg_product_id = int(product_id),
        iceberg_offer_id = 0,
        iceber_variation = size,
        mail_sent=mail_sent,
        time_stamp=today,
        date=date_tweet,
        user=user
    )
    operation.put()