Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import os
- import logging
- from tools import repnuplogger
- import time
- import json
- import smtplib
- from email.MIMEMultipart import MIMEMultipart
- from email.MIMEText import MIMEText
- from email.MIMEImage import MIMEImage
- import hashlib
- def date_handler(obj):
- return obj.isoformat() if hasattr(obj, 'isoformat') else obj
- # generate summary report for the user
- def generate_summary_report(user_id, db_conn, config, type, sn, g_admin_emails):
- logger = logging.getLogger("repnuplogger")
- fbuser = db_conn.selectOne('tbl_fb_users', "user_id='" + str(user_id) + "'", 'fbid', 'fbname', 'textStatus', 'imageStatus', 'emailId')
- user = db_conn.selectOne('tbl_users', "id='" + str(user_id) + "'", 'created', 'approvedSummaryDate', 'email', 'uuid')
- user_setting = db_conn.selectOne('tbl_settings',"user_id='"+str(user_id)+"'",'progress_report')
- mailFlag = True
- notifyAdminFlag = True
- userTotalAlert = 0
- if user_setting:
- if user_setting[0] == 0:
- mailFlag = False
- twuser = db_conn.selectOne('tbl_twitter_users', "user_id='" + str(user_id) + "'")
- inuser = db_conn.selectOne('tbl_instagram_users', "user_id='" + str(user_id) + "'")
- logger.info("Generating summary report for user %s" % str(user_id))
- report = {}
- report['user_id'] = str(user_id)
- if type:
- report['reportType'] = str(type)
- else:
- report['reportType'] = 0
- if fbuser:
- allAlertsRecord = db_conn.select_as_dict('tbl_fb_text_alerts',where="userFbId='"+str(fbuser[0])+"' and innocent=0 and (violence > 1 or inappropriate > 1 OR indecency > 1 OR alcohol > 1 OR other > 1 OR questionable > 1)")
- tmpAlert = db_conn.selectCount("select count(algoQueryId) as t from tbl_fb_text_alerts where userFbId='"+str(fbuser[0])+"'")
- if tmpAlert:
- tmpalert = str(tmpAlert[0])
- userTotalAlert = userTotalAlert + int(tmpalert)
- else:
- allAlertsRecord = []
- badPost = 0
- badComments = 0
- badShare = 0
- badTweetPhoto = 0
- badTweet = 0
- badInstaCaption = 0
- badInstaComment = 0
- oldCount = {}
- newCount = {}
- totalCounts = {}
- lastFeedTime = ''
- checkList = ['comments', 'commentsPhoto', 'bad_images', 'bad_likes']
- index = 0
- allAlerts = {}
- totalAlert = 0
- for rec in allAlertsRecord:
- if rec['type'] not in checkList and rec['statusType'] !='shared_story':
- badPost = badPost + 1
- elif rec['type'] == 'comments' or rec['type'] == 'commentsPhoto':
- badComments = badComments + 1
- elif rec['type'] == 'shared_story':
- badShare = badShare + 1
- # create confirmed Alert category based on bit field value > 1
- confirmedAlertCat = []
- if str(rec['violence']) > '1':
- confirmedAlertCat.append('violence')
- if str(rec['inappropriate']) > '1':
- confirmedAlertCat.append('inappropriate')
- if str(rec['indecency']) > '1':
- confirmedAlertCat.append('indecency')
- if str(rec['alcohol']) > '1':
- confirmedAlertCat.append('alcohol')
- if str(rec['other']) > '1':
- confirmedAlertCat.append('other')
- if str(rec['questionable']) > '1':
- confirmedAlertCat.append('questionable')
- confirmedAlertCatStr = ','.join(confirmedAlertCat)
- allAlerts[index] = {}
- allAlerts[index]['AllAlert'] = {}
- allAlerts[index]['AllAlert']['algoQueryid'] = rec['algoQueryId']
- allAlerts[index]['AllAlert']['feedId'] = rec['feedId']
- allAlerts[index]['AllAlert']['userFbId'] = rec['userFbId']
- allAlerts[index]['AllAlert']['wallFbId'] = rec['wallFbId']
- allAlerts[index]['AllAlert']['fromName'] = rec['fromName']
- allAlerts[index]['AllAlert']['fromFbId'] = rec['fromFbId']
- allAlerts[index]['AllAlert']['type'] = rec['type']
- allAlerts[index]['AllAlert']['statusType'] = rec['statusType']
- allAlerts[index]['AllAlert']['message'] = rec['message']
- allAlerts[index]['AllAlert']['messageTag'] = rec['messageTag']
- allAlerts[index]['AllAlert']['alertWord'] = rec['alertWord']
- allAlerts[index]['AllAlert']['alertMatchWord'] = rec['alertMatchWord']
- allAlerts[index]['AllAlert']['originalAlertCategory'] = ""
- allAlerts[index]['AllAlert']['confirmedAlertCategory'] = confirmedAlertCatStr
- allAlerts[index]['AllAlert']['feedTime'] = rec['feedTime']
- allAlerts[index]['AllAlert']['language'] = rec['language']
- allAlerts[index]['AllAlert']['manual'] = rec['manual']
- allAlerts[index]['AllAlert']['privacy'] = rec['privacy']
- allAlerts[index]['AllAlert']['sn_type'] = 'fb'
- if lastFeedTime > str(rec['feedTime']) or lastFeedTime == '':
- lastFeedTime = str(rec['feedTime'])
- index = index+1
- if twuser:
- allAlertsRecord = db_conn.select_as_dict('tbl_tw_text_alerts', where="userTwId='" + str(twuser[2]) + "' and innocent=0 and (violence >1 OR inappropriate >1 OR indecency >1 OR alcohol >1 OR questionable >1 OR other >1)")
- tmpTwAlert = db_conn.selectCount("select count(algoQueryId) as t from tbl_tw_text_alerts where userTwId='"+str(twuser[2])+"'")
- if tmpTwAlert:
- tmpalert = str(tmpTwAlert[0])
- userTotalAlert = userTotalAlert + int(tmpalert)
- for rec in allAlertsRecord:
- if 'photo' in rec['type']:
- badTweetPhoto += 1
- else:
- badTweet += 1
- # create confirmed Alert category based on bit field value > 1
- confirmedAlertCat = []
- if str(rec['violence']) > '1':
- confirmedAlertCat.append('violence')
- if str(rec['inappropriate']) > '1':
- confirmedAlertCat.append('inappropriate')
- if str(rec['indecency']) > '1':
- confirmedAlertCat.append('indecency')
- if str(rec['alcohol']) > '1':
- confirmedAlertCat.append('alcohol')
- if str(rec['other']) > '1':
- confirmedAlertCat.append('other')
- if str(rec['questionable']) > '1':
- confirmedAlertCat.append('questionable')
- confirmedAlertCatStr = ','.join(confirmedAlertCat)
- allAlerts[index] = {}
- allAlerts[index]['AllAlert'] = {}
- allAlerts[index]['AllAlert']['algoQueryid'] = rec['algoQueryId']
- allAlerts[index]['AllAlert']['tweetId'] = rec['tweetId']
- allAlerts[index]['AllAlert']['userTwId'] = rec['userTwId']
- allAlerts[index]['AllAlert']['fromTwId'] = rec['fromTwId']
- allAlerts[index]['AllAlert']['fromName'] = rec['fromName']
- allAlerts[index]['AllAlert']['fromScreenName'] = rec['fromScreenName']
- allAlerts[index]['AllAlert']['type'] = rec['type']
- allAlerts[index]['AllAlert']['message'] = rec['message']
- allAlerts[index]['AllAlert']['alertWord'] = rec['alertWord']
- allAlerts[index]['AllAlert']['alertMatchWord'] = rec['alertMatchWord']
- allAlerts[index]['AllAlert']['originalAlertCategory'] = ""
- allAlerts[index]['AllAlert']['confirmedAlertCategory'] = confirmedAlertCatStr
- allAlerts[index]['AllAlert']['feedTime'] = rec['feedTime']
- allAlerts[index]['AllAlert']['language'] = rec['language']
- allAlerts[index]['AllAlert']['privacy'] = rec['privacy']
- allAlerts[index]['AllAlert']['possibleSensitive'] = rec['possibleSensitive']
- allAlerts[index]['AllAlert']['sn_type'] = 'tw'
- if lastFeedTime > str(rec['feedTime']) or lastFeedTime == '':
- lastFeedTime = str(rec['feedTime'])
- index += 1
- if inuser:
- allAlertsRecord = db_conn.select_as_dict('tbl_insta_text_alerts',where="userInsId='"+str(inuser[2])+"' and innocent=0 and (violence >1 OR inappropriate >1 OR indecency >1 OR alcohol >1 OR questionable >1 OR other >1)")
- tmpInAlert = db_conn.selectCount("select count(algoQueryId) from tbl_insta_text_alerts where userInsId='"+str(inuser[2])+"'")
- if tmpInAlert:
- tmpalert = str(tmpInAlert[0])
- userTotalAlert = userTotalAlert + int(tmpalert)
- for rec in allAlertsRecord:
- if rec['type'] == 'caption':
- badInstaCaption = badInstaCaption + 1
- else:
- badInstaComment = badInstaComment + 1
- # create confirmed Alert category based on bit field value > 1
- confirmedAlertCat = []
- if str(rec['violence']) > '1':
- confirmedAlertCat.append('violence')
- if str(rec['inappropriate']) > '1':
- confirmedAlertCat.append('inappropriate')
- if str(rec['indecency']) > '1':
- confirmedAlertCat.append('indecency')
- if str(rec['alcohol']) > '1':
- confirmedAlertCat.append('alcohol')
- if str(rec['other']) > '1':
- confirmedAlertCat.append('other')
- if str(rec['questionable']) > '1':
- confirmedAlertCat.append('questionable')
- confirmedAlertCatStr = ','.join(confirmedAlertCat)
- allAlerts[index] = {}
- allAlerts[index]['AllAlert'] = {}
- allAlerts[index]['AllAlert']['algoQueryid'] = rec['algoQueryId']
- allAlerts[index]['AllAlert']['mediaId'] = rec['mediaId']
- allAlerts[index]['AllAlert']['feedId'] = rec['feedId']
- allAlerts[index]['AllAlert']['userInsId'] = rec['userInsId']
- allAlerts[index]['AllAlert']['fromInsId'] = rec['fromInsId']
- allAlerts[index]['AllAlert']['fromName'] = rec['fromName']
- allAlerts[index]['AllAlert']['fromScreenName'] = rec['fromScreenName']
- allAlerts[index]['AllAlert']['type'] = rec['type']
- allAlerts[index]['AllAlert']['message'] = rec['message']
- allAlerts[index]['AllAlert']['alertWord'] = rec['alertWord']
- allAlerts[index]['AllAlert']['alertMatchWord'] = rec['alertMatchWord']
- allAlerts[index]['AllAlert']['originalAlertCategory'] = ""
- allAlerts[index]['AllAlert']['confirmedAlertCategory'] = confirmedAlertCatStr
- allAlerts[index]['AllAlert']['feedTime'] = rec['feedTime']
- allAlerts[index]['AllAlert']['language'] = rec['language']
- allAlerts[index]['AllAlert']['link'] = rec['link']
- allAlerts[index]['AllAlert']['sn_type'] = 'in'
- index = index+1
- if (len(allAlertsRecord) == userTotalAlert) and report['reportType'] == "2":
- # for initial report check if total alert and confirmed alerts are equal then generate detail report
- report['reportType'] = "0"
- rectime = time.strftime('%Y-%m-%d %H:%M:%S')
- #db_conn.updateRec('tbl_users',"id='"+str(report['user_id'])+"'",approvedSummaryDate=str(rectime),aprovalStatus="1")
- query = "update tbl_users set approvedSummaryDate='"+str(rectime)+"',aprovalStatus=0 where id ='"+str(report['user_id'])+"'"
- logger.info(query)
- db_conn.sqlQuery(query)
- notifyAdminFlag = False
- if len(allAlertsRecord) == 0 and report['reportType'] != "2" and report['reportType'] != "3" and report['reportType'] != "4":
- report['noAlert'] = 1
- oldCount['badPosts'] = badPost
- oldCount['badComments'] = badComments
- oldCount['badShares'] = badShare
- oldCount['badTweetPhoto'] = badTweetPhoto
- oldCount['badTweet'] = badTweet
- oldCount['badInstaComment'] = badInstaComment
- oldCount['badInstaCaption'] = badInstaCaption
- totalFeedCount = 0
- totalAlert = badPost + badComments + badShare
- totalTweetAlert = badTweet + badTweetPhoto
- totalInAlert = badInstaCaption + badInstaComment
- totalImageCount = 0
- totalTweetCount = 0
- totalTweetMediaCount = 0
- totalInstaCount = 0
- totalInstaMediaCount = 0
- if fbuser:
- fbcounts = db_conn.selectOne('tbl_fb_user_counts',"fbid='"+str(fbuser[0])+"'")
- if fbcounts:
- textcount = json.loads(fbcounts[1])
- imagecount = json.loads(fbcounts[2])
- totalCounts['feeds'] = {}
- if 'commentCount' not in textcount:
- textcount['commentCount'] = 0
- if 'postCount' not in textcount:
- textcount['postCount'] = 0
- if 'sharedCount' not in textcount:
- textcount['sharedCount'] = 0
- totalCounts['feeds']['all'] = textcount['commentCount'] + textcount['postCount'] + textcount['sharedCount']
- totalFeedCount = totalCounts['feeds']['all']
- totalCounts['feeds']['posts'] = textcount['postCount']
- totalCounts['feeds']['comments'] = textcount['commentCount']
- totalCounts['feeds']['shares'] = textcount['sharedCount']
- totalCounts['images'] = {}
- totalCounts['images']['tagged'] = imagecount['photoTagged']
- totalCounts['images']['upload'] = imagecount['photoUploadedCount']
- totalCounts['images']['like'] = imagecount['photoLikedCount']
- totalCounts['feeds']['images'] = imagecount['photoTagged'] + imagecount['photoUploadedCount']
- totalCounts['feeds']['likes'] = imagecount['photoLikedCount']
- totalCounts['alerts'] = len(allAlertsRecord)
- totalImageCount = imagecount['photoTagged'] + imagecount['photoUploadedCount'] + imagecount['photoLikedCount']
- if twuser:
- twcounts = db_conn.selectOne('tbl_tw_user_counts',"twid='"+str(twuser[2])+"'")
- if twcounts:
- tweetcount = json.loads(twcounts[1])
- photocount = json.loads(twcounts[2])
- totalCounts['tweets'] = {}
- totalCounts['tweets']['all'] = tweetcount['tweet'] + tweetcount['retweet']
- totalTweetCount = totalCounts['tweets']['all']
- totalCounts['tweets']['tweet'] = tweetcount['tweet']
- totalCounts['tweets']['retweet'] = tweetcount['retweet']
- totalTweetCount = totalCounts['tweets']['all']
- totalCounts['tweetimages'] = {}
- totalCounts['tweetimages']['all'] = photocount['tweet'] + photocount['retweet']
- totalCounts['tweetimages']['tweet'] = photocount['tweet']
- totalCounts['tweetimages']['retweet'] = photocount['retweet']
- totalTweetMediaCount = photocount['tweet'] + photocount['retweet']
- if inuser:
- incounts = db_conn.selectOne('tbl_insta_user_counts',"instagramId='"+str(inuser[2])+"'")
- if incounts:
- intexcount = json.loads(incounts[2])
- inimagecount = incounts[1]
- totalCounts['instagram'] = {}
- totalCounts['instagram']['all'] = intexcount['commentCount'] + intexcount['captionCount']+inimagecount
- totalCounts['instagram']['comment'] = intexcount['commentCount']
- totalCounts['instagram']['caption'] = intexcount['captionCount']
- totalCounts['instagram']['media'] = inimagecount
- totalInstaCount = intexcount['commentCount'] + intexcount['captionCount']
- totalInstaMediaCount = inimagecount
- report['oldCount'] = json.dumps(json.dumps(oldCount) )
- #new count and old count are equal for now, a new future feature will update the new count
- report['newCount'] = json.dumps(json.dumps(oldCount))
- report['netCount'] = json.dumps(json.dumps(totalCounts) )
- report['joinningDate'] = user[0]
- report['approvalDate'] = user[1]
- report['timeBack'] = lastFeedTime
- report['report'] = json.dumps(allAlerts, default=date_handler)
- report['id'] = hashlib.md5(str(time.time())+str(fbuser[0])).hexdigest()
- rectime = time.strftime('%Y-%m-%d %H:%M:%S')
- if report['approvalDate'] is None:
- report['approvalDate'] = '0000-00-00'
- try:
- if report['reportType'] == '4':
- db_conn.updateRec('tbl_reports', "user_id='"+str(report['user_id'])+"'",
- report=report['report'],
- created=rectime,
- modified=rectime)
- db_conn.updateRec('tbl_users', "id='"+str(report['user_id'])+"'",
- is_new=1, regenerate_report=0, last_email_sent=rectime)
- return
- if report['reportType'] == "3":
- db_conn.updateRec('tbl_reports', "user_id='"+str(report['user_id'])+"'",
- report=report['report'],
- created=rectime,
- modified=rectime)
- if sendDailyReportMail(report['id'], report['user_id'], fbuser[0], fbuser[1], user[2], config, mailFlag, user[3]):
- db_conn.updateRec('tbl_users', "id='"+str(report['user_id'])+"'",
- is_new=1, mail_status="daily_report_mail", regenerate_report=0, modified=rectime, last_email_sent=rectime)
- return
- db_conn.sqlQuery("INSERT into tbl_reports (id,user_id,report,newCounts,oldCounts,netCounts,approvalDate,timeBack,reportType,created,modified) values ('"+str(report['id'])+"',"+report['user_id']+","+json.dumps(report['report'])+","+report['newCount']+","+report['oldCount']+","+report['netCount']+",'"+str(report['approvalDate'])+"','"+str(report['timeBack'])+"',"+str(report['reportType'])+",'"+(rectime)+"','"+str(rectime)+"')")
- if sn == 'fb':
- db_conn.updateRec('tbl_users', "id='"+str(report['user_id'])+"'", status=2)
- if 'noAlert' in report:
- if(sendNoAlertMail(report['id'],report['user_id'],fbuser[0],fbuser[1],user[2],totalFeedCount,totalImageCount,totalCounts['feeds']['posts'],totalCounts['feeds']['comments'],totalCounts['feeds']['shares'],totalCounts['feeds']['likes'],config,mailFlag,user[3])):
- rectime = time.strftime('%Y-%m-%d %H:%M:%S')
- db_conn.updateRec('tbl_reports',"id='"+str(report['id'])+"'",mailStatus=2,modified=rectime)
- db_conn.updateRec('tbl_users',"id='"+str(report['user_id'])+"'",mail_status="summary_mail",status=6,modified=rectime,last_email_sent=rectime)
- else:
- flag = False
- if report['reportType'] == "2":
- if(sendInitialMail(report['id'],report['user_id'],fbuser[0],fbuser[1],user[2],totalFeedCount,totalAlert,totalImageCount,config,mailFlag,user[3])):
- flag = True
- db_conn.updateRec('tbl_users',"id='"+str(report['user_id'])+"'",mail_status="initial_report_mail", status=2, modified=rectime, last_email_sent=rectime)
- else:
- if(sendSummaryMail(report['id'],report['user_id'],fbuser[0],fbuser[1],user[2],totalFeedCount,totalAlert,totalImageCount,config,mailFlag,user[3])):
- flag = True
- db_conn.updateRec('tbl_users', "id='"+str(report['user_id'])+"'", mail_status="summary_mail", status=6, modified=rectime, last_email_sent=rectime)
- if flag:
- rectime = time.strftime('%Y-%m-%d %H:%M:%S')
- db_conn.updateRec('tbl_reports',"id='"+str(report['id'])+"'",mailStatus=1,modified=rectime)
- elif sn == 'tw':
- db_conn.updateRec('tbl_users',"id='"+str(report['user_id'])+"'",twitterStatus=2)
- if 'noAlert' in report:
- totalFeedCount = totalTweetMediaCount + totalTweetCount
- if(sendNoTwAlertMail(report['id'],report['user_id'],twuser[2],twuser[3],user[2],totalFeedCount,totalTweetCount,totalTweetMediaCount,config,mailFlag,user[3])):
- rectime = time.strftime('%Y-%m-%d %H:%M:%S')
- db_conn.updateRec('tbl_reports',"id='"+str(report['id'])+"'",mailStatus=2,modified=rectime)
- db_conn.updateRec('tbl_users',"id='"+str(report['user_id'])+"'",mail_status="summary_mail",twitterStatus=6,modified=rectime, last_email_sent=rectime)
- else:
- flag = False
- if report['reportType'] == "2":
- #logger.info("Sending email ")
- #if(sendInitialTwMail(report['id'],report['user_id'],twuser[2],twuser[3],user[2],totalTweetCount,totalTweetAlert,config,mailFlag,user[3])):
- # flag = True
- db_conn.updateRec('tbl_users',"id='"+str(report['user_id'])+"'",mail_status="initial_report_mail",twitterStatus=2,modified=rectime, last_email_sent=rectime)
- else:
- if(sendTwSummaryMail(report['id'],report['user_id'],twuser[2],twuser[3],user[2],totalTweetCount,totalTweetAlert,config,mailFlag,user[3])):
- flag = True
- db_conn.updateRec('tbl_users',"id='"+str(report['user_id'])+"'",mail_status="summary_mail",twitterStatus=6,modified=rectime, last_email_sent=rectime)
- if flag:
- rectime = time.strftime('%Y-%m-%d %H:%M:%S')
- db_conn.updateRec('tbl_reports',"id='"+str(report['id'])+"'",mailStatus=1,modified=rectime)
- elif sn == 'in':
- db_conn.updateRec('tbl_users',"id='"+str(report['user_id'])+"'",instagramStatus=2)
- if 'noAlert' in report:
- if(sendNoInAlertMail(report['id'],report['user_id'],inuser[2],inuser[4],user[2],totalInstaCount,totalInstaMediaCount,config,mailFlag,user[3])):
- rectime = time.strftime('%Y-%m-%d %H:%M:%S')
- db_conn.updateRec('tbl_reports',"id='"+str(report['id'])+"'",mailStatus=2,modified=rectime)
- db_conn.updateRec('tbl_users',"id='"+str(report['user_id'])+"'",mail_status="summary_mail",instagramStatus=6,modified=rectime, last_email_sent=rectime)
- else:
- flag = False
- if report['reportType'] == "2":
- #logger.info("Sending email ")
- #if(sendInitialInMail(report['id'],report['user_id'],inuser[4],user[2],config,mailFlag,user[3])):
- flag = True
- db_conn.updateRec('tbl_users',"id='"+str(report['user_id'])+"'",mail_status="initial_report_mail",instagramStatus=2,modified=rectime, last_email_sent=rectime)
- else:
- if(sendInSummaryMail(report['id'],report['user_id'],inuser[4],user[2],totalInstaMediaCount,totalInAlert,config,mailFlag,user[3])):
- flag = True
- db_conn.updateRec('tbl_users',"id='"+str(report['user_id'])+"'",mail_status="summary_mail",instagramStatus=6,modified=rectime, last_email_sent=rectime)
- if flag:
- rectime = time.strftime('%Y-%m-%d %H:%M:%S')
- db_conn.updateRec('tbl_reports',"id='"+str(report['id'])+"'",mailStatus=1,modified=rectime)
- if report['reportType'] == "2" and notifyAdminFlag:
- notify_admin(1,user_id,db_conn,g_admin_emails,config)
- except Exception as e:
- logger.error("Unable to create summary report for user id %s with error %s"%(user_id,str(e)))
- def generate_detailed_report(user_id, db_conn, config, sn, mtype='1'):
- """
- mtype = 1 generate report and send detailed mail
- mtype = 2 regenerate report witout mail
- mtype = 3 regenerate report and send daily mail
- """
- logger = logging.getLogger("repnuplogger")
- fbuser = db_conn.selectOne('tbl_fb_users',"user_id='"+str(user_id)+"'",'fbid','fbname','textStatus','imageStatus','emailId')
- user = db_conn.selectOne('tbl_users',"id='"+str(user_id)+"'",'created','approvedSummaryDate','email','uuid')
- user_setting = db_conn.selectOne('tbl_settings',"user_id='"+str(user_id)+"'",'progress_report')
- mailFlag = True
- if user_setting:
- if user_setting[0] == 0:
- mailFlag = False
- twuser = db_conn.selectOne('tbl_twitter_users',"user_id='"+str(user_id)+"'")
- inuser = db_conn.selectOne('tbl_instagram_users',"user_id='"+str(user_id)+"'")
- logger.info("Generating detail report for user %s"%str(user_id))
- report = {}
- report['user_id'] = str(user_id)
- report['reportType'] = str(mtype)
- badPost = 0
- badComments = 0
- badShare = 0
- badImages = 0
- oldCount = {}
- newCount = {}
- totalCounts = {}
- lastFeedTime = ''
- checkList = ['comments','commentsPhoto','bad_images','bad_likes']
- index = 0
- allAlerts = {}
- totalAlert = 0
- badTweet = 0
- badTweetPhoto = 0
- badInstaCaption = 0
- badInstaComment = 0
- badInstaMedia = 0
- if fbuser:
- allAlertsRecord = db_conn.select_as_dict('tbl_fb_text_alerts', where="userFbId='"+str(fbuser[0])+"' and innocent=0 and (violence >1 OR inappropriate >1 OR indecency >1 OR alcohol >1 OR questionable >1 OR other >1) ")
- for rec in allAlertsRecord:
- if rec['type'] not in checkList and rec['statusType'] != 'shared_story':
- badPost = badPost + 1
- elif rec['type'] == 'comments' or rec['type'] == 'commentsPhoto':
- badComments = badComments + 1
- elif rec['type'] == 'shared_story':
- badShare = badShare + 1
- # create confirmed Alert category based on bit field value > 1
- confirmedAlertCat = []
- if str(rec['violence']) > '1':
- confirmedAlertCat.append('violence')
- if str(rec['inappropriate']) > '1':
- confirmedAlertCat.append('inappropriate')
- if str(rec['indecency']) > '1':
- confirmedAlertCat.append('indecency')
- if str(rec['alcohol']) > '1':
- confirmedAlertCat.append('alcohol')
- if str(rec['other']) > '1':
- confirmedAlertCat.append('other')
- if str(rec['questionable']) > '1':
- confirmedAlertCat.append('questionable')
- confirmedAlertCatStr = ','.join(confirmedAlertCat)
- allAlerts[index] = {}
- allAlerts[index]['AllAlert'] = {}
- allAlerts[index]['AllAlert']['algoQueryid'] = rec['algoQueryId']
- allAlerts[index]['AllAlert']['feedId'] = rec['feedId']
- allAlerts[index]['AllAlert']['userFbId'] = rec['userFbId']
- allAlerts[index]['AllAlert']['wallFbId'] = rec['wallFbId']
- allAlerts[index]['AllAlert']['fromName'] = rec['fromName']
- allAlerts[index]['AllAlert']['fromFbId'] = rec['fromFbId']
- allAlerts[index]['AllAlert']['type'] = rec['type']
- allAlerts[index]['AllAlert']['statusType'] = rec['statusType']
- allAlerts[index]['AllAlert']['message'] = rec['message']
- allAlerts[index]['AllAlert']['messageTag'] = rec['messageTag']
- allAlerts[index]['AllAlert']['alertWord'] = rec['alertWord']
- allAlerts[index]['AllAlert']['alertMatchWord'] = rec['alertMatchWord']
- allAlerts[index]['AllAlert']['originalAlertCategory'] = ""
- allAlerts[index]['AllAlert']['confirmedAlertCategory'] = confirmedAlertCatStr
- allAlerts[index]['AllAlert']['feedTime'] = rec['feedTime']
- allAlerts[index]['AllAlert']['language'] = rec['language']
- allAlerts[index]['AllAlert']['manual'] = rec['manual']
- allAlerts[index]['AllAlert']['privacy'] = rec['privacy']
- allAlerts[index]['AllAlert']['sn_type'] = 'fb'
- if (lastFeedTime > str(rec['feedTime']) or lastFeedTime == ''):
- lastFeedTime = str(rec['feedTime'])
- index += 1
- allImageAlertsRecord = db_conn.select_as_dict('tbl_fb_photos', where="userFbId='"+str(fbuser[0])+"' and innocent=0 and (violence >1 OR inappropriate >1 OR indecency >1 OR alcohol >1 OR questionable >1 OR smoking >1)")
- for rec in allImageAlertsRecord:
- badImages = badImages + 1
- # create confirmed Alert category based on bit field value > 1
- confirmedAlertCat = []
- if str(rec['violence']) > '1':
- confirmedAlertCat.append('violence')
- if str(rec['inappropriate']) > '1':
- confirmedAlertCat.append('inappropriate')
- if str(rec['indecency']) > '1':
- confirmedAlertCat.append('indecency')
- if str(rec['alcohol']) > '1':
- confirmedAlertCat.append('alcohol')
- if str(rec['smoking']) > '1':
- confirmedAlertCat.append('smoking')
- if str(rec['questionable']) > '1':
- confirmedAlertCat.append('questionable')
- confirmedAlertCatStr = ','.join(confirmedAlertCat)
- allAlerts[index] = {}
- allAlerts[index]['AllAlert'] = {}
- allAlerts[index]['AllAlert']['algoQueryid'] = hashlib.md5(str(rec['feedId'])).hexdigest()
- allAlerts[index]['AllAlert']['feedId'] = rec['feedId']
- allAlerts[index]['AllAlert']['userFbId'] = rec['userFbId']
- allAlerts[index]['AllAlert']['wallFbId'] = rec['userFbId']
- allAlerts[index]['AllAlert']['fromName'] = ''
- allAlerts[index]['AllAlert']['fromFbId'] = rec['fromFbId']
- allAlerts[index]['AllAlert']['type'] = 'bad_image'
- allAlerts[index]['AllAlert']['description'] = rec['photo']
- allAlerts[index]['AllAlert']['photoType'] = rec['photoType']
- allAlerts[index]['AllAlert']['message'] = rec['name']
- allAlerts[index]['AllAlert']['messageTag'] = ''
- allAlerts[index]['AllAlert']['alertWord'] = ''
- allAlerts[index]['AllAlert']['alertMatchWord'] = ''
- allAlerts[index]['AllAlert']['originalAlertCategory'] = ""
- allAlerts[index]['AllAlert']['confirmedAlertCategory'] = confirmedAlertCatStr
- allAlerts[index]['AllAlert']['feedTime'] = rec['feedTime']
- allAlerts[index]['AllAlert']['manual'] = ''
- allAlerts[index]['AllAlert']['privacy'] = rec['privacy']
- allAlerts[index]['AllAlert']['photo'] = rec['photo']
- allAlerts[index]['AllAlert']['link'] = rec['link']
- allAlerts[index]['AllAlert']['sn_type'] = 'fb'
- index += 1
- if twuser:
- allAlertsRecord = db_conn.select_as_dict('tbl_tw_text_alerts', where="userTwId='"+str(twuser[2])+"' and innocent=0 and (violence >1 OR inappropriate >1 OR indecency >1 OR alcohol >1 OR questionable >1 OR other >1)")
- for rec in allAlertsRecord:
- if 'photo' in rec['type']:
- badTweetPhoto = badTweetPhoto + 1
- else:
- badTweet = badTweet + 1
- # create confirmed Alert category based on bit field value > 1
- confirmedAlertCat = []
- if str(rec['violence']) > '1':
- confirmedAlertCat.append('violence')
- if str(rec['inappropriate']) > '1':
- confirmedAlertCat.append('inappropriate')
- if str(rec['indecency']) > '1':
- confirmedAlertCat.append('indecency')
- if str(rec['alcohol']) > '1':
- confirmedAlertCat.append('alcohol')
- if str(rec['other']) > '1':
- confirmedAlertCat.append('other')
- if str(rec['questionable']) > '1':
- confirmedAlertCat.append('questionable')
- confirmedAlertCatStr = ','.join(confirmedAlertCat)
- allAlerts[index] = {}
- allAlerts[index]['AllAlert'] = {}
- allAlerts[index]['AllAlert']['algoQueryid'] = rec['algoQueryId']
- allAlerts[index]['AllAlert']['tweetId'] = rec['tweetId']
- allAlerts[index]['AllAlert']['userTwId'] = rec['userTwId']
- allAlerts[index]['AllAlert']['fromTwId'] = rec['fromTwId']
- allAlerts[index]['AllAlert']['fromName'] = rec['fromName']
- allAlerts[index]['AllAlert']['fromScreenName'] = rec['fromScreenName']
- allAlerts[index]['AllAlert']['type'] = rec['type']
- allAlerts[index]['AllAlert']['message'] = rec['message']
- allAlerts[index]['AllAlert']['alertWord'] = rec['alertWord']
- allAlerts[index]['AllAlert']['alertMatchWord'] = rec['alertMatchWord']
- allAlerts[index]['AllAlert']['originalAlertCategory'] = ""
- allAlerts[index]['AllAlert']['confirmedAlertCategory'] = confirmedAlertCatStr
- allAlerts[index]['AllAlert']['feedTime'] = rec['feedTime']
- allAlerts[index]['AllAlert']['language'] = rec['language']
- allAlerts[index]['AllAlert']['privacy'] = rec['privacy']
- allAlerts[index]['AllAlert']['possibleSensitive'] = rec['possibleSensitive']
- allAlerts[index]['AllAlert']['sn_type'] = 'tw'
- if lastFeedTime > str(rec['feedTime']) or lastFeedTime == '':
- lastFeedTime = str(rec['feedTime'])
- index += 1
- allImageAlertsRecord = db_conn.select_as_dict('tbl_tw_photos', where="userTwId='"+str(twuser[2])+"' and innocent=0 and (violence >1 OR inappropriate >1 OR indecency >1 OR alcohol >1 OR questionable >1 OR smoking >1)")
- for rec in allImageAlertsRecord:
- badImages = badImages + 1
- # create confirmed Alert category based on bit field value > 1
- confirmedAlertCat = []
- if str(rec['violence']) > '1':
- confirmedAlertCat.append('violence')
- if str(rec['inappropriate']) > '1':
- confirmedAlertCat.append('inappropriate')
- if str(rec['indecency']) > '1':
- confirmedAlertCat.append('indecency')
- if str(rec['alcohol']) > '1':
- confirmedAlertCat.append('alcohol')
- if str(rec['smoking']) > '1':
- confirmedAlertCat.append('smoking')
- if str(rec['questionable']) > '1':
- confirmedAlertCat.append('questionable')
- confirmedAlertCatStr = ','.join(confirmedAlertCat)
- allAlerts[index] = {}
- allAlerts[index]['AllAlert'] = {}
- allAlerts[index]['AllAlert']['algoQueryid'] = hashlib.md5(str(rec['tweetId'])).hexdigest()
- allAlerts[index]['AllAlert']['tweetId'] = rec['tweetId']
- allAlerts[index]['AllAlert']['userTwId'] = rec['userTwId']
- allAlerts[index]['AllAlert']['fromTwId'] = rec['fromTwId']
- allAlerts[index]['AllAlert']['fromName'] = rec['fromName']
- allAlerts[index]['AllAlert']['fromScreenName'] = rec['fromName']
- allAlerts[index]['AllAlert']['type'] = 'bad_image'
- allAlerts[index]['AllAlert']['description'] = ''
- allAlerts[index]['AllAlert']['photoType'] = ''
- allAlerts[index]['AllAlert']['message'] = ''
- allAlerts[index]['AllAlert']['messageTag'] = ''
- allAlerts[index]['AllAlert']['alertWord'] = ''
- allAlerts[index]['AllAlert']['alertMatchWord'] = ''
- allAlerts[index]['AllAlert']['originalAlertCategory'] = ""
- allAlerts[index]['AllAlert']['confirmedAlertCategory'] = confirmedAlertCatStr
- allAlerts[index]['AllAlert']['feedTime'] = rec['feedTime']
- allAlerts[index]['AllAlert']['manual'] = ''
- allAlerts[index]['AllAlert']['privacy'] = rec['privacy']
- allAlerts[index]['AllAlert']['photo'] = rec['photo']
- imglink = "https://twitter.com/" + str(rec['screenName']) + "/status/" + str(rec['tweetId'])
- allAlerts[index]['AllAlert']['link'] = str(imglink)
- allAlerts[index]['AllAlert']['possibleSensitive'] = rec['possibleSensitive']
- allAlerts[index]['AllAlert']['sn_type'] = 'tw'
- index += 1
- if inuser:
- allInAlertsRecord = db_conn.select_as_dict('tbl_insta_text_alerts',where="userInsId='"+str(inuser[2])+"' and innocent=0 and (violence >1 OR inappropriate >1 OR indecency >1 OR alcohol >1 OR questionable >1 OR other >1)")
- for rec in allInAlertsRecord:
- if rec['type'] == 'caption':
- badInstaCaption = badInstaCaption + 1
- else:
- badInstaComment = badInstaComment + 1
- # create confirmed Alert category based on bit field value > 1
- confirmedAlertCat = []
- if str(rec['violence']) > '1':
- confirmedAlertCat.append('violence')
- if str(rec['inappropriate']) > '1':
- confirmedAlertCat.append('inappropriate')
- if str(rec['indecency']) > '1':
- confirmedAlertCat.append('indecency')
- if str(rec['alcohol']) > '1':
- confirmedAlertCat.append('alcohol')
- if str(rec['other']) > '1':
- confirmedAlertCat.append('other')
- if str(rec['questionable']) > '1':
- confirmedAlertCat.append('questionable')
- confirmedAlertCatStr = ','.join(confirmedAlertCat)
- allAlerts[index] = {}
- allAlerts[index]['AllAlert'] = {}
- allAlerts[index]['AllAlert']['algoQueryid'] = rec['algoQueryId']
- allAlerts[index]['AllAlert']['mediaId'] = rec['mediaId']
- allAlerts[index]['AllAlert']['feedId'] = rec['feedId']
- allAlerts[index]['AllAlert']['userInsId'] = rec['userInsId']
- allAlerts[index]['AllAlert']['fromInsId'] = rec['fromInsId']
- allAlerts[index]['AllAlert']['fromName'] = rec['fromName']
- allAlerts[index]['AllAlert']['fromScreenName'] = rec['fromScreenName']
- allAlerts[index]['AllAlert']['type'] = rec['type']
- allAlerts[index]['AllAlert']['message'] = rec['message']
- allAlerts[index]['AllAlert']['alertWord'] = rec['alertWord']
- allAlerts[index]['AllAlert']['alertMatchWord'] = rec['alertMatchWord']
- allAlerts[index]['AllAlert']['originalAlertCategory'] = ""
- allAlerts[index]['AllAlert']['confirmedAlertCategory'] = confirmedAlertCatStr
- allAlerts[index]['AllAlert']['feedTime'] = rec['feedTime']
- allAlerts[index]['AllAlert']['language'] = rec['language']
- allAlerts[index]['AllAlert']['link'] = rec['link']
- allAlerts[index]['AllAlert']['sn_type'] = 'in'
- index = index+1
- allInImageAlertsRecord = db_conn.select_as_dict('tbl_insta_photos',where="userInsId='"+str(inuser[2])+"' and innocent=0 and (violence >1 OR inappropriate >1 OR indecency >1 OR alcohol >1 OR questionable >1 OR smoking >1)")
- for rec in allInImageAlertsRecord:
- badImages = badImages + 1
- badInstaMedia = badInstaMedia + 1
- # create confirmed Alert category based on bit field value > 1
- confirmedAlertCat = []
- if str(rec['violence']) > '1':
- confirmedAlertCat.append('violence')
- if str(rec['inappropriate']) > '1':
- confirmedAlertCat.append('inappropriate')
- if str(rec['indecency']) > '1':
- confirmedAlertCat.append('indecency')
- if str(rec['alcohol']) > '1':
- confirmedAlertCat.append('alcohol')
- if str(rec['smoking']) > '1':
- confirmedAlertCat.append('smoking')
- if str(rec['questionable']) > '1':
- confirmedAlertCat.append('questionable')
- confirmedAlertCatStr = ','.join(confirmedAlertCat)
- allAlerts[index] = {}
- allAlerts[index]['AllAlert'] = {}
- allAlerts[index]['AllAlert']['algoQueryid'] = hashlib.md5(str(rec['mediaId'])).hexdigest()
- allAlerts[index]['AllAlert']['mediaId'] = rec['mediaId']
- allAlerts[index]['AllAlert']['feedId'] = rec['fromInsId']
- allAlerts[index]['AllAlert']['userInsId'] = rec['userInsId']
- allAlerts[index]['AllAlert']['fromInsId'] = rec['userInsId']
- allAlerts[index]['AllAlert']['fromName'] = rec['fromName']
- allAlerts[index]['AllAlert']['fromScreenName'] = rec['fromScreenName']
- allAlerts[index]['AllAlert']['type'] = 'bad_image'
- allAlerts[index]['AllAlert']['description'] = ''
- allAlerts[index]['AllAlert']['photoType'] = ''
- allAlerts[index]['AllAlert']['message'] = ''
- allAlerts[index]['AllAlert']['messageTag'] = ''
- allAlerts[index]['AllAlert']['alertWord'] = ''
- allAlerts[index]['AllAlert']['alertMatchWord'] = ''
- allAlerts[index]['AllAlert']['originalAlertCategory'] = ""
- allAlerts[index]['AllAlert']['confirmedAlertCategory'] = confirmedAlertCatStr
- allAlerts[index]['AllAlert']['feedTime'] = rec['feedTime']
- allAlerts[index]['AllAlert']['manual'] = ''
- allAlerts[index]['AllAlert']['photo'] = rec['photo']
- allAlerts[index]['AllAlert']['link'] = rec['link']
- allAlerts[index]['AllAlert']['sn_type'] = 'in'
- index = index + 1
- if len(allAlertsRecord) == 0 and len(allImageAlertsRecord) == 0:
- report['noAlert'] = 1
- oldCount['badPosts'] = badPost
- oldCount['badComments'] = badComments
- oldCount['badShares'] = badShare
- oldCount['badImages'] = badImages
- totalFeedCount = 0
- totalAlert = badPost + badComments + badShare
- totalTweetAlert = badTweet + badTweetPhoto
- totalInAlert = badInstaComment + badInstaCaption + badInstaMedia
- totalImageCount = 0
- totalTweetCount = 0
- totalTweetMediaCount = 0
- totalInstaCount = 0
- totalInstaMediaCount = 0
- if fbuser:
- images = db_conn.selectCount("SELECT count(id) from tbl_fb_photos where userFbId='"+str(fbuser[0])+"'")
- likes = db_conn.selectCount("SELECT count(id) from tbl_fb_photos where userFbId='"+str(fbuser[0])+"' and photoType='like_photo'")
- totalImageCount = images[0]
- totalLikeCount = likes[0]
- fbcounts = db_conn.selectOne('tbl_fb_user_counts', "fbid='" + str(fbuser[0]) + "'")
- if fbcounts:
- textcount = json.loads(fbcounts[1])
- imagecount = json.loads(fbcounts[2])
- totalCounts['feeds'] = {}
- totalCounts['feeds']['all'] = textcount['commentCount'] + textcount['postCount'] + textcount['sharedCount']
- totalFeedCount = totalCounts['feeds']['all']
- totalCounts['feeds']['posts'] = textcount['postCount']
- totalCounts['feeds']['comments'] = textcount['commentCount']
- totalCounts['feeds']['shares'] = textcount['sharedCount']
- totalCounts['images'] = {}
- totalCounts['images']['tagged'] = imagecount['photoTagged']
- totalCounts['images']['upload'] = imagecount['photoUploadedCount']
- totalCounts['images']['like'] = imagecount['photoLikedCount']
- totalCounts['feeds']['images'] = totalImageCount
- totalCounts['feeds']['likes'] = totalLikeCount
- totalCounts['alerts'] = len(allAlertsRecord)
- totalImageCount = imagecount['photoTagged'] + imagecount['photoUploadedCount'] + imagecount['photoLikedCount']
- if twuser:
- totalAlert = totalAlert + badTweetPhoto + badShare
- twcounts = db_conn.selectOne('tbl_tw_user_counts',"twid='"+str(twuser[2])+"'")
- tw_images = db_conn.selectCount("SELECT count(id) from tbl_tw_photos where userTwId='"+str(twuser[2])+"'")
- totalTweetMediaCount = tw_images[0]
- if twcounts:
- tweetcount = json.loads(twcounts[1])
- photocount = json.loads(twcounts[2])
- totalCounts['tweets'] = {}
- totalCounts['tweets']['all'] = tweetcount['tweet'] + tweetcount['retweet']
- totalTweetCount = totalCounts['tweets']['all']
- totalCounts['tweets']['tweet'] = tweetcount['tweet']
- totalCounts['tweets']['retweet'] = tweetcount['retweet']
- totalTweetCount = totalCounts['tweets']['all']
- totalCounts['tweetimages'] = {}
- totalCounts['tweetimages']['all'] = photocount['tweet'] + photocount['retweet']
- totalCounts['tweetimages']['tweet'] = photocount['tweet']
- totalCounts['tweetimages']['retweet'] = photocount['retweet']
- if inuser:
- incounts = db_conn.selectOne('tbl_insta_user_counts',"instagramId='"+str(inuser[2])+"'")
- if incounts:
- intexcount = json.loads(incounts[2])
- inimagecount = incounts[1]
- totalCounts['instagram'] = {}
- totalCounts['instagram']['all'] = intexcount['commentCount'] + intexcount['captionCount']+inimagecount
- totalCounts['instagram']['comment'] = intexcount['commentCount']
- totalCounts['instagram']['caption'] = intexcount['captionCount']
- totalCounts['instagram']['media'] = inimagecount
- totalInstaCount = intexcount['commentCount'] + intexcount['captionCount']
- totalInstaMediaCount = inimagecount
- report['oldCount'] = json.dumps(json.dumps(oldCount) )
- #new count and old count are equal for now, a new future feature will update the new count
- report['newCount'] = json.dumps(json.dumps(oldCount))
- report['netCount'] = json.dumps(json.dumps(totalCounts) )
- report['joinningDate'] = str(user[0])
- report['approvalDate'] = str(user[1])
- from pprint import pprint
- pprint(allAlerts)
- report['report'] = json.dumps(allAlerts, default=date_handler)
- report['id'] = hashlib.md5(str(time.time())+str(fbuser[0])).hexdigest()
- rectime = time.strftime('%Y-%m-%d %H:%M:%S')
- try:
- if report['reportType'] == '2':
- db_conn.updateRec('tbl_reports', "user_id='"+str(report['user_id'])+"'",
- report=report['report'],
- created=rectime,
- modified=rectime)
- db_conn.updateRec('tbl_users', "id='"+str(report['user_id'])+"'",
- is_new=1, mail_status="detail_report_mail", status=10, regenerate_report=0, modified=rectime, last_email_sent=rectime)
- logger.info("Detailed report regenerated for user %s",user_id)
- return
- if report['reportType'] == '3':
- db_conn.updateRec('tbl_reports', "user_id='"+str(report['user_id'])+"'",
- report=report['report'],
- created=rectime,
- modified=rectime)
- db_conn.updateRec('tbl_users',"id='"+str(report['user_id'])+"'",
- is_new=1, mail_status="detail_report_mail", status=10, regenerate_report=0, modified=rectime, last_email_sent=rectime)
- sendDailyReportMail(report['id'], report['user_id'], fbuser[0], fbuser[1], user[2], config, mailFlag, user[3], pro=True)
- logger.info("Detailed 24h report generated for user %s", user_id)
- return
- db_conn.sqlQuery("INSERT into tbl_reports (id,user_id,report,newCounts,oldCounts,netCounts,approvalDate,reportType,created,modified) values ('" + str(report['id']) + "'," + report['user_id'] + "," + json.dumps(report['report'])+","+report['newCount']+","+report['oldCount']+","+report['netCount']+",'"+report['approvalDate']+"',"+str(report['reportType'])+",'"+rectime+"','"+rectime+"')")
- if sn == 'fb':
- if 'noAlert' in report:
- if(sendNoDetailAlertMail(report['id'],report['user_id'],fbuser[0],fbuser[1],user[2],totalFeedCount,totalImageCount,totalCounts['feeds']['posts'],totalCounts['feeds']['comments'],totalCounts['feeds']['shares'],totalCounts['feeds']['likes'],config,mailFlag,user[3])):
- rectime = time.strftime('%Y-%m-%d %H:%M:%S')
- db_conn.updateRec('tbl_reports',"id='"+str(report['id'])+"'",mailStatus=2,modified=rectime)
- db_conn.updateRec('tbl_users',"id='"+str(report['user_id'])+"'",mail_status="detail_report_mail",status=10,modified=rectime, last_email_sent=rectime)
- else:
- if(sendDetailReportMail(report['id'],report['user_id'],fbuser[0],fbuser[1],user[2],badImages,totalImageCount,config,mailFlag,user[3])):
- rectime = time.strftime('%Y-%m-%d %H:%M:%S')
- db_conn.updateRec('tbl_reports',"id='"+str(report['id'])+"'",mailStatus=1,modified=rectime)
- db_conn.updateRec('tbl_users',"id='"+str(report['user_id'])+"'",mail_status="detail_report_mail", status=10, modified=rectime, last_email_sent=rectime)
- elif sn == 'tw':
- if 'noAlert' in report:
- if(sendNoDetailTwAlertMail(report['id'],report['user_id'],twuser[2],twuser[3],user[2],totalTweetCount,totalTweetMediaCount,config,mailFlag,user[3])):
- rectime = time.strftime('%Y-%m-%d %H:%M:%S')
- db_conn.updateRec('tbl_reports',"id='"+str(report['id'])+"'",mailStatus=2,modified=rectime)
- db_conn.updateRec('tbl_users',"id='"+str(report['user_id'])+"'",mail_status="detail_report_mail",twitterStatus=10,modified=rectime, last_email_sent=rectime)
- else:
- if(sendDetailTwReportMail(report['id'],report['user_id'],twuser[2],twuser[3],user[2],config,mailFlag,user[3])):
- rectime = time.strftime('%Y-%m-%d %H:%M:%S')
- db_conn.updateRec('tbl_reports',"id='"+str(report['id'])+"'",mailStatus=1,modified=rectime)
- db_conn.updateRec('tbl_users',"id='"+str(report['user_id'])+"'",mail_status="detail_report_mail",twitterStatus=10,modified=rectime, last_email_sent=rectime)
- elif sn == 'in':
- if 'noAlert' in report:
- if(sendNoDetailInAlertMail(report['id'],report['user_id'],inuser[4],user[2],totalInstaCount,totalInstaMediaCount,config,mailFlag,user[3])):
- rectime = time.strftime('%Y-%m-%d %H:%M:%S')
- db_conn.updateRec('tbl_reports',"id='"+str(report['id'])+"'",mailStatus=2,modified=rectime)
- db_conn.updateRec('tbl_users',"id='"+str(report['user_id'])+"'",mail_status="detail_report_mail",instagramStatus=10,modified=rectime, last_email_sent=rectime)
- else:
- if(sendDetailInReportMail(report['id'], report['user_id'], inuser[4], user[2], config, mailFlag, user[3])):
- rectime = time.strftime('%Y-%m-%d %H:%M:%S')
- db_conn.updateRec('tbl_reports',"id='"+str(report['id'])+"'",mailStatus=1,modified=rectime)
- db_conn.updateRec('tbl_users',"id='"+str(report['user_id'])+"'",mail_status="detail_report_mail",instagramStatus=10,modified=rectime, last_email_sent=rectime)
- logger.info("Detailed report generated for user %s",user_id)
- except Exception as e:
- logger.error("Unable to create detailed report for user id %s with error %s"%(user_id,str(e)))
- # process to send email to admins that user is ready to review
- def notify_admin(type,user_id,db_conn,g_admin_emails,config):
- logger = logging.getLogger("repnuplogger")
- fbuser = db_conn.selectOne('tbl_fb_users',"user_id='"+str(user_id)+"'",'fbid','fbname','textStatus','imageStatus')
- logger.info("Sending mail to admin to review user for fb %s"%str(fbuser[0]))
- host_name = config.get('smtp_settings','host')
- user_name = config.get('smtp_settings','username')
- password = config.get('smtp_settings','password')
- mail_template_path = config.get('smtp_settings','mail_template_path')
- siteurl = config.get('admin_settings','site_url')
- sender = config.get('smtp_settings','sender')
- cc_address = config.get('admin_settings','cc_email')
- if fbuser:
- if str(fbuser[2]) =="3":
- try:
- fo = open(os.path.join(mail_template_path, 'admin_report_ready.html'))
- filecontent = fo.read()
- fo.close()
- messagebody = filecontent.replace("site_url", siteurl)
- fbuser_name = fbuser[1].encode('utf-8')
- messagebody = messagebody.replace("fb_user_id", str(user_id))
- messagebody = messagebody.replace("fb_user_name", fbuser_name)
- fbuser_name = fbuser[1].encode('utf-8')
- msgRoot = MIMEMultipart('related')
- if type ==1:
- msgRoot['Subject'] = "Please review text for " + fbuser_name
- else :
- msgRoot['Subject'] = "Please review images for " + fbuser_name
- msgRoot['From'] = "RepNup <reports@repnup.com>"
- msgRoot['To'] = g_admin_emails
- msgRoot.preamble = 'This is a multi-part message in MIME format.'
- s = smtplib.SMTP(host_name)
- s.set_debuglevel(0)
- s.ehlo()
- if s.has_extn('STARTTLS'):
- s.starttls()
- s.ehlo()
- s.login(user_name,password)
- html_body = MIMEText(messagebody,'html')
- msg= MIMEMultipart('alternative')
- msgRoot.attach(msg)
- msg.attach(html_body)
- attachment = os.path.join(mail_template_path,'rep.png')
- fp = open(attachment,'rb')
- img = MIMEImage(fp.read())
- fp.close()
- img.add_header('Content-ID',"<header-image>")
- img.add_header('Content-Disposition', 'inline', filename='rep.png')
- attachment2 = os.path.join(mail_template_path,'fb.png')
- fp1 = open(attachment2,'rb')
- fbimg = MIMEImage(fp1.read())
- fp1.close()
- fbimg.add_header('Content-ID',"<fb-icon-image>")
- fbimg.add_header('Content-Disposition', 'inline', filename='fb.png')
- attachment3 = os.path.join(mail_template_path,'tw.png')
- fp2 = open(attachment3,'rb')
- twimg = MIMEImage(fp2.read())
- fp2.close()
- twimg.add_header('Content-ID',"<tw-icon-image>")
- twimg.add_header('Content-Disposition', 'inline', filename='tw.png')
- msg.attach(img)
- TOADDR = [msgRoot['To']]
- s.sendmail(sender,TOADDR,msgRoot.as_string())
- s.quit()
- rectime = time.strftime('%Y-%m-%d %H:%M:%S')
- if type ==1:
- db_conn.updateRec('tbl_users',"id='"+str(user_id)+"'",mail_status="admin_review_mail",status=4,modified=rectime)
- else:
- db_conn.updateRec('tbl_users',"id='"+str(user_id)+"'",mail_status="admin_review_mail",status=8,modified=rectime)
- logger.info("Successfully send mail to admin to review user %s"%str(fbuser[0]))
- return True
- except Exception as e:
- logger.error("Error while sending email to admin for facebook user %s"%str(e))
- return False
- else:
- return False
- #Send initial report email to user
- def sendInitialMail(report_id,user_id,fbid,fbname,email,totalFeedCount,totalAlert,totalImageCount,config,mailFlag,uuid):
- if mailFlag == False:
- return True
- logger = logging.getLogger("repnuplogger")
- logger.info("Sending initial summary mail to user %s",user_id)
- host_name = config.get('smtp_settings','host')
- user_name = config.get('smtp_settings','username')
- password = config.get('smtp_settings','password')
- mail_template_path = config.get('smtp_settings','mail_template_path')
- siteurl = config.get('admin_settings','site_url')
- sender = config.get('smtp_settings','sender')
- cc_address = config.get('admin_settings','cc_email')
- uuid = str(uuid)
- #email = 'marcomtl@gmail.com';
- try:
- fo = open(os.path.join(mail_template_path,'initial_report.html'))
- filecontent = fo.read()
- fo.close()
- messagebody = filecontent.replace("site_url",siteurl)
- fbuser_name = fbname.encode('utf-8')
- messagebody = messagebody.replace("app_user_name",fbuser_name)
- messagebody = messagebody.replace("user_uuid",str(uuid))
- msgRoot = MIMEMultipart('related')
- msgRoot['Subject'] = "Your social media initial report from RepNup"
- msgRoot['From'] = "RepNup <reports@repnup.com>"
- msgRoot['To'] = email
- msgRoot['Bcc'] = cc_address
- msgRoot.preamble = 'This is a multi-part message in MIME format.'
- s = smtplib.SMTP(host_name)
- s.set_debuglevel(0)
- s.ehlo()
- if s.has_extn('STARTTLS'):
- s.starttls()
- s.ehlo()
- s.login(user_name,password)
- html_body = MIMEText(messagebody,'html')
- msg= MIMEMultipart('alternative')
- msgRoot.attach(msg)
- msg.attach(html_body)
- attachment = os.path.join(mail_template_path,'logo.jpg')
- fp = open(attachment,'rb')
- img = MIMEImage(fp.read())
- fp.close()
- img.add_header('Content-ID',"<logo-image>")
- img.add_header('Content-Disposition', 'inline', filename='logo.jpg')
- attachment2 = os.path.join(mail_template_path,'top-left-white-corner.gif')
- fp1 = open(attachment2,'rb')
- topleftwhiteimg = MIMEImage(fp1.read())
- fp1.close()
- topleftwhiteimg.add_header('Content-ID',"<top-left-white-image>")
- topleftwhiteimg.add_header('Content-Disposition', 'inline', filename='top-left-white-corner.gif')
- attachment3 = os.path.join(mail_template_path,'top-right-white-corner.gif')
- fp2 = open(attachment3,'rb')
- toprightwhiteimg = MIMEImage(fp2.read())
- fp2.close()
- toprightwhiteimg.add_header('Content-ID',"<top-right-white-image>")
- toprightwhiteimg.add_header('Content-Disposition', 'inline', filename='top-right-white-corner.gif')
- attachment4 = os.path.join(mail_template_path,'top-left-blue-corner.gif')
- fp3 = open(attachment4,'rb')
- topleftblueimg = MIMEImage(fp3.read())
- fp3.close()
- topleftblueimg.add_header('Content-ID',"<top-left-blue-image>")
- topleftblueimg.add_header('Content-Disposition', 'inline', filename='top-left-blue-corner.gif')
- attachment5 = os.path.join(mail_template_path,'top-right-blue-corner.gif')
- fp4 = open(attachment5,'rb')
- toprightblueimg = MIMEImage(fp4.read())
- fp4.close()
- toprightblueimg.add_header('Content-ID',"<top-right-blue-image>")
- toprightblueimg.add_header('Content-Disposition', 'inline', filename='top-right-blue-corner.gif')
- attachment6 = os.path.join(mail_template_path,'report_in_process.jpg')
- fp5 = open(attachment6,'rb')
- reportimg = MIMEImage(fp5.read())
- fp5.close()
- reportimg.add_header('Content-ID',"<report-image>")
- reportimg.add_header('Content-Disposition', 'inline', filename='report_in_process.jpg')
- attachment7 = os.path.join(mail_template_path,'bottom-left-blue-corner.gif')
- fp6 = open(attachment7,'rb')
- bottomleftblueimg = MIMEImage(fp6.read())
- fp6.close()
- bottomleftblueimg.add_header('Content-ID',"<bottom-left-blue-image>")
- bottomleftblueimg.add_header('Content-Disposition', 'inline', filename='bottom-left-blue-corner.gif')
- attachment8 = os.path.join(mail_template_path,'bottom-right-blue-corner.gif')
- fp7 = open(attachment8,'rb')
- bottomrightblueimg = MIMEImage(fp7.read())
- fp7.close()
- bottomrightblueimg.add_header('Content-ID',"<bottom-right-blue-image>")
- bottomrightblueimg.add_header('Content-Disposition', 'inline', filename='bottom-right-blue-corner.gif')
- attachment9 = os.path.join(mail_template_path,'bottom-left-brown-corner.gif')
- fp8 = open(attachment9,'rb')
- bottomleftbrownimg = MIMEImage(fp8.read())
- fp8.close()
- bottomleftbrownimg.add_header('Content-ID',"<bottom-left-brown-image>")
- bottomleftbrownimg.add_header('Content-Disposition', 'inline', filename='bottom-left-brown-corner.gif')
- attachment10 = os.path.join(mail_template_path,'bottom-right-brown-corner.gif')
- fp9 = open(attachment10,'rb')
- bottomrightbrownimg = MIMEImage(fp9.read())
- fp9.close()
- bottomrightbrownimg.add_header('Content-ID',"<bottom-right-brown-image>")
- bottomrightbrownimg.add_header('Content-Disposition', 'inline', filename='bottom-right-brown-corner.gif')
- attachment11 = os.path.join(mail_template_path,'fb.jpg')
- fp10 = open(attachment11,'rb')
- fbimg = MIMEImage(fp10.read())
- fp10.close()
- fbimg.add_header('Content-ID',"<fb-image>")
- fbimg.add_header('Content-Disposition', 'inline', filename='fb.jpg')
- attachment12 = os.path.join(mail_template_path,'tw.jpg')
- fp11 = open(attachment12,'rb')
- twimg = MIMEImage(fp11.read())
- fp11.close()
- twimg.add_header('Content-ID',"<tw-image>")
- twimg.add_header('Content-Disposition', 'inline', filename='tw.jpg')
- attachment13 = os.path.join(mail_template_path,'lnk.jpg')
- fp12 = open(attachment13,'rb')
- lknimg = MIMEImage(fp12.read())
- fp12.close()
- lknimg.add_header('Content-ID',"<link-image>")
- lknimg.add_header('Content-Disposition', 'inline', filename='lnk.jpg')
- msgRoot.attach(img)
- msgRoot.attach(topleftwhiteimg)
- msgRoot.attach(toprightwhiteimg)
- msgRoot.attach(topleftblueimg)
- msgRoot.attach(toprightblueimg)
- msgRoot.attach(reportimg)
- msgRoot.attach(bottomleftblueimg)
- msgRoot.attach(bottomrightblueimg)
- msgRoot.attach(bottomleftbrownimg)
- msgRoot.attach(bottomrightbrownimg)
- msgRoot.attach(fbimg)
- msgRoot.attach(twimg)
- msgRoot.attach(lknimg)
- TOADDR = [msgRoot['To']]
- CCADDR = [msgRoot['Bcc']]
- s.sendmail(sender,TOADDR+CCADDR,msgRoot.as_string())
- s.quit()
- logger.info("Successfully send summary mail to user %s"%str(user_id))
- return True
- except Exception as e:
- logger.error("Error while sending email %s"%str(e))
- return False
- # Send summary email to user
- def sendSummaryMail(report_id, user_id, fbid, fbname, email, totalFeedCount, totalAlert, totalImageCount, config, mailFlag, uuid):
- if mailFlag == False:
- return True
- logger = logging.getLogger("repnuplogger")
- logger.info("Sending summary mail to user %s with report id %s"%(user_id,str(report_id)))
- host_name = config.get('smtp_settings','host')
- user_name = config.get('smtp_settings','username')
- password = config.get('smtp_settings','password')
- mail_template_path = config.get('smtp_settings','mail_template_path')
- siteurl = config.get('admin_settings','site_url')
- sender = config.get('smtp_settings','sender')
- cc_address = config.get('admin_settings','cc_email')
- #email = 'margomtl@gmail.com'
- fbuser_name = fbname.encode('utf-8')
- uuid = str(uuid)
- try:
- fo = open(os.path.join(mail_template_path,'summary_report.html'))
- filecontent = fo.read()
- fo.close()
- messagebody = filecontent.replace("site_url",siteurl)
- messagebody = messagebody.replace("app_user_name",str(fbuser_name))
- messagebody = messagebody.replace("user_total_feed",str(totalFeedCount))
- messagebody = messagebody.replace("user_total_alerts",str(totalAlert))
- messagebody = messagebody.replace("user_total_images",str(totalImageCount))
- messagebody = messagebody.replace("user_uuid",str(uuid))
- msgRoot = MIMEMultipart('related')
- msgRoot['Subject'] = "Your social media summary report from RepNup"
- msgRoot['From'] = "RepNup <reports@repnup.com>"
- msgRoot['To'] = email
- msgRoot['Bcc'] = cc_address
- msgRoot.preamble = 'This is a multi-part message in MIME format.'
- s = smtplib.SMTP(host_name)
- s.set_debuglevel(0)
- s.ehlo()
- if s.has_extn('STARTTLS'):
- s.starttls()
- s.ehlo()
- s.login(user_name,password)
- html_body = MIMEText(messagebody,'html')
- msg= MIMEMultipart('alternative')
- msgRoot.attach(msg)
- msg.attach(html_body)
- attachment = os.path.join(mail_template_path,'logo.jpg')
- fp = open(attachment,'rb')
- img = MIMEImage(fp.read())
- fp.close()
- img.add_header('Content-ID',"<logo-image>")
- img.add_header('Content-Disposition', 'inline', filename='logo.jpg')
- attachment2 = os.path.join(mail_template_path,'top-left-white-corner.gif')
- fp1 = open(attachment2,'rb')
- topleftwhiteimg = MIMEImage(fp1.read())
- fp1.close()
- topleftwhiteimg.add_header('Content-ID',"<top-left-white-image>")
- topleftwhiteimg.add_header('Content-Disposition', 'inline', filename='top-left-white-corner.gif')
- attachment3 = os.path.join(mail_template_path,'top-right-white-corner.gif')
- fp2 = open(attachment3,'rb')
- toprightwhiteimg = MIMEImage(fp2.read())
- fp2.close()
- toprightwhiteimg.add_header('Content-ID',"<top-right-white-image>")
- toprightwhiteimg.add_header('Content-Disposition', 'inline', filename='top-right-white-corner.gif')
- attachment4 = os.path.join(mail_template_path,'top-left-blue-corner.gif')
- fp3 = open(attachment4,'rb')
- topleftblueimg = MIMEImage(fp3.read())
- fp3.close()
- topleftblueimg.add_header('Content-ID',"<top-left-blue-image>")
- topleftblueimg.add_header('Content-Disposition', 'inline', filename='top-left-blue-corner.gif')
- attachment5 = os.path.join(mail_template_path,'top-right-blue-corner.gif')
- fp4 = open(attachment5,'rb')
- toprightblueimg = MIMEImage(fp4.read())
- fp4.close()
- toprightblueimg.add_header('Content-ID',"<top-right-blue-image>")
- toprightblueimg.add_header('Content-Disposition', 'inline', filename='top-right-blue-corner.gif')
- attachment6 = os.path.join(mail_template_path,'report_ready.jpg')
- fp5 = open(attachment6,'rb')
- reportimg = MIMEImage(fp5.read())
- fp5.close()
- reportimg.add_header('Content-ID',"<report-ready-image>")
- reportimg.add_header('Content-Disposition', 'inline', filename='report_ready.jpg')
- attachment7 = os.path.join(mail_template_path,'bottom-left-blue-corner.gif')
- fp6 = open(attachment7,'rb')
- bottomleftblueimg = MIMEImage(fp6.read())
- fp6.close()
- bottomleftblueimg.add_header('Content-ID',"<bottom-left-blue-image>")
- bottomleftblueimg.add_header('Content-Disposition', 'inline', filename='bottom-left-blue-corner.gif')
- attachment8 = os.path.join(mail_template_path,'bottom-right-blue-corner.gif')
- fp7 = open(attachment8,'rb')
- bottomrightblueimg = MIMEImage(fp7.read())
- fp7.close()
- bottomrightblueimg.add_header('Content-ID',"<bottom-right-blue-image>")
- bottomrightblueimg.add_header('Content-Disposition', 'inline', filename='bottom-right-blue-corner.gif')
- attachment9 = os.path.join(mail_template_path,'bottom-left-brown-corner.gif')
- fp8 = open(attachment9,'rb')
- bottomleftbrownimg = MIMEImage(fp8.read())
- fp8.close()
- bottomleftbrownimg.add_header('Content-ID',"<bottom-left-brown-image>")
- bottomleftbrownimg.add_header('Content-Disposition', 'inline', filename='bottom-left-brown-corner.gif')
- attachment10 = os.path.join(mail_template_path,'bottom-right-brown-corner.gif')
- fp9 = open(attachment10,'rb')
- bottomrightbrownimg = MIMEImage(fp9.read())
- fp9.close()
- bottomrightbrownimg.add_header('Content-ID',"<bottom-right-brown-image>")
- bottomrightbrownimg.add_header('Content-Disposition', 'inline', filename='bottom-right-brown-corner.gif')
- attachment11 = os.path.join(mail_template_path,'fb.jpg')
- fp10 = open(attachment11,'rb')
- fbimg = MIMEImage(fp10.read())
- fp10.close()
- fbimg.add_header('Content-ID',"<fb-image>")
- fbimg.add_header('Content-Disposition', 'inline', filename='fb.jpg')
- attachment12 = os.path.join(mail_template_path,'tw.jpg')
- fp11 = open(attachment12,'rb')
- twimg = MIMEImage(fp11.read())
- fp11.close()
- twimg.add_header('Content-ID',"<tw-image>")
- twimg.add_header('Content-Disposition', 'inline', filename='tw.jpg')
- attachment13 = os.path.join(mail_template_path,'lnk.jpg')
- fp12 = open(attachment13,'rb')
- lknimg = MIMEImage(fp12.read())
- fp12.close()
- lknimg.add_header('Content-ID',"<link-image>")
- lknimg.add_header('Content-Disposition', 'inline', filename='lnk.jpg')
- attachment14 = os.path.join(mail_template_path,'top-left-green-corner.gif')
- fp13 = open(attachment14,'rb')
- topgreenleft = MIMEImage(fp13.read())
- fp13.close()
- topgreenleft.add_header('Content-ID',"top-left-green-image>")
- topgreenleft.add_header('Content-Disposition', 'inline', filename='top-left-green-corner.gif')
- attachment15 = os.path.join(mail_template_path,'top-right-green-corner.gif')
- fp14 = open(attachment15,'rb')
- topgreenright = MIMEImage(fp14.read())
- fp14.close()
- topgreenright.add_header('Content-ID',"top-right-green-image>")
- topgreenright.add_header('Content-Disposition', 'inline', filename='top-right-green-corner.gif')
- attachment16 = os.path.join(mail_template_path,'bottom-left-green-corner.gif')
- fp15 = open(attachment16,'rb')
- bottomleftgreen = MIMEImage(fp15.read())
- fp15.close()
- bottomleftgreen.add_header('Content-ID',"bottom-left-green-image>")
- bottomleftgreen.add_header('Content-Disposition', 'inline', filename='bottom-left-green-corner.gif')
- attachment17 = os.path.join(mail_template_path,'bottom-right-green-corner.gif')
- fp16 = open(attachment17,'rb')
- bottomrightgreen = MIMEImage(fp16.read())
- fp16.close()
- bottomrightgreen.add_header('Content-ID',"bottom-right-green-image>")
- bottomrightgreen.add_header('Content-Disposition', 'inline', filename='bottom-right-green-corner.gif')
- msgRoot.attach(img)
- msgRoot.attach(topleftwhiteimg)
- msgRoot.attach(toprightwhiteimg)
- msgRoot.attach(topleftblueimg)
- msgRoot.attach(toprightblueimg)
- msgRoot.attach(reportimg)
- msgRoot.attach(bottomleftblueimg)
- msgRoot.attach(bottomrightblueimg)
- msgRoot.attach(bottomleftbrownimg)
- msgRoot.attach(bottomrightbrownimg)
- msgRoot.attach(fbimg)
- msgRoot.attach(twimg)
- msgRoot.attach(lknimg)
- msgRoot.attach(topgreenleft)
- msgRoot.attach(topgreenright)
- msgRoot.attach(bottomleftgreen)
- msgRoot.attach(bottomrightgreen)
- TOADDR = [msgRoot['To']]
- CCADDR = [msgRoot['Bcc']]
- s.sendmail(sender,TOADDR+CCADDR,msgRoot.as_string())
- s.quit()
- logger.info("Successfully send summary mail to user %s"%str(user_id))
- return True
- except Exception as e:
- logger.error("Error while sending email %s"%str(e))
- return False
- # Send detail report email to user
- def sendDetailReportMail(report_id,user_id,fbid,fbname,email,totalImageAlert,totalImageCount,config,mailFlag,uuid):
- if mailFlag == False:
- return True
- logger = logging.getLogger("repnuplogger")
- logger.info("Sending detail report to user %s",user_id)
- host_name = config.get('smtp_settings','host')
- user_name = config.get('smtp_settings','username')
- password = config.get('smtp_settings','password')
- mail_template_path = config.get('smtp_settings','mail_template_path')
- siteurl = config.get('admin_settings','site_url')
- sender = config.get('smtp_settings','sender')
- cc_address = config.get('admin_settings','cc_email')
- uuid = str(uuid)
- #email = 'marcomtl@gmail.com'
- if totalImageCount < totalImageAlert:
- totalImageCount = totalImageAlert
- try:
- fo = open(os.path.join(mail_template_path,'detailed_report.html'))
- filecontent = fo.read()
- fo.close()
- messagebody = filecontent.replace("site_url",siteurl)
- fbuser_name = fbname.encode('utf-8')
- messagebody = messagebody.replace("app_user_name",fbuser_name)
- messagebody = messagebody.replace("image_alert_count",str(totalImageAlert))
- messagebody = messagebody.replace("total_image_count",str(totalImageCount))
- messagebody = messagebody.replace("user_uuid",uuid)
- msgRoot = MIMEMultipart('related')
- msgRoot['Subject'] = "Your social media detailed report from RepNup"
- msgRoot['From'] = "RepNup <reports@repnup.com>"
- msgRoot['To'] = email
- msgRoot['Bcc'] = cc_address
- msgRoot.preamble = 'This is a multi-part message in MIME format.'
- s = smtplib.SMTP(host_name)
- s.set_debuglevel(0)
- s.ehlo()
- if s.has_extn('STARTTLS'):
- s.starttls()
- s.ehlo()
- s.login(user_name,password)
- html_body = MIMEText(messagebody,'html')
- msg= MIMEMultipart('alternative')
- msgRoot.attach(msg)
- msg.attach(html_body)
- attachment = os.path.join(mail_template_path,'logo.jpg')
- fp = open(attachment,'rb')
- img = MIMEImage(fp.read())
- fp.close()
- img.add_header('Content-ID',"<logo-image>")
- img.add_header('Content-Disposition', 'inline', filename='logo.jpg')
- attachment2 = os.path.join(mail_template_path,'top-left-white-corner.gif')
- fp1 = open(attachment2,'rb')
- topleftwhiteimg = MIMEImage(fp1.read())
- fp1.close()
- topleftwhiteimg.add_header('Content-ID',"<top-left-white-image>")
- topleftwhiteimg.add_header('Content-Disposition', 'inline', filename='top-left-white-corner.gif')
- attachment3 = os.path.join(mail_template_path,'top-right-white-corner.gif')
- fp2 = open(attachment3,'rb')
- toprightwhiteimg = MIMEImage(fp2.read())
- fp2.close()
- toprightwhiteimg.add_header('Content-ID',"<top-right-white-image>")
- toprightwhiteimg.add_header('Content-Disposition', 'inline', filename='top-right-white-corner.gif')
- attachment4 = os.path.join(mail_template_path,'top-left-blue-corner.gif')
- fp3 = open(attachment4,'rb')
- topleftblueimg = MIMEImage(fp3.read())
- fp3.close()
- topleftblueimg.add_header('Content-ID',"<top-left-blue-image>")
- topleftblueimg.add_header('Content-Disposition', 'inline', filename='top-left-blue-corner.gif')
- attachment5 = os.path.join(mail_template_path,'top-right-blue-corner.gif')
- fp4 = open(attachment5,'rb')
- toprightblueimg = MIMEImage(fp4.read())
- fp4.close()
- toprightblueimg.add_header('Content-ID',"<top-right-blue-image>")
- toprightblueimg.add_header('Content-Disposition', 'inline', filename='top-right-blue-corner.gif')
- attachment6 = os.path.join(mail_template_path,'report_ready.jpg')
- fp5 = open(attachment6,'rb')
- reportimg = MIMEImage(fp5.read())
- fp5.close()
- reportimg.add_header('Content-ID',"<report-ready-image>")
- reportimg.add_header('Content-Disposition', 'inline', filename='report_ready.jpg')
- attachment7 = os.path.join(mail_template_path,'bottom-left-blue-corner.gif')
- fp6 = open(attachment7,'rb')
- bottomleftblueimg = MIMEImage(fp6.read())
- fp6.close()
- bottomleftblueimg.add_header('Content-ID',"<bottom-left-blue-image>")
- bottomleftblueimg.add_header('Content-Disposition', 'inline', filename='bottom-left-blue-corner.gif')
- attachment8 = os.path.join(mail_template_path,'bottom-right-blue-corner.gif')
- fp7 = open(attachment8,'rb')
- bottomrightblueimg = MIMEImage(fp7.read())
- fp7.close()
- bottomrightblueimg.add_header('Content-ID',"<bottom-right-blue-image>")
- bottomrightblueimg.add_header('Content-Disposition', 'inline', filename='bottom-right-blue-corner.gif')
- attachment9 = os.path.join(mail_template_path,'bottom-left-brown-corner.gif')
- fp8 = open(attachment9,'rb')
- bottomleftbrownimg = MIMEImage(fp8.read())
- fp8.close()
- bottomleftbrownimg.add_header('Content-ID',"<bottom-left-brown-image>")
- bottomleftbrownimg.add_header('Content-Disposition', 'inline', filename='bottom-left-brown-corner.gif')
- attachment10 = os.path.join(mail_template_path,'bottom-right-brown-corner.gif')
- fp9 = open(attachment10,'rb')
- bottomrightbrownimg = MIMEImage(fp9.read())
- fp9.close()
- bottomrightbrownimg.add_header('Content-ID',"<bottom-right-brown-image>")
- bottomrightbrownimg.add_header('Content-Disposition', 'inline', filename='bottom-right-brown-corner.gif')
- attachment11 = os.path.join(mail_template_path,'fb.jpg')
- fp10 = open(attachment11,'rb')
- fbimg = MIMEImage(fp10.read())
- fp10.close()
- fbimg.add_header('Content-ID',"<fb-image>")
- fbimg.add_header('Content-Disposition', 'inline', filename='fb.jpg')
- attachment12 = os.path.join(mail_template_path,'tw.jpg')
- fp11 = open(attachment12,'rb')
- twimg = MIMEImage(fp11.read())
- fp11.close()
- twimg.add_header('Content-ID',"<tw-image>")
- twimg.add_header('Content-Disposition', 'inline', filename='tw.jpg')
- attachment13 = os.path.join(mail_template_path,'lnk.jpg')
- fp12 = open(attachment13,'rb')
- lknimg = MIMEImage(fp12.read())
- fp12.close()
- lknimg.add_header('Content-ID',"<link-image>")
- lknimg.add_header('Content-Disposition', 'inline', filename='lnk.jpg')
- msgRoot.attach(img)
- msgRoot.attach(topleftwhiteimg)
- msgRoot.attach(toprightwhiteimg)
- msgRoot.attach(topleftblueimg)
- msgRoot.attach(toprightblueimg)
- msgRoot.attach(reportimg)
- msgRoot.attach(bottomleftblueimg)
- msgRoot.attach(bottomrightblueimg)
- msgRoot.attach(bottomleftbrownimg)
- msgRoot.attach(bottomrightbrownimg)
- msgRoot.attach(fbimg)
- msgRoot.attach(twimg)
- msgRoot.attach(lknimg)
- TOADDR = [msgRoot['To']]
- CCADDR = [msgRoot['Bcc']]
- s.sendmail(sender,TOADDR+CCADDR,msgRoot.as_string())
- s.quit()
- logger.info("Successfully send detail report mail to user %s"%str(user_id))
- return True
- except Exception as e:
- logger.error("Error while sending email %s"%str(e))
- return False
- # Send detail report email to user
- def sendDailyReportMail(report_id, user_id, fbid, fbname, email, config, mailFlag, uuid, pro=False):
- if mailFlag == False:
- return True
- logger = logging.getLogger("repnuplogger")
- logger.info("Sending detail report to user %s",user_id)
- host_name = config.get('smtp_settings','host')
- user_name = config.get('smtp_settings','username')
- password = config.get('smtp_settings','password')
- mail_template_path = config.get('smtp_settings','mail_template_path')
- siteurl = config.get('admin_settings','site_url')
- sender = config.get('smtp_settings','sender')
- cc_address = config.get('admin_settings','cc_email')
- uuid = str(uuid)
- fbuser_name = fbname.encode('utf-8')
- #email = 'marcomtl@gmail.com'
- # if totalImageCount < totalImageAlert:
- # totalImageCount = totalImageAlert
- try:
- if pro:
- fo = open(os.path.join(mail_template_path, '24h_report_pro.html'))
- else:
- fo = open(os.path.join(mail_template_path, '24h_report.html'))
- filecontent = fo.read()
- fo.close()
- messagebody = filecontent.replace("site_url",siteurl)
- fbuser_name = fbname.encode('utf-8')
- messagebody = messagebody.replace("app_user_name",fbuser_name)
- messagebody = messagebody.replace("user_uuid",uuid)
- #messagebody = messagebody.replace("image_alert_count", str(totalImageAlert))
- #messagebody = messagebody.replace("total_image_count", str(totalImageCount))
- msgRoot = MIMEMultipart('related')
- msgRoot['Subject'] = "24hour report from RepNup"
- msgRoot['From'] = "RepNup <reports@repnup.com>"
- msgRoot['To'] = email
- msgRoot['Bcc'] = cc_address
- msgRoot.preamble = 'This is a multi-part message in MIME format.'
- s = smtplib.SMTP(host_name)
- s.set_debuglevel(0)
- s.ehlo()
- if s.has_extn('STARTTLS'):
- s.starttls()
- s.ehlo()
- s.login(user_name,password)
- html_body = MIMEText(messagebody,'html')
- msg= MIMEMultipart('alternative')
- msgRoot.attach(msg)
- msg.attach(html_body)
- attachment = os.path.join(mail_template_path,'logo.jpg')
- fp = open(attachment,'rb')
- img = MIMEImage(fp.read())
- fp.close()
- img.add_header('Content-ID',"<logo-image>")
- img.add_header('Content-Disposition', 'inline', filename='logo.jpg')
- attachment2 = os.path.join(mail_template_path,'top-left-white-corner.gif')
- fp1 = open(attachment2,'rb')
- topleftwhiteimg = MIMEImage(fp1.read())
- fp1.close()
- topleftwhiteimg.add_header('Content-ID',"<top-left-white-image>")
- topleftwhiteimg.add_header('Content-Disposition', 'inline', filename='top-left-white-corner.gif')
- attachment3 = os.path.join(mail_template_path,'top-right-white-corner.gif')
- fp2 = open(attachment3,'rb')
- toprightwhiteimg = MIMEImage(fp2.read())
- fp2.close()
- toprightwhiteimg.add_header('Content-ID',"<top-right-white-image>")
- toprightwhiteimg.add_header('Content-Disposition', 'inline', filename='top-right-white-corner.gif')
- attachment4 = os.path.join(mail_template_path,'top-left-blue-corner.gif')
- fp3 = open(attachment4,'rb')
- topleftblueimg = MIMEImage(fp3.read())
- fp3.close()
- topleftblueimg.add_header('Content-ID',"<top-left-blue-image>")
- topleftblueimg.add_header('Content-Disposition', 'inline', filename='top-left-blue-corner.gif')
- attachment5 = os.path.join(mail_template_path,'top-right-blue-corner.gif')
- fp4 = open(attachment5,'rb')
- toprightblueimg = MIMEImage(fp4.read())
- fp4.close()
- toprightblueimg.add_header('Content-ID',"<top-right-blue-image>")
- toprightblueimg.add_header('Content-Disposition', 'inline', filename='top-right-blue-corner.gif')
- attachment6 = os.path.join(mail_template_path,'report_ready.jpg')
- fp5 = open(attachment6,'rb')
- reportimg = MIMEImage(fp5.read())
- fp5.close()
- reportimg.add_header('Content-ID',"<report-ready-image>")
- reportimg.add_header('Content-Disposition', 'inline', filename='report_ready.jpg')
- attachment7 = os.path.join(mail_template_path,'bottom-left-blue-corner.gif')
- fp6 = open(attachment7,'rb')
- bottomleftblueimg = MIMEImage(fp6.read())
- fp6.close()
- bottomleftblueimg.add_header('Content-ID',"<bottom-left-blue-image>")
- bottomleftblueimg.add_header('Content-Disposition', 'inline', filename='bottom-left-blue-corner.gif')
- attachment8 = os.path.join(mail_template_path,'bottom-right-blue-corner.gif')
- fp7 = open(attachment8,'rb')
- bottomrightblueimg = MIMEImage(fp7.read())
- fp7.close()
- bottomrightblueimg.add_header('Content-ID',"<bottom-right-blue-image>")
- bottomrightblueimg.add_header('Content-Disposition', 'inline', filename='bottom-right-blue-corner.gif')
- attachment9 = os.path.join(mail_template_path,'bottom-left-brown-corner.gif')
- fp8 = open(attachment9,'rb')
- bottomleftbrownimg = MIMEImage(fp8.read())
- fp8.close()
- bottomleftbrownimg.add_header('Content-ID',"<bottom-left-brown-image>")
- bottomleftbrownimg.add_header('Content-Disposition', 'inline', filename='bottom-left-brown-corner.gif')
- attachment10 = os.path.join(mail_template_path,'bottom-right-brown-corner.gif')
- fp9 = open(attachment10,'rb')
- bottomrightbrownimg = MIMEImage(fp9.read())
- fp9.close()
- bottomrightbrownimg.add_header('Content-ID',"<bottom-right-brown-image>")
- bottomrightbrownimg.add_header('Content-Disposition', 'inline', filename='bottom-right-brown-corner.gif')
- attachment11 = os.path.join(mail_template_path,'fb.jpg')
- fp10 = open(attachment11,'rb')
- fbimg = MIMEImage(fp10.read())
- fp10.close()
- fbimg.add_header('Content-ID',"<fb-image>")
- fbimg.add_header('Content-Disposition', 'inline', filename='fb.jpg')
- attachment12 = os.path.join(mail_template_path,'tw.jpg')
- fp11 = open(attachment12,'rb')
- twimg = MIMEImage(fp11.read())
- fp11.close()
- twimg.add_header('Content-ID',"<tw-image>")
- twimg.add_header('Content-Disposition', 'inline', filename='tw.jpg')
- attachment13 = os.path.join(mail_template_path,'lnk.jpg')
- fp12 = open(attachment13,'rb')
- lknimg = MIMEImage(fp12.read())
- fp12.close()
- lknimg.add_header('Content-ID',"<link-image>")
- lknimg.add_header('Content-Disposition', 'inline', filename='lnk.jpg')
- attachment14 = os.path.join(mail_template_path,'top-left-green-corner.gif')
- fp13 = open(attachment14,'rb')
- topgreenleft = MIMEImage(fp13.read())
- fp13.close()
- topgreenleft.add_header('Content-ID',"top-left-green-image>")
- topgreenleft.add_header('Content-Disposition', 'inline', filename='top-left-green-corner.gif')
- attachment15 = os.path.join(mail_template_path,'top-right-green-corner.gif')
- fp14 = open(attachment15,'rb')
- topgreenright = MIMEImage(fp14.read())
- fp14.close()
- topgreenright.add_header('Content-ID',"top-right-green-image>")
- topgreenright.add_header('Content-Disposition', 'inline', filename='top-right-green-corner.gif')
- attachment16 = os.path.join(mail_template_path,'bottom-left-green-corner.gif')
- fp15 = open(attachment16,'rb')
- bottomleftgreen = MIMEImage(fp15.read())
- fp15.close()
- bottomleftgreen.add_header('Content-ID',"bottom-left-green-image>")
- bottomleftgreen.add_header('Content-Disposition', 'inline', filename='bottom-left-green-corner.gif')
- attachment17 = os.path.join(mail_template_path,'bottom-right-green-corner.gif')
- fp16 = open(attachment17,'rb')
- bottomrightgreen = MIMEImage(fp16.read())
- fp16.close()
- bottomrightgreen.add_header('Content-ID',"bottom-right-green-image>")
- bottomrightgreen.add_header('Content-Disposition', 'inline', filename='bottom-right-green-corner.gif')
- msgRoot.attach(img)
- msgRoot.attach(topleftwhiteimg)
- msgRoot.attach(toprightwhiteimg)
- msgRoot.attach(topleftblueimg)
- msgRoot.attach(toprightblueimg)
- msgRoot.attach(reportimg)
- msgRoot.attach(bottomleftblueimg)
- msgRoot.attach(bottomrightblueimg)
- msgRoot.attach(bottomleftbrownimg)
- msgRoot.attach(bottomrightbrownimg)
- msgRoot.attach(fbimg)
- msgRoot.attach(twimg)
- msgRoot.attach(lknimg)
- msgRoot.attach(topgreenleft)
- msgRoot.attach(topgreenright)
- msgRoot.attach(bottomleftgreen)
- msgRoot.attach(bottomrightgreen)
- TOADDR = [msgRoot['To']]
- CCADDR = [msgRoot['Bcc']]
- s.sendmail(sender,TOADDR+CCADDR,msgRoot.as_string())
- s.quit()
- logger.info("Successfully send 24hour report mail to user %s"%str(user_id))
- return True
- except Exception as e:
- logger.error("Error while sending 24hour email %s"%str(e))
- return False
- def sendNoAlertMail(report_id, user_id, fbid, fbname, email, totalFeedCount, totalImageCount, totalPost, totalComment, totalShare, totalLike, config, mailFlag, uuid):
- if mailFlag == False:
- return True
- logger = logging.getLogger("repnuplogger")
- logger.info("Sending no alert email to user %s",user_id)
- host_name = config.get('smtp_settings','host')
- user_name = config.get('smtp_settings','username')
- password = config.get('smtp_settings','password')
- mail_template_path = config.get('smtp_settings','mail_template_path')
- siteurl = config.get('admin_settings','site_url')
- sender = config.get('smtp_settings','sender')
- cc_address = config.get('admin_settings','cc_email')
- #email = 'marcomtl@gmail.com'
- uuid = str(uuid)
- try:
- fo = open(os.path.join(mail_template_path,'no_alert_report.html'))
- filecontent = fo.read()
- fo.close()
- messagebody = filecontent.replace("site_url",siteurl)
- fbuser_name = fbname.encode('utf-8')
- messagebody = messagebody.replace("app_user_name",fbuser_name)
- messagebody = messagebody.replace("user_total_feed",str(totalFeedCount))
- messagebody = messagebody.replace("user_total_images",str(totalImageCount))
- messagebody = messagebody.replace("total_feed_post",str(totalPost))
- messagebody = messagebody.replace("total_comments",str(totalComment))
- messagebody = messagebody.replace("total_share",str(totalShare))
- messagebody = messagebody.replace("total_likes",str(totalLike))
- messagebody = messagebody.replace("user_uuid",uuid)
- msgRoot = MIMEMultipart('related')
- msgRoot['Subject'] = "Your social media report from RepNup"
- msgRoot['From'] = "RepNup <reports@repnup.com>"
- msgRoot['To'] = email
- msgRoot['Bcc'] = cc_address
- msgRoot.preamble = 'This is a multi-part message in MIME format.'
- s = smtplib.SMTP(host_name)
- s.set_debuglevel(0)
- s.ehlo()
- if s.has_extn('STARTTLS'):
- s.starttls()
- s.ehlo()
- s.login(user_name,password)
- html_body = MIMEText(messagebody,'html')
- msg= MIMEMultipart('alternative')
- msgRoot.attach(msg)
- msg.attach(html_body)
- attachment = os.path.join(mail_template_path,'logo.jpg')
- fp = open(attachment,'rb')
- img = MIMEImage(fp.read())
- fp.close()
- img.add_header('Content-ID',"<logo-image>")
- img.add_header('Content-Disposition', 'inline', filename='logo.jpg')
- attachment2 = os.path.join(mail_template_path,'top-left-white-corner.gif')
- fp1 = open(attachment2,'rb')
- topleftwhiteimg = MIMEImage(fp1.read())
- fp1.close()
- topleftwhiteimg.add_header('Content-ID',"<top-left-white-image>")
- topleftwhiteimg.add_header('Content-Disposition', 'inline', filename='top-left-white-corner.gif')
- attachment3 = os.path.join(mail_template_path,'top-right-white-corner.gif')
- fp2 = open(attachment3,'rb')
- toprightwhiteimg = MIMEImage(fp2.read())
- fp2.close()
- toprightwhiteimg.add_header('Content-ID',"<top-right-white-image>")
- toprightwhiteimg.add_header('Content-Disposition', 'inline', filename='top-right-white-corner.gif')
- attachment4 = os.path.join(mail_template_path,'top-left-blue-corner.gif')
- fp3 = open(attachment4,'rb')
- topleftblueimg = MIMEImage(fp3.read())
- fp3.close()
- topleftblueimg.add_header('Content-ID',"<top-left-blue-image>")
- topleftblueimg.add_header('Content-Disposition', 'inline', filename='top-left-blue-corner.gif')
- attachment5 = os.path.join(mail_template_path,'top-right-blue-corner.gif')
- fp4 = open(attachment5,'rb')
- toprightblueimg = MIMEImage(fp4.read())
- fp4.close()
- toprightblueimg.add_header('Content-ID',"<top-right-blue-image>")
- toprightblueimg.add_header('Content-Disposition', 'inline', filename='top-right-blue-corner.gif')
- attachment6 = os.path.join(mail_template_path,'report_ready.jpg')
- fp5 = open(attachment6,'rb')
- reportimg = MIMEImage(fp5.read())
- fp5.close()
- reportimg.add_header('Content-ID',"<report-ready-image>")
- reportimg.add_header('Content-Disposition', 'inline', filename='report_ready.jpg')
- attachment7 = os.path.join(mail_template_path,'bottom-left-blue-corner.gif')
- fp6 = open(attachment7,'rb')
- bottomleftblueimg = MIMEImage(fp6.read())
- fp6.close()
- bottomleftblueimg.add_header('Content-ID',"<bottom-left-blue-image>")
- bottomleftblueimg.add_header('Content-Disposition', 'inline', filename='bottom-left-blue-corner.gif')
- attachment8 = os.path.join(mail_template_path,'bottom-right-blue-corner.gif')
- fp7 = open(attachment8,'rb')
- bottomrightblueimg = MIMEImage(fp7.read())
- fp7.close()
- bottomrightblueimg.add_header('Content-ID',"<bottom-right-blue-image>")
- bottomrightblueimg.add_header('Content-Disposition', 'inline', filename='bottom-right-blue-corner.gif')
- attachment9 = os.path.join(mail_template_path,'bottom-left-brown-corner.gif')
- fp8 = open(attachment9,'rb')
- bottomleftbrownimg = MIMEImage(fp8.read())
- fp8.close()
- bottomleftbrownimg.add_header('Content-ID',"<bottom-left-brown-image>")
- bottomleftbrownimg.add_header('Content-Disposition', 'inline', filename='bottom-left-brown-corner.gif')
- attachment10 = os.path.join(mail_template_path,'bottom-right-brown-corner.gif')
- fp9 = open(attachment10,'rb')
- bottomrightbrownimg = MIMEImage(fp9.read())
- fp9.close()
- bottomrightbrownimg.add_header('Content-ID',"<bottom-right-brown-image>")
- bottomrightbrownimg.add_header('Content-Disposition', 'inline', filename='bottom-right-brown-corner.gif')
- attachment11 = os.path.join(mail_template_path,'fb.jpg')
- fp10 = open(attachment11,'rb')
- fbimg = MIMEImage(fp10.read())
- fp10.close()
- fbimg.add_header('Content-ID',"<fb-image>")
- fbimg.add_header('Content-Disposition', 'inline', filename='fb.jpg')
- attachment12 = os.path.join(mail_template_path,'tw.jpg')
- fp11 = open(attachment12,'rb')
- twimg = MIMEImage(fp11.read())
- fp11.close()
- twimg.add_header('Content-ID',"<tw-image>")
- twimg.add_header('Content-Disposition', 'inline', filename='tw.jpg')
- attachment13 = os.path.join(mail_template_path,'lnk.jpg')
- fp12 = open(attachment13,'rb')
- lknimg = MIMEImage(fp12.read())
- fp12.close()
- lknimg.add_header('Content-ID',"<link-image>")
- lknimg.add_header('Content-Disposition', 'inline', filename='lnk.jpg')
- msgRoot.attach(img)
- msgRoot.attach(topleftwhiteimg)
- msgRoot.attach(toprightwhiteimg)
- msgRoot.attach(topleftblueimg)
- msgRoot.attach(toprightblueimg)
- msgRoot.attach(reportimg)
- msgRoot.attach(bottomleftblueimg)
- msgRoot.attach(bottomrightblueimg)
- msgRoot.attach(bottomleftbrownimg)
- msgRoot.attach(bottomrightbrownimg)
- msgRoot.attach(fbimg)
- msgRoot.attach(twimg)
- msgRoot.attach(lknimg)
- TOADDR = [msgRoot['To']]
- CCADDR = [msgRoot['Bcc']]
- s.sendmail(sender,TOADDR+CCADDR,msgRoot.as_string())
- s.quit()
- logger.info("Successfully send no alert mail to user %s"%str(user_id))
- return True
- except Exception as e:
- logger.error("Error while sending email %s"%str(e))
- return False
- # Send no alert email to user
- def sendNoDetailAlertMail(report_id,user_id,fbid,fbname,email,totalFeedCount,totalImageCount,totalPost,totalComment,totalShare,totalLike,config,mailFlag,uuid):
- if mailFlag == False:
- return True
- logger = logging.getLogger("repnuplogger")
- logger.info("Sending no detail alert mail to user %s",user_id)
- host_name = config.get('smtp_settings','host')
- user_name = config.get('smtp_settings','username')
- password = config.get('smtp_settings','password')
- mail_template_path = config.get('smtp_settings','mail_template_path')
- siteurl = config.get('admin_settings','site_url')
- sender = config.get('smtp_settings','sender')
- cc_address = config.get('admin_settings','cc_email')
- #email = 'marcomtl@gmail.com'
- uuid = str(uuid)
- try:
- fo = open(os.path.join(mail_template_path,'no_alert_detail_report.html'))
- filecontent = fo.read()
- fo.close()
- messagebody = filecontent.replace("site_url",siteurl)
- fbuser_name = fbname.encode('utf-8')
- messagebody = messagebody.replace("app_user_name",fbuser_name)
- messagebody = messagebody.replace("user_total_feed",str(totalFeedCount))
- messagebody = messagebody.replace("user_total_images",str(totalImageCount))
- messagebody = messagebody.replace("total_feed_post",str(totalPost))
- messagebody = messagebody.replace("total_comments",str(totalComment))
- messagebody = messagebody.replace("total_share",str(totalShare))
- messagebody = messagebody.replace("total_likes",str(totalLike))
- messagebody = messagebody.replace("user_uuid",uuid)
- msgRoot = MIMEMultipart('related')
- msgRoot['Subject'] = "Your social media report from RepNup"
- msgRoot['From'] = "RepNup <reports@repnup.com>"
- msgRoot['To'] = email
- msgRoot['Bcc'] = cc_address
- msgRoot.preamble = 'This is a multi-part message in MIME format.'
- s = smtplib.SMTP(host_name)
- s.set_debuglevel(0)
- s.ehlo()
- if s.has_extn('STARTTLS'):
- s.starttls()
- s.ehlo()
- s.login(user_name,password)
- html_body = MIMEText(messagebody,'html')
- msg= MIMEMultipart('alternative')
- msgRoot.attach(msg)
- msg.attach(html_body)
- attachment = os.path.join(mail_template_path,'logo.jpg')
- fp = open(attachment,'rb')
- img = MIMEImage(fp.read())
- fp.close()
- img.add_header('Content-ID',"<logo-image>")
- img.add_header('Content-Disposition', 'inline', filename='logo.jpg')
- attachment2 = os.path.join(mail_template_path,'top-left-white-corner.gif')
- fp1 = open(attachment2,'rb')
- topleftwhiteimg = MIMEImage(fp1.read())
- fp1.close()
- topleftwhiteimg.add_header('Content-ID',"<top-left-white-image>")
- topleftwhiteimg.add_header('Content-Disposition', 'inline', filename='top-left-white-corner.gif')
- attachment3 = os.path.join(mail_template_path,'top-right-white-corner.gif')
- fp2 = open(attachment3,'rb')
- toprightwhiteimg = MIMEImage(fp2.read())
- fp2.close()
- toprightwhiteimg.add_header('Content-ID',"<top-right-white-image>")
- toprightwhiteimg.add_header('Content-Disposition', 'inline', filename='top-right-white-corner.gif')
- attachment4 = os.path.join(mail_template_path,'top-left-blue-corner.gif')
- fp3 = open(attachment4,'rb')
- topleftblueimg = MIMEImage(fp3.read())
- fp3.close()
- topleftblueimg.add_header('Content-ID',"<top-left-blue-image>")
- topleftblueimg.add_header('Content-Disposition', 'inline', filename='top-left-blue-corner.gif')
- attachment5 = os.path.join(mail_template_path,'top-right-blue-corner.gif')
- fp4 = open(attachment5,'rb')
- toprightblueimg = MIMEImage(fp4.read())
- fp4.close()
- toprightblueimg.add_header('Content-ID',"<top-right-blue-image>")
- toprightblueimg.add_header('Content-Disposition', 'inline', filename='top-right-blue-corner.gif')
- attachment6 = os.path.join(mail_template_path,'report_ready.jpg')
- fp5 = open(attachment6,'rb')
- reportimg = MIMEImage(fp5.read())
- fp5.close()
- reportimg.add_header('Content-ID',"<report-ready-image>")
- reportimg.add_header('Content-Disposition', 'inline', filename='report_ready.jpg')
- attachment7 = os.path.join(mail_template_path,'bottom-left-blue-corner.gif')
- fp6 = open(attachment7,'rb')
- bottomleftblueimg = MIMEImage(fp6.read())
- fp6.close()
- bottomleftblueimg.add_header('Content-ID',"<bottom-left-blue-image>")
- bottomleftblueimg.add_header('Content-Disposition', 'inline', filename='bottom-left-blue-corner.gif')
- attachment8 = os.path.join(mail_template_path,'bottom-right-blue-corner.gif')
- fp7 = open(attachment8,'rb')
- bottomrightblueimg = MIMEImage(fp7.read())
- fp7.close()
- bottomrightblueimg.add_header('Content-ID',"<bottom-right-blue-image>")
- bottomrightblueimg.add_header('Content-Disposition', 'inline', filename='bottom-right-blue-corner.gif')
- attachment9 = os.path.join(mail_template_path,'bottom-left-brown-corner.gif')
- fp8 = open(attachment9,'rb')
- bottomleftbrownimg = MIMEImage(fp8.read())
- fp8.close()
- bottomleftbrownimg.add_header('Content-ID',"<bottom-left-brown-image>")
- bottomleftbrownimg.add_header('Content-Disposition', 'inline', filename='bottom-left-brown-corner.gif')
- attachment10 = os.path.join(mail_template_path,'bottom-right-brown-corner.gif')
- fp9 = open(attachment10,'rb')
- bottomrightbrownimg = MIMEImage(fp9.read())
- fp9.close()
- bottomrightbrownimg.add_header('Content-ID',"<bottom-right-brown-image>")
- bottomrightbrownimg.add_header('Content-Disposition', 'inline', filename='bottom-right-brown-corner.gif')
- attachment11 = os.path.join(mail_template_path,'fb.jpg')
- fp10 = open(attachment11,'rb')
- fbimg = MIMEImage(fp10.read())
- fp10.close()
- fbimg.add_header('Content-ID',"<fb-image>")
- fbimg.add_header('Content-Disposition', 'inline', filename='fb.jpg')
- attachment12 = os.path.join(mail_template_path,'tw.jpg')
- fp11 = open(attachment12,'rb')
- twimg = MIMEImage(fp11.read())
- fp11.close()
- twimg.add_header('Content-ID',"<tw-image>")
- twimg.add_header('Content-Disposition', 'inline', filename='tw.jpg')
- attachment13 = os.path.join(mail_template_path,'lnk.jpg')
- fp12 = open(attachment13,'rb')
- lknimg = MIMEImage(fp12.read())
- fp12.close()
- lknimg.add_header('Content-ID',"<link-image>")
- lknimg.add_header('Content-Disposition', 'inline', filename='lnk.jpg')
- msgRoot.attach(img)
- msgRoot.attach(topleftwhiteimg)
- msgRoot.attach(toprightwhiteimg)
- msgRoot.attach(topleftblueimg)
- msgRoot.attach(toprightblueimg)
- msgRoot.attach(reportimg)
- msgRoot.attach(bottomleftblueimg)
- msgRoot.attach(bottomrightblueimg)
- msgRoot.attach(bottomleftbrownimg)
- msgRoot.attach(bottomrightbrownimg)
- msgRoot.attach(fbimg)
- msgRoot.attach(twimg)
- msgRoot.attach(lknimg)
- TOADDR = [msgRoot['To']]
- CCADDR = [msgRoot['Bcc']]
- s.sendmail(sender,TOADDR+CCADDR,msgRoot.as_string())
- s.quit()
- logger.info("Successfully send no detailed alert mail to user %s"%str(user_id))
- return True
- except Exception as e:
- logger.error("Error while sending email %s"%str(e))
- return False
- # Send no alert email to user
- def sendNoTwAlertMail(report_id,user_id,twid,twname,email,totalFeed,totalTweetCount,totalImageCount,config,mailFlag,uuid):
- if mailFlag == False:
- return True
- logger = logging.getLogger("repnuplogger")
- logger.info("Sending no alert email to user %s",user_id)
- host_name = config.get('smtp_settings','host')
- user_name = config.get('smtp_settings','username')
- password = config.get('smtp_settings','password')
- mail_template_path = config.get('smtp_settings','mail_template_path')
- siteurl = config.get('admin_settings','site_url')
- sender = config.get('smtp_settings','sender')
- cc_address = config.get('admin_settings','cc_email')
- #email = 'marcomtl@gmail.com'
- uuid = str(uuid)
- try:
- fo = open(os.path.join(mail_template_path,'no_alert_tw_report.html'))
- filecontent = fo.read()
- fo.close()
- messagebody = filecontent.replace("site_url",siteurl)
- twname = twname.encode('utf-8')
- messagebody = messagebody.replace("app_user_name",twname)
- messagebody = messagebody.replace("user_total_feed ",str(totalTweetCount))
- messagebody = messagebody.replace("total_tweet",str(totalTweetCount))
- messagebody = messagebody.replace("total_photos",str(totalImageCount))
- messagebody = messagebody.replace("user_uuid",uuid)
- msgRoot = MIMEMultipart('related')
- msgRoot['Subject'] = "Your social media report for Twitter from RepNup"
- msgRoot['From'] = "RepNup <reports@repnup.com>"
- msgRoot['To'] = email
- msgRoot['Bcc'] = cc_address
- msgRoot.preamble = 'This is a multi-part message in MIME format.'
- s = smtplib.SMTP(host_name)
- s.set_debuglevel(0)
- s.ehlo()
- if s.has_extn('STARTTLS'):
- s.starttls()
- s.ehlo()
- s.login(user_name,password)
- html_body = MIMEText(messagebody,'html')
- msg= MIMEMultipart('alternative')
- msgRoot.attach(msg)
- msg.attach(html_body)
- attachment = os.path.join(mail_template_path,'logo.jpg')
- fp = open(attachment,'rb')
- img = MIMEImage(fp.read())
- fp.close()
- img.add_header('Content-ID',"<logo-image>")
- img.add_header('Content-Disposition', 'inline', filename='logo.jpg')
- attachment2 = os.path.join(mail_template_path,'top-left-white-corner.gif')
- fp1 = open(attachment2,'rb')
- topleftwhiteimg = MIMEImage(fp1.read())
- fp1.close()
- topleftwhiteimg.add_header('Content-ID',"<top-left-white-image>")
- topleftwhiteimg.add_header('Content-Disposition', 'inline', filename='top-left-white-corner.gif')
- attachment3 = os.path.join(mail_template_path,'top-right-white-corner.gif')
- fp2 = open(attachment3,'rb')
- toprightwhiteimg = MIMEImage(fp2.read())
- fp2.close()
- toprightwhiteimg.add_header('Content-ID',"<top-right-white-image>")
- toprightwhiteimg.add_header('Content-Disposition', 'inline', filename='top-right-white-corner.gif')
- attachment4 = os.path.join(mail_template_path,'top-left-blue-corner.gif')
- fp3 = open(attachment4,'rb')
- topleftblueimg = MIMEImage(fp3.read())
- fp3.close()
- topleftblueimg.add_header('Content-ID',"<top-left-blue-image>")
- topleftblueimg.add_header('Content-Disposition', 'inline', filename='top-left-blue-corner.gif')
- attachment5 = os.path.join(mail_template_path,'top-right-blue-corner.gif')
- fp4 = open(attachment5,'rb')
- toprightblueimg = MIMEImage(fp4.read())
- fp4.close()
- toprightblueimg.add_header('Content-ID',"<top-right-blue-image>")
- toprightblueimg.add_header('Content-Disposition', 'inline', filename='top-right-blue-corner.gif')
- attachment6 = os.path.join(mail_template_path,'report_ready.jpg')
- fp5 = open(attachment6,'rb')
- reportimg = MIMEImage(fp5.read())
- fp5.close()
- reportimg.add_header('Content-ID',"<report-ready-image>")
- reportimg.add_header('Content-Disposition', 'inline', filename='report_ready.jpg')
- attachment7 = os.path.join(mail_template_path,'bottom-left-blue-corner.gif')
- fp6 = open(attachment7,'rb')
- bottomleftblueimg = MIMEImage(fp6.read())
- fp6.close()
- bottomleftblueimg.add_header('Content-ID',"<bottom-left-blue-image>")
- bottomleftblueimg.add_header('Content-Disposition', 'inline', filename='bottom-left-blue-corner.gif')
- attachment8 = os.path.join(mail_template_path,'bottom-right-blue-corner.gif')
- fp7 = open(attachment8,'rb')
- bottomrightblueimg = MIMEImage(fp7.read())
- fp7.close()
- bottomrightblueimg.add_header('Content-ID',"<bottom-right-blue-image>")
- bottomrightblueimg.add_header('Content-Disposition', 'inline', filename='bottom-right-blue-corner.gif')
- attachment9 = os.path.join(mail_template_path,'bottom-left-brown-corner.gif')
- fp8 = open(attachment9,'rb')
- bottomleftbrownimg = MIMEImage(fp8.read())
- fp8.close()
- bottomleftbrownimg.add_header('Content-ID',"<bottom-left-brown-image>")
- bottomleftbrownimg.add_header('Content-Disposition', 'inline', filename='bottom-left-brown-corner.gif')
- attachment10 = os.path.join(mail_template_path,'bottom-right-brown-corner.gif')
- fp9 = open(attachment10,'rb')
- bottomrightbrownimg = MIMEImage(fp9.read())
- fp9.close()
- bottomrightbrownimg.add_header('Content-ID',"<bottom-right-brown-image>")
- bottomrightbrownimg.add_header('Content-Disposition', 'inline', filename='bottom-right-brown-corner.gif')
- attachment11 = os.path.join(mail_template_path,'fb.jpg')
- fp10 = open(attachment11,'rb')
- fbimg = MIMEImage(fp10.read())
- fp10.close()
- fbimg.add_header('Content-ID',"<fb-image>")
- fbimg.add_header('Content-Disposition', 'inline', filename='fb.jpg')
- attachment12 = os.path.join(mail_template_path,'tw.jpg')
- fp11 = open(attachment12,'rb')
- twimg = MIMEImage(fp11.read())
- fp11.close()
- twimg.add_header('Content-ID',"<tw-image>")
- twimg.add_header('Content-Disposition', 'inline', filename='tw.jpg')
- attachment13 = os.path.join(mail_template_path,'lnk.jpg')
- fp12 = open(attachment13,'rb')
- lknimg = MIMEImage(fp12.read())
- fp12.close()
- lknimg.add_header('Content-ID',"<link-image>")
- lknimg.add_header('Content-Disposition', 'inline', filename='lnk.jpg')
- msgRoot.attach(img)
- msgRoot.attach(topleftwhiteimg)
- msgRoot.attach(toprightwhiteimg)
- msgRoot.attach(topleftblueimg)
- msgRoot.attach(toprightblueimg)
- msgRoot.attach(reportimg)
- msgRoot.attach(bottomleftblueimg)
- msgRoot.attach(bottomrightblueimg)
- msgRoot.attach(bottomleftbrownimg)
- msgRoot.attach(bottomrightbrownimg)
- msgRoot.attach(fbimg)
- msgRoot.attach(twimg)
- msgRoot.attach(lknimg)
- TOADDR = [msgRoot['To']]
- CCADDR = [msgRoot['Bcc']]
- msgRoot.attach(img)
- msgRoot.attach(fbimg)
- msgRoot.attach(twimg)
- TOADDR = [msgRoot['To']]
- CCADDR = [msgRoot['Bcc']]
- s.sendmail(sender,TOADDR+CCADDR,msgRoot.as_string())
- s.quit()
- logger.info("Successfully send no alert mail to user %s"%str(user_id))
- return True
- except Exception as e:
- logger.error("Error while sending email %s"%str(e))
- return False
- # Send no alert email to user
- #Send initial report email to user
- def sendInitialTwMail(report_id,user_id,twid,twname,email,totalFeedCount,totalAlert,config,mailFlag,uuid):
- if mailFlag == False:
- return True
- logger = logging.getLogger("repnuplogger")
- logger.info("Sending initial summary mail to user %s",user_id)
- host_name = config.get('smtp_settings','host')
- user_name = config.get('smtp_settings','username')
- password = config.get('smtp_settings','password')
- mail_template_path = config.get('smtp_settings','mail_template_path')
- siteurl = config.get('admin_settings','site_url')
- sender = config.get('smtp_settings','sender')
- cc_address = config.get('admin_settings','cc_email')
- #email = 'marcomtl@gmail.com';
- uuid = str(uuid)
- try:
- fo = open(os.path.join(mail_template_path,'initial_tw_report.html'))
- filecontent = fo.read()
- fo.close()
- messagebody = filecontent.replace("site_url",siteurl)
- twname = twname.encode('utf-8')
- messagebody = messagebody.replace("app_user_name",twname)
- messagebody = messagebody.replace("user_total_feed ",str(totalFeedCount))
- messagebody = messagebody.replace("user_total_alerts ",str(totalAlert))
- messagebody = messagebody.replace("user_uuid",uuid)
- msgRoot = MIMEMultipart('related')
- msgRoot['Subject'] = "Your social media initial report for Twitter from RepNup"
- msgRoot['From'] = "RepNup <reports@repnup.com>"
- msgRoot['To'] = email
- msgRoot['Bcc'] = cc_address
- msgRoot.preamble = 'This is a multi-part message in MIME format.'
- s = smtplib.SMTP(host_name)
- s.set_debuglevel(0)
- s.ehlo()
- if s.has_extn('STARTTLS'):
- s.starttls()
- s.ehlo()
- s.login(user_name,password)
- html_body = MIMEText(messagebody,'html')
- msg= MIMEMultipart('alternative')
- msgRoot.attach(msg)
- msg.attach(html_body)
- attachment = os.path.join(mail_template_path,'logo.jpg')
- fp = open(attachment,'rb')
- img = MIMEImage(fp.read())
- fp.close()
- img.add_header('Content-ID',"<logo-image>")
- img.add_header('Content-Disposition', 'inline', filename='logo.jpg')
- attachment2 = os.path.join(mail_template_path,'top-left-white-corner.gif')
- fp1 = open(attachment2,'rb')
- topleftwhiteimg = MIMEImage(fp1.read())
- fp1.close()
- topleftwhiteimg.add_header('Content-ID',"<top-left-white-image>")
- topleftwhiteimg.add_header('Content-Disposition', 'inline', filename='top-left-white-corner.gif')
- attachment3 = os.path.join(mail_template_path,'top-right-white-corner.gif')
- fp2 = open(attachment3,'rb')
- toprightwhiteimg = MIMEImage(fp2.read())
- fp2.close()
- toprightwhiteimg.add_header('Content-ID',"<top-right-white-image>")
- toprightwhiteimg.add_header('Content-Disposition', 'inline', filename='top-right-white-corner.gif')
- attachment4 = os.path.join(mail_template_path,'top-left-blue-corner.gif')
- fp3 = open(attachment4,'rb')
- topleftblueimg = MIMEImage(fp3.read())
- fp3.close()
- topleftblueimg.add_header('Content-ID',"<top-left-blue-image>")
- topleftblueimg.add_header('Content-Disposition', 'inline', filename='top-left-blue-corner.gif')
- attachment5 = os.path.join(mail_template_path,'top-right-blue-corner.gif')
- fp4 = open(attachment5,'rb')
- toprightblueimg = MIMEImage(fp4.read())
- fp4.close()
- toprightblueimg.add_header('Content-ID',"<top-right-blue-image>")
- toprightblueimg.add_header('Content-Disposition', 'inline', filename='top-right-blue-corner.gif')
- attachment6 = os.path.join(mail_template_path,'report_in_process.jpg')
- fp5 = open(attachment6,'rb')
- reportimg = MIMEImage(fp5.read())
- fp5.close()
- reportimg.add_header('Content-ID',"<report-image>")
- reportimg.add_header('Content-Disposition', 'inline', filename='report_in_process.jpg')
- attachment7 = os.path.join(mail_template_path,'bottom-left-blue-corner.gif')
- fp6 = open(attachment7,'rb')
- bottomleftblueimg = MIMEImage(fp6.read())
- fp6.close()
- bottomleftblueimg.add_header('Content-ID',"<bottom-left-blue-image>")
- bottomleftblueimg.add_header('Content-Disposition', 'inline', filename='bottom-left-blue-corner.gif')
- attachment8 = os.path.join(mail_template_path,'bottom-right-blue-corner.gif')
- fp7 = open(attachment8,'rb')
- bottomrightblueimg = MIMEImage(fp7.read())
- fp7.close()
- bottomrightblueimg.add_header('Content-ID',"<bottom-right-blue-image>")
- bottomrightblueimg.add_header('Content-Disposition', 'inline', filename='bottom-right-blue-corner.gif')
- attachment9 = os.path.join(mail_template_path,'bottom-left-brown-corner.gif')
- fp8 = open(attachment9,'rb')
- bottomleftbrownimg = MIMEImage(fp8.read())
- fp8.close()
- bottomleftbrownimg.add_header('Content-ID',"<bottom-left-brown-image>")
- bottomleftbrownimg.add_header('Content-Disposition', 'inline', filename='bottom-left-brown-corner.gif')
- attachment10 = os.path.join(mail_template_path,'bottom-right-brown-corner.gif')
- fp9 = open(attachment10,'rb')
- bottomrightbrownimg = MIMEImage(fp9.read())
- fp9.close()
- bottomrightbrownimg.add_header('Content-ID',"<bottom-right-brown-image>")
- bottomrightbrownimg.add_header('Content-Disposition', 'inline', filename='bottom-right-brown-corner.gif')
- attachment11 = os.path.join(mail_template_path,'fb.jpg')
- fp10 = open(attachment11,'rb')
- fbimg = MIMEImage(fp10.read())
- fp10.close()
- fbimg.add_header('Content-ID',"<fb-image>")
- fbimg.add_header('Content-Disposition', 'inline', filename='fb.jpg')
- attachment12 = os.path.join(mail_template_path,'tw.jpg')
- fp11 = open(attachment12,'rb')
- twimg = MIMEImage(fp11.read())
- fp11.close()
- twimg.add_header('Content-ID',"<tw-image>")
- twimg.add_header('Content-Disposition', 'inline', filename='tw.jpg')
- attachment13 = os.path.join(mail_template_path,'lnk.jpg')
- fp12 = open(attachment13,'rb')
- lknimg = MIMEImage(fp12.read())
- fp12.close()
- lknimg.add_header('Content-ID',"<link-image>")
- lknimg.add_header('Content-Disposition', 'inline', filename='lnk.jpg')
- msgRoot.attach(img)
- msgRoot.attach(topleftwhiteimg)
- msgRoot.attach(toprightwhiteimg)
- msgRoot.attach(topleftblueimg)
- msgRoot.attach(toprightblueimg)
- msgRoot.attach(reportimg)
- msgRoot.attach(bottomleftblueimg)
- msgRoot.attach(bottomrightblueimg)
- msgRoot.attach(bottomleftbrownimg)
- msgRoot.attach(bottomrightbrownimg)
- msgRoot.attach(fbimg)
- msgRoot.attach(twimg)
- msgRoot.attach(lknimg)
- TOADDR = [msgRoot['To']]
- CCADDR = [msgRoot['Bcc']]
- s.sendmail(sender,TOADDR+CCADDR,msgRoot.as_string())
- s.quit()
- logger.info("Successfully send summary mail to user %s"%str(user_id))
- return True
- except Exception as e:
- logger.error("Error while sending email %s"%str(e))
- return False
- # Send summary email to user
- def sendTwSummaryMail(report_id,user_id,twid,twname,email,totalFeedCount,totalAlert,config,mailFlag,uuid):
- if mailFlag == False:
- return True
- logger = logging.getLogger("repnuplogger")
- logger.info("Sending summary mail to user %s with report id %s"%(user_id,str(report_id)))
- host_name = config.get('smtp_settings','host')
- user_name = config.get('smtp_settings','username')
- password = config.get('smtp_settings','password')
- mail_template_path = config.get('smtp_settings','mail_template_path')
- siteurl = config.get('admin_settings','site_url')
- sender = config.get('smtp_settings','sender')
- cc_address = config.get('admin_settings','cc_email')
- #email = 'margomtl@gmail.com'
- uuid = str(uuid)
- try:
- fo = open(os.path.join(mail_template_path,'summary_tw_report.html'))
- filecontent = fo.read()
- fo.close()
- messagebody = filecontent.replace("site_url",siteurl)
- twname = twname.encode('utf-8')
- messagebody = messagebody.replace("app_user_name",twname)
- messagebody = messagebody.replace("user_total_feed",str(totalFeedCount))
- messagebody = messagebody.replace("user_total_alerts",str(totalAlert))
- messagebody = messagebody.replace("user_uuid",uuid)
- msgRoot = MIMEMultipart('related')
- msgRoot['Subject'] = "Your social media summary report for Twitter from RepNup"
- msgRoot['From'] = "RepNup <reports@repnup.com>"
- msgRoot['To'] = email
- msgRoot['Bcc'] = cc_address
- msgRoot.preamble = 'This is a multi-part message in MIME format.'
- s = smtplib.SMTP(host_name)
- s.set_debuglevel(0)
- s.ehlo()
- if s.has_extn('STARTTLS'):
- s.starttls()
- s.ehlo()
- s.login(user_name,password)
- html_body = MIMEText(messagebody,'html')
- msg= MIMEMultipart('alternative')
- msgRoot.attach(msg)
- msg.attach(html_body)
- attachment = os.path.join(mail_template_path,'logo.jpg')
- fp = open(attachment,'rb')
- img = MIMEImage(fp.read())
- fp.close()
- img.add_header('Content-ID',"<logo-image>")
- img.add_header('Content-Disposition', 'inline', filename='logo.jpg')
- attachment2 = os.path.join(mail_template_path,'top-left-white-corner.gif')
- fp1 = open(attachment2,'rb')
- topleftwhiteimg = MIMEImage(fp1.read())
- fp1.close()
- topleftwhiteimg.add_header('Content-ID',"<top-left-white-image>")
- topleftwhiteimg.add_header('Content-Disposition', 'inline', filename='top-left-white-corner.gif')
- attachment3 = os.path.join(mail_template_path,'top-right-white-corner.gif')
- fp2 = open(attachment3,'rb')
- toprightwhiteimg = MIMEImage(fp2.read())
- fp2.close()
- toprightwhiteimg.add_header('Content-ID',"<top-right-white-image>")
- toprightwhiteimg.add_header('Content-Disposition', 'inline', filename='top-right-white-corner.gif')
- attachment4 = os.path.join(mail_template_path,'top-left-blue-corner.gif')
- fp3 = open(attachment4,'rb')
- topleftblueimg = MIMEImage(fp3.read())
- fp3.close()
- topleftblueimg.add_header('Content-ID',"<top-left-blue-image>")
- topleftblueimg.add_header('Content-Disposition', 'inline', filename='top-left-blue-corner.gif')
- attachment5 = os.path.join(mail_template_path,'top-right-blue-corner.gif')
- fp4 = open(attachment5,'rb')
- toprightblueimg = MIMEImage(fp4.read())
- fp4.close()
- toprightblueimg.add_header('Content-ID',"<top-right-blue-image>")
- toprightblueimg.add_header('Content-Disposition', 'inline', filename='top-right-blue-corner.gif')
- attachment6 = os.path.join(mail_template_path,'report_ready.jpg')
- fp5 = open(attachment6,'rb')
- reportimg = MIMEImage(fp5.read())
- fp5.close()
- reportimg.add_header('Content-ID',"<report-ready-image>")
- reportimg.add_header('Content-Disposition', 'inline', filename='report_ready.jpg')
- attachment7 = os.path.join(mail_template_path,'bottom-left-blue-corner.gif')
- fp6 = open(attachment7,'rb')
- bottomleftblueimg = MIMEImage(fp6.read())
- fp6.close()
- bottomleftblueimg.add_header('Content-ID',"<bottom-left-blue-image>")
- bottomleftblueimg.add_header('Content-Disposition', 'inline', filename='bottom-left-blue-corner.gif')
- attachment8 = os.path.join(mail_template_path,'bottom-right-blue-corner.gif')
- fp7 = open(attachment8,'rb')
- bottomrightblueimg = MIMEImage(fp7.read())
- fp7.close()
- bottomrightblueimg.add_header('Content-ID',"<bottom-right-blue-image>")
- bottomrightblueimg.add_header('Content-Disposition', 'inline', filename='bottom-right-blue-corner.gif')
- attachment9 = os.path.join(mail_template_path,'bottom-left-brown-corner.gif')
- fp8 = open(attachment9,'rb')
- bottomleftbrownimg = MIMEImage(fp8.read())
- fp8.close()
- bottomleftbrownimg.add_header('Content-ID',"<bottom-left-brown-image>")
- bottomleftbrownimg.add_header('Content-Disposition', 'inline', filename='bottom-left-brown-corner.gif')
- attachment10 = os.path.join(mail_template_path,'bottom-right-brown-corner.gif')
- fp9 = open(attachment10,'rb')
- bottomrightbrownimg = MIMEImage(fp9.read())
- fp9.close()
- bottomrightbrownimg.add_header('Content-ID',"<bottom-right-brown-image>")
- bottomrightbrownimg.add_header('Content-Disposition', 'inline', filename='bottom-right-brown-corner.gif')
- attachment11 = os.path.join(mail_template_path,'fb.jpg')
- fp10 = open(attachment11,'rb')
- fbimg = MIMEImage(fp10.read())
- fp10.close()
- fbimg.add_header('Content-ID',"<fb-image>")
- fbimg.add_header('Content-Disposition', 'inline', filename='fb.jpg')
- attachment12 = os.path.join(mail_template_path,'tw.jpg')
- fp11 = open(attachment12,'rb')
- twimg = MIMEImage(fp11.read())
- fp11.close()
- twimg.add_header('Content-ID',"<tw-image>")
- twimg.add_header('Content-Disposition', 'inline', filename='tw.jpg')
- attachment13 = os.path.join(mail_template_path,'lnk.jpg')
- fp12 = open(attachment13,'rb')
- lknimg = MIMEImage(fp12.read())
- fp12.close()
- lknimg.add_header('Content-ID',"<link-image>")
- lknimg.add_header('Content-Disposition', 'inline', filename='lnk.jpg')
- msgRoot.attach(img)
- msgRoot.attach(topleftwhiteimg)
- msgRoot.attach(toprightwhiteimg)
- msgRoot.attach(topleftblueimg)
- msgRoot.attach(toprightblueimg)
- msgRoot.attach(reportimg)
- msgRoot.attach(bottomleftblueimg)
- msgRoot.attach(bottomrightblueimg)
- msgRoot.attach(bottomleftbrownimg)
- msgRoot.attach(bottomrightbrownimg)
- msgRoot.attach(fbimg)
- msgRoot.attach(twimg)
- msgRoot.attach(lknimg)
- TOADDR = [msgRoot['To']]
- CCADDR = [msgRoot['Bcc']]
- s.sendmail(sender,TOADDR+CCADDR,msgRoot.as_string())
- s.quit()
- logger.info("Successfully send summary mail to user %s"%str(user_id))
- return True
- except Exception as e:
- logger.error("Error while sending email %s"%str(e))
- return False
- # process to send email to admins that user is ready to review
- def tw_notify_admin(type,user_id,db_conn,g_admin_emails,config):
- logger = logging.getLogger("repnuplogger")
- twuser = db_conn.selectOne('tbl_twitter_users',"user_id='"+str(user_id)+"'",'twitterId','screenName','text_status','media_status')
- logger.info("Sending mail to admin to review user for twitter %s"%str(twuser[0]))
- host_name = config.get('smtp_settings','host')
- user_name = config.get('smtp_settings','username')
- password = config.get('smtp_settings','password')
- mail_template_path = config.get('smtp_settings','mail_template_path')
- siteurl = config.get('admin_settings','site_url')
- sender = config.get('smtp_settings','sender')
- cc_address = config.get('admin_settings','cc_email')
- if twuser:
- if str(twuser[2]) =="3":
- try:
- fo = open(os.path.join(mail_template_path,'admin_report_ready.html'))
- filecontent = fo.read()
- fo.close()
- messagebody = filecontent.replace("site_url",siteurl)
- name = twuser[1].encode('utf-8')
- messagebody = messagebody.replace("fb_user_id",str(user_id))
- messagebody = messagebody.replace("fb_user_name",name)
- msgRoot = MIMEMultipart('related')
- if type ==1:
- msgRoot['Subject'] = "Please review text for " + name
- else :
- msgRoot['Subject'] = "Please review images for " + name
- msgRoot['From'] = "RepNup <reports@repnup.com>"
- msgRoot['To'] = g_admin_emails
- msgRoot.preamble = 'This is a multi-part message in MIME format.'
- s = smtplib.SMTP(host_name)
- s.set_debuglevel(0)
- s.ehlo()
- if s.has_extn('STARTTLS'):
- s.starttls()
- s.ehlo()
- s.login(user_name,password)
- html_body = MIMEText(messagebody,'html')
- msg= MIMEMultipart('alternative')
- msgRoot.attach(msg)
- msg.attach(html_body)
- attachment = os.path.join(mail_template_path,'rep.png')
- fp = open(attachment,'rb')
- img = MIMEImage(fp.read())
- fp.close()
- img.add_header('Content-ID',"<header-image>")
- img.add_header('Content-Disposition', 'inline', filename='rep.png')
- attachment2 = os.path.join(mail_template_path,'fb.png')
- fp1 = open(attachment2,'rb')
- fbimg = MIMEImage(fp1.read())
- fp1.close()
- fbimg.add_header('Content-ID',"<fb-icon-image>")
- fbimg.add_header('Content-Disposition', 'inline', filename='fb.png')
- attachment3 = os.path.join(mail_template_path,'tw.png')
- fp2 = open(attachment3,'rb')
- twimg = MIMEImage(fp2.read())
- fp2.close()
- twimg.add_header('Content-ID',"<tw-icon-image>")
- twimg.add_header('Content-Disposition', 'inline', filename='tw.png')
- msgRoot.attach(img)
- msgRoot.attach(fbimg)
- msgRoot.attach(twimg)
- TOADDR = [msgRoot['To']]
- s.sendmail(sender,TOADDR,msgRoot.as_string())
- s.quit()
- rectime = time.strftime('%Y-%m-%d %H:%M:%S')
- if type ==1:
- db_conn.updateRec('tbl_users',"id='"+str(user_id)+"'",mail_status="admin_review_mail",twitterStatus=4,modified=rectime)
- else:
- db_conn.updateRec('tbl_users',"id='"+str(user_id)+"'",mail_status="admin_review_mail",twitterStatus=8,modified=rectime)
- logger.info("Successfully send mail to admin to review user %s"%str(twuser[0]))
- return True
- except Exception as e:
- logger.error("Error while sending email to admin %s"%str(e))
- return False
- else:
- return False
- def sendNoDetailTwAlertMail(report_id,user_id,twid,twname,email,totalTweetCount,totalTweetMediaCount,config,mailFlag,uuid):
- if mailFlag == False:
- return True
- logger = logging.getLogger("repnuplogger")
- logger.info("Sending no detail alert mail to user %s",user_id)
- host_name = config.get('smtp_settings','host')
- user_name = config.get('smtp_settings','username')
- password = config.get('smtp_settings','password')
- mail_template_path = config.get('smtp_settings','mail_template_path')
- siteurl = config.get('admin_settings','site_url')
- sender = config.get('smtp_settings','sender')
- cc_address = config.get('admin_settings','cc_email')
- uuid = str(uuid)
- #email = 'marcomtl@gmail.com'
- try:
- fo = open(os.path.join(mail_template_path,'no_alert_detail_tw_report.html'))
- filecontent = fo.read()
- fo.close()
- messagebody = filecontent.replace("site_url",siteurl)
- twname = twname.encode('utf-8')
- messagebody = messagebody.replace("app_user_name",twname)
- messagebody = messagebody.replace("total_tweet ",str(totalTweetCount))
- messagebody = messagebody.replace("total_photos ",str(totalTweetMediaCount))
- messagebody = messagebody.replace("user_uuid",uuid)
- msgRoot = MIMEMultipart('related')
- msgRoot['Subject'] = "Your social media report for Twitter from RepNup"
- msgRoot['From'] = "RepNup <reports@repnup.com>"
- msgRoot['To'] = email
- msgRoot['Bcc'] = cc_address
- msgRoot.preamble = 'This is a multi-part message in MIME format.'
- s = smtplib.SMTP(host_name)
- s.set_debuglevel(0)
- s.ehlo()
- if s.has_extn('STARTTLS'):
- s.starttls()
- s.ehlo()
- s.login(user_name,password)
- html_body = MIMEText(messagebody,'html')
- msg= MIMEMultipart('alternative')
- msgRoot.attach(msg)
- msg.attach(html_body)
- attachment = os.path.join(mail_template_path,'logo.jpg')
- fp = open(attachment,'rb')
- img = MIMEImage(fp.read())
- fp.close()
- img.add_header('Content-ID',"<logo-image>")
- img.add_header('Content-Disposition', 'inline', filename='logo.jpg')
- attachment2 = os.path.join(mail_template_path,'top-left-white-corner.gif')
- fp1 = open(attachment2,'rb')
- topleftwhiteimg = MIMEImage(fp1.read())
- fp1.close()
- topleftwhiteimg.add_header('Content-ID',"<top-left-white-image>")
- topleftwhiteimg.add_header('Content-Disposition', 'inline', filename='top-left-white-corner.gif')
- attachment3 = os.path.join(mail_template_path,'top-right-white-corner.gif')
- fp2 = open(attachment3,'rb')
- toprightwhiteimg = MIMEImage(fp2.read())
- fp2.close()
- toprightwhiteimg.add_header('Content-ID',"<top-right-white-image>")
- toprightwhiteimg.add_header('Content-Disposition', 'inline', filename='top-right-white-corner.gif')
- attachment4 = os.path.join(mail_template_path,'top-left-blue-corner.gif')
- fp3 = open(attachment4,'rb')
- topleftblueimg = MIMEImage(fp3.read())
- fp3.close()
- topleftblueimg.add_header('Content-ID',"<top-left-blue-image>")
- topleftblueimg.add_header('Content-Disposition', 'inline', filename='top-left-blue-corner.gif')
- attachment5 = os.path.join(mail_template_path,'top-right-blue-corner.gif')
- fp4 = open(attachment5,'rb')
- toprightblueimg = MIMEImage(fp4.read())
- fp4.close()
- toprightblueimg.add_header('Content-ID',"<top-right-blue-image>")
- toprightblueimg.add_header('Content-Disposition', 'inline', filename='top-right-blue-corner.gif')
- attachment6 = os.path.join(mail_template_path,'report_ready.jpg')
- fp5 = open(attachment6,'rb')
- reportimg = MIMEImage(fp5.read())
- fp5.close()
- reportimg.add_header('Content-ID',"<report-ready-image>")
- reportimg.add_header('Content-Disposition', 'inline', filename='report_ready.jpg')
- attachment7 = os.path.join(mail_template_path,'bottom-left-blue-corner.gif')
- fp6 = open(attachment7,'rb')
- bottomleftblueimg = MIMEImage(fp6.read())
- fp6.close()
- bottomleftblueimg.add_header('Content-ID',"<bottom-left-blue-image>")
- bottomleftblueimg.add_header('Content-Disposition', 'inline', filename='bottom-left-blue-corner.gif')
- attachment8 = os.path.join(mail_template_path,'bottom-right-blue-corner.gif')
- fp7 = open(attachment8,'rb')
- bottomrightblueimg = MIMEImage(fp7.read())
- fp7.close()
- bottomrightblueimg.add_header('Content-ID',"<bottom-right-blue-image>")
- bottomrightblueimg.add_header('Content-Disposition', 'inline', filename='bottom-right-blue-corner.gif')
- attachment9 = os.path.join(mail_template_path,'bottom-left-brown-corner.gif')
- fp8 = open(attachment9,'rb')
- bottomleftbrownimg = MIMEImage(fp8.read())
- fp8.close()
- bottomleftbrownimg.add_header('Content-ID',"<bottom-left-brown-image>")
- bottomleftbrownimg.add_header('Content-Disposition', 'inline', filename='bottom-left-brown-corner.gif')
- attachment10 = os.path.join(mail_template_path,'bottom-right-brown-corner.gif')
- fp9 = open(attachment10,'rb')
- bottomrightbrownimg = MIMEImage(fp9.read())
- fp9.close()
- bottomrightbrownimg.add_header('Content-ID',"<bottom-right-brown-image>")
- bottomrightbrownimg.add_header('Content-Disposition', 'inline', filename='bottom-right-brown-corner.gif')
- attachment11 = os.path.join(mail_template_path,'fb.jpg')
- fp10 = open(attachment11,'rb')
- fbimg = MIMEImage(fp10.read())
- fp10.close()
- fbimg.add_header('Content-ID',"<fb-image>")
- fbimg.add_header('Content-Disposition', 'inline', filename='fb.jpg')
- attachment12 = os.path.join(mail_template_path,'tw.jpg')
- fp11 = open(attachment12,'rb')
- twimg = MIMEImage(fp11.read())
- fp11.close()
- twimg.add_header('Content-ID',"<tw-image>")
- twimg.add_header('Content-Disposition', 'inline', filename='tw.jpg')
- attachment13 = os.path.join(mail_template_path,'lnk.jpg')
- fp12 = open(attachment13,'rb')
- lknimg = MIMEImage(fp12.read())
- fp12.close()
- lknimg.add_header('Content-ID',"<link-image>")
- lknimg.add_header('Content-Disposition', 'inline', filename='lnk.jpg')
- msgRoot.attach(img)
- msgRoot.attach(topleftwhiteimg)
- msgRoot.attach(toprightwhiteimg)
- msgRoot.attach(topleftblueimg)
- msgRoot.attach(toprightblueimg)
- msgRoot.attach(reportimg)
- msgRoot.attach(bottomleftblueimg)
- msgRoot.attach(bottomrightblueimg)
- msgRoot.attach(bottomleftbrownimg)
- msgRoot.attach(bottomrightbrownimg)
- msgRoot.attach(fbimg)
- msgRoot.attach(twimg)
- msgRoot.attach(lknimg)
- TOADDR = [msgRoot['To']]
- CCADDR = [msgRoot['Bcc']]
- s.sendmail(sender,TOADDR+CCADDR,msgRoot.as_string())
- s.quit()
- logger.info("Successfully send no detailed alert mail to user %s"%str(user_id))
- return True
- except Exception as e:
- logger.error("Error while sending email %s"%str(e))
- return False
- # Send detail report email to user
- def sendDetailTwReportMail(report_id,user_id,twid,twname,email,config,mailFlag,uuid):
- if mailFlag == False:
- return True
- logger = logging.getLogger("repnuplogger")
- logger.info("Sending detail report to user %s",user_id)
- host_name = config.get('smtp_settings','host')
- user_name = config.get('smtp_settings','username')
- password = config.get('smtp_settings','password')
- mail_template_path = config.get('smtp_settings','mail_template_path')
- siteurl = config.get('admin_settings','site_url')
- sender = config.get('smtp_settings','sender')
- cc_address = config.get('admin_settings','cc_email')
- #email = 'marcomtl@gmail.com'
- uuid = str(uuid)
- try:
- fo = open(os.path.join(mail_template_path,'detailed_tw_report.html'))
- filecontent = fo.read()
- fo.close()
- messagebody = filecontent.replace("site_url",siteurl)
- twname = twname.encode('utf-8')
- messagebody = messagebody.replace("app_user_name",twname)
- messagebody = messagebody.replace("user_uuid",uuid)
- msgRoot = MIMEMultipart('related')
- msgRoot['Subject'] = "Your social media detailed report for Twitter from RepNup"
- msgRoot['From'] = "RepNup <reports@repnup.com>"
- msgRoot['To'] = email
- msgRoot['Bcc'] = cc_address
- msgRoot.preamble = 'This is a multi-part message in MIME format.'
- s = smtplib.SMTP(host_name)
- s.set_debuglevel(0)
- s.ehlo()
- if s.has_extn('STARTTLS'):
- s.starttls()
- s.ehlo()
- s.login(user_name,password)
- html_body = MIMEText(messagebody,'html')
- msg= MIMEMultipart('alternative')
- msgRoot.attach(msg)
- msg.attach(html_body)
- attachment = os.path.join(mail_template_path,'logo.jpg')
- fp = open(attachment,'rb')
- img = MIMEImage(fp.read())
- fp.close()
- img.add_header('Content-ID',"<logo-image>")
- img.add_header('Content-Disposition', 'inline', filename='logo.jpg')
- attachment2 = os.path.join(mail_template_path,'top-left-white-corner.gif')
- fp1 = open(attachment2,'rb')
- topleftwhiteimg = MIMEImage(fp1.read())
- fp1.close()
- topleftwhiteimg.add_header('Content-ID',"<top-left-white-image>")
- topleftwhiteimg.add_header('Content-Disposition', 'inline', filename='top-left-white-corner.gif')
- attachment3 = os.path.join(mail_template_path,'top-right-white-corner.gif')
- fp2 = open(attachment3,'rb')
- toprightwhiteimg = MIMEImage(fp2.read())
- fp2.close()
- toprightwhiteimg.add_header('Content-ID',"<top-right-white-image>")
- toprightwhiteimg.add_header('Content-Disposition', 'inline', filename='top-right-white-corner.gif')
- attachment4 = os.path.join(mail_template_path,'top-left-blue-corner.gif')
- fp3 = open(attachment4,'rb')
- topleftblueimg = MIMEImage(fp3.read())
- fp3.close()
- topleftblueimg.add_header('Content-ID',"<top-left-blue-image>")
- topleftblueimg.add_header('Content-Disposition', 'inline', filename='top-left-blue-corner.gif')
- attachment5 = os.path.join(mail_template_path,'top-right-blue-corner.gif')
- fp4 = open(attachment5,'rb')
- toprightblueimg = MIMEImage(fp4.read())
- fp4.close()
- toprightblueimg.add_header('Content-ID',"<top-right-blue-image>")
- toprightblueimg.add_header('Content-Disposition', 'inline', filename='top-right-blue-corner.gif')
- attachment6 = os.path.join(mail_template_path,'report_ready.jpg')
- fp5 = open(attachment6,'rb')
- reportimg = MIMEImage(fp5.read())
- fp5.close()
- reportimg.add_header('Content-ID',"<report-ready-image>")
- reportimg.add_header('Content-Disposition', 'inline', filename='report_ready.jpg')
- attachment7 = os.path.join(mail_template_path,'bottom-left-blue-corner.gif')
- fp6 = open(attachment7,'rb')
- bottomleftblueimg = MIMEImage(fp6.read())
- fp6.close()
- bottomleftblueimg.add_header('Content-ID',"<bottom-left-blue-image>")
- bottomleftblueimg.add_header('Content-Disposition', 'inline', filename='bottom-left-blue-corner.gif')
- attachment8 = os.path.join(mail_template_path,'bottom-right-blue-corner.gif')
- fp7 = open(attachment8,'rb')
- bottomrightblueimg = MIMEImage(fp7.read())
- fp7.close()
- bottomrightblueimg.add_header('Content-ID',"<bottom-right-blue-image>")
- bottomrightblueimg.add_header('Content-Disposition', 'inline', filename='bottom-right-blue-corner.gif')
- attachment9 = os.path.join(mail_template_path,'bottom-left-brown-corner.gif')
- fp8 = open(attachment9,'rb')
- bottomleftbrownimg = MIMEImage(fp8.read())
- fp8.close()
- bottomleftbrownimg.add_header('Content-ID',"<bottom-left-brown-image>")
- bottomleftbrownimg.add_header('Content-Disposition', 'inline', filename='bottom-left-brown-corner.gif')
- attachment10 = os.path.join(mail_template_path,'bottom-right-brown-corner.gif')
- fp9 = open(attachment10,'rb')
- bottomrightbrownimg = MIMEImage(fp9.read())
- fp9.close()
- bottomrightbrownimg.add_header('Content-ID',"<bottom-right-brown-image>")
- bottomrightbrownimg.add_header('Content-Disposition', 'inline', filename='bottom-right-brown-corner.gif')
- attachment11 = os.path.join(mail_template_path,'fb.jpg')
- fp10 = open(attachment11,'rb')
- fbimg = MIMEImage(fp10.read())
- fp10.close()
- fbimg.add_header('Content-ID',"<fb-image>")
- fbimg.add_header('Content-Disposition', 'inline', filename='fb.jpg')
- attachment12 = os.path.join(mail_template_path,'tw.jpg')
- fp11 = open(attachment12,'rb')
- twimg = MIMEImage(fp11.read())
- fp11.close()
- twimg.add_header('Content-ID',"<tw-image>")
- twimg.add_header('Content-Disposition', 'inline', filename='tw.jpg')
- attachment13 = os.path.join(mail_template_path,'lnk.jpg')
- fp12 = open(attachment13,'rb')
- lknimg = MIMEImage(fp12.read())
- fp12.close()
- lknimg.add_header('Content-ID',"<link-image>")
- lknimg.add_header('Content-Disposition', 'inline', filename='lnk.jpg')
- msgRoot.attach(img)
- msgRoot.attach(topleftwhiteimg)
- msgRoot.attach(toprightwhiteimg)
- msgRoot.attach(topleftblueimg)
- msgRoot.attach(toprightblueimg)
- msgRoot.attach(reportimg)
- msgRoot.attach(bottomleftblueimg)
- msgRoot.attach(bottomrightblueimg)
- msgRoot.attach(bottomleftbrownimg)
- msgRoot.attach(bottomrightbrownimg)
- msgRoot.attach(fbimg)
- msgRoot.attach(twimg)
- msgRoot.attach(lknimg)
- TOADDR = [msgRoot['To']]
- CCADDR = [msgRoot['Bcc']]
- s.sendmail(sender,TOADDR+CCADDR,msgRoot.as_string())
- s.quit()
- logger.info("Successfully send detail report mail to user %s"%str(user_id))
- return True
- except Exception as e:
- logger.error("Error while sending email %s"%str(e))
- return False
- # notify user for upgrade
- def notify_user_to_upgrade(fbuser_name,email,user_id, user_image_path, config):
- logger = logging.getLogger("repnuplogger")
- logger.info("Sending mail to user %s for upgrading account "%str(user_id))
- host_name = config.get('smtp_settings','host')
- user_name = config.get('smtp_settings','username')
- password = config.get('smtp_settings','password')
- mail_template_path = config.get('smtp_settings','mail_template_path')
- siteurl = config.get('admin_settings','site_url')
- sender = config.get('smtp_settings','sender')
- try:
- fo = open(os.path.join(mail_template_path,'upgrade_account.html'))
- filecontent = fo.read()
- fo.close()
- messagebody = filecontent.replace("site_url",siteurl)
- fbuser_name = fbuser_name.encode('utf-8')
- messagebody = messagebody.replace("app_user_name",fbuser_name)
- msgRoot = MIMEMultipart('related')
- msgRoot['Subject'] = "Please upgrade your RepNup account"
- msgRoot['From'] = "RepNup <reports@repnup.com>"
- msgRoot['To'] = email
- msgRoot.preamble = 'This is a multi-part message in MIME format.'
- s = smtplib.SMTP(host_name)
- s.set_debuglevel(0)
- s.ehlo()
- if s.has_extn('STARTTLS'):
- s.starttls()
- s.ehlo()
- s.login(user_name,password)
- html_body = MIMEText(messagebody, 'html')
- msg= MIMEMultipart('alternative')
- msgRoot.attach(msg)
- msg.attach(html_body)
- attachment = os.path.join(mail_template_path,'rep.png')
- fp = open(attachment,'rb')
- img = MIMEImage(fp.read())
- fp.close()
- img.add_header('Content-ID',"<header-image>")
- img.add_header('Content-Disposition', 'inline', filename='rep.png')
- attachment2 = os.path.join(mail_template_path,'fb.png')
- fp1 = open(attachment2,'rb')
- fbimg = MIMEImage(fp1.read())
- fp1.close()
- fbimg.add_header('Content-ID',"<fb-icon-image>")
- fbimg.add_header('Content-Disposition', 'inline', filename='fb.png')
- attachment3 = os.path.join(mail_template_path,'tw.png')
- fp2 = open(attachment3,'rb')
- twimg = MIMEImage(fp2.read())
- fp2.close()
- twimg.add_header('Content-ID',"<tw-icon-image>")
- twimg.add_header('Content-Disposition', 'inline', filename='tw.png')
- fp3 = open(user_image_path,'rv')
- userimg = MIMEImage(fp3.read(), "JPG")
- fp3.close()
- userimg.add_header('Content-ID', "<user-image>")
- msgRoot.attach(img)
- msgRoot.attach(fbimg)
- msgRoot.attach(twimg)
- msgRoot.attach(userimg)
- msgRoot['To'] = email
- TOADDR = [msgRoot['To']]
- s.sendmail(sender,TOADDR,msgRoot.as_string())
- s.quit()
- logger.info("Successfully send summary mail to user %s"%str(user_id))
- return True
- except Exception as e:
- logger.error("Error while sending email %s"%str(e))
- return False
- def notify_upgraded_to_pro_user(fbuser_name, email, user_id, config, uuid):
- logger = logging.getLogger("repnuplogger")
- logger.info("Sending mail to user %s for pro account " % str(user_id))
- host_name = config.get('smtp_settings', 'host')
- user_name = config.get('smtp_settings', 'username')
- password = config.get('smtp_settings', 'password')
- mail_template_path = config.get('smtp_settings', 'mail_template_path')
- siteurl = config.get('admin_settings', 'site_url')
- sender = config.get('smtp_settings', 'sender')
- try:
- fo = open(os.path.join(mail_template_path, 'upgraded_to_pro.html'))
- filecontent = fo.read()
- fo.close()
- messagebody = filecontent.replace("site_url",siteurl)
- fbuser_name = fbuser_name.encode('utf-8')
- messagebody = messagebody.replace("app_user_name", fbuser_name)
- messagebody = messagebody.replace("user_uuid", str(uuid))
- msgRoot = MIMEMultipart('related')
- msgRoot['Subject'] = "Your Rep'nUp account upgraded to pro"
- msgRoot['From'] = "RepNup <reports@repnup.com>"
- msgRoot['To'] = email
- msgRoot.preamble = 'This is a multi-part message in MIME format.'
- s = smtplib.SMTP(host_name)
- s.set_debuglevel(0)
- s.ehlo()
- if s.has_extn('STARTTLS'):
- s.starttls()
- s.ehlo()
- s.login(user_name, password)
- html_body = MIMEText(messagebody, 'html')
- msg= MIMEMultipart('alternative')
- msgRoot.attach(msg)
- msg.attach(html_body)
- attachment = os.path.join(mail_template_path,'rep.png')
- fp = open(attachment,'rb')
- img = MIMEImage(fp.read())
- fp.close()
- img.add_header('Content-ID',"<header-image>")
- img.add_header('Content-Disposition', 'inline', filename='rep.png')
- attachment2 = os.path.join(mail_template_path,'fb.png')
- fp1 = open(attachment2,'rb')
- fbimg = MIMEImage(fp1.read())
- fp1.close()
- fbimg.add_header('Content-ID',"<fb-icon-image>")
- fbimg.add_header('Content-Disposition', 'inline', filename='fb.png')
- attachment3 = os.path.join(mail_template_path,'tw.png')
- fp2 = open(attachment3,'rb')
- twimg = MIMEImage(fp2.read())
- fp2.close()
- twimg.add_header('Content-ID',"<tw-icon-image>")
- twimg.add_header('Content-Disposition', 'inline', filename='tw.png')
- msgRoot.attach(img)
- msgRoot.attach(fbimg)
- msgRoot.attach(twimg)
- msgRoot['To'] = email
- TOADDR = [msgRoot['To']]
- s.sendmail(sender, TOADDR, msgRoot.as_string())
- s.quit()
- logger.info("Successfully send upgraded_to_pro mail to user %s"%str(user_id))
- return True
- except Exception as e:
- logger.error("Error while sending email %s"%str(e))
- return False
- # Send no alert email to user
- def sendNoInAlertMail(report_id,user_id,instaid,instaname,email,totalFeed,totalImageCount,config,mailFlag,uuid):
- if mailFlag == False:
- return True
- logger = logging.getLogger("repnuplogger")
- logger.info("Sending no alert email to user %s",user_id)
- host_name = config.get('smtp_settings','host')
- user_name = config.get('smtp_settings','username')
- password = config.get('smtp_settings','password')
- mail_template_path = config.get('smtp_settings','mail_template_path')
- siteurl = config.get('admin_settings','site_url')
- sender = config.get('smtp_settings','sender')
- cc_address = config.get('admin_settings','cc_email')
- #email = 'marcomtl@gmail.com'
- uuid = str(uuid)
- try:
- fo = open(os.path.join(mail_template_path,'no_alert_in_report.html'))
- filecontent = fo.read()
- fo.close()
- messagebody = filecontent.replace("site_url",siteurl)
- instaname = instaname.encode('utf-8')
- messagebody = messagebody.replace("app_user_name",instaname)
- messagebody = messagebody.replace("user_total_feed ",str(totalImageCount))
- messagebody = messagebody.replace("total_media",str(totalImageCount))
- messagebody = messagebody.replace("total_text",str(totalFeed))
- messagebody = messagebody.replace("user_uuid", uuid)
- msgRoot = MIMEMultipart('related')
- msgRoot['Subject'] = "Your social media report for Instagram from RepNup"
- msgRoot['From'] = "RepNup <reports@repnup.com>"
- msgRoot['To'] = email
- msgRoot['Bcc'] = cc_address
- msgRoot.preamble = 'This is a multi-part message in MIME format.'
- s = smtplib.SMTP(host_name)
- s.set_debuglevel(0)
- s.ehlo()
- if s.has_extn('STARTTLS'):
- s.starttls()
- s.ehlo()
- s.login(user_name,password)
- html_body = MIMEText(messagebody,'html')
- msg= MIMEMultipart('alternative')
- msgRoot.attach(msg)
- msg.attach(html_body)
- attachment = os.path.join(mail_template_path,'logo.jpg')
- fp = open(attachment,'rb')
- img = MIMEImage(fp.read())
- fp.close()
- img.add_header('Content-ID',"<logo-image>")
- img.add_header('Content-Disposition', 'inline', filename='logo.jpg')
- attachment2 = os.path.join(mail_template_path,'top-left-white-corner.gif')
- fp1 = open(attachment2,'rb')
- topleftwhiteimg = MIMEImage(fp1.read())
- fp1.close()
- topleftwhiteimg.add_header('Content-ID',"<top-left-white-image>")
- topleftwhiteimg.add_header('Content-Disposition', 'inline', filename='top-left-white-corner.gif')
- attachment3 = os.path.join(mail_template_path,'top-right-white-corner.gif')
- fp2 = open(attachment3,'rb')
- toprightwhiteimg = MIMEImage(fp2.read())
- fp2.close()
- toprightwhiteimg.add_header('Content-ID',"<top-right-white-image>")
- toprightwhiteimg.add_header('Content-Disposition', 'inline', filename='top-right-white-corner.gif')
- attachment4 = os.path.join(mail_template_path,'top-left-blue-corner.gif')
- fp3 = open(attachment4,'rb')
- topleftblueimg = MIMEImage(fp3.read())
- fp3.close()
- topleftblueimg.add_header('Content-ID',"<top-left-blue-image>")
- topleftblueimg.add_header('Content-Disposition', 'inline', filename='top-left-blue-corner.gif')
- attachment5 = os.path.join(mail_template_path,'top-right-blue-corner.gif')
- fp4 = open(attachment5,'rb')
- toprightblueimg = MIMEImage(fp4.read())
- fp4.close()
- toprightblueimg.add_header('Content-ID',"<top-right-blue-image>")
- toprightblueimg.add_header('Content-Disposition', 'inline', filename='top-right-blue-corner.gif')
- attachment6 = os.path.join(mail_template_path,'report_ready.jpg')
- fp5 = open(attachment6,'rb')
- reportimg = MIMEImage(fp5.read())
- fp5.close()
- reportimg.add_header('Content-ID',"<report-ready-image>")
- reportimg.add_header('Content-Disposition', 'inline', filename='report_ready.jpg')
- attachment7 = os.path.join(mail_template_path,'bottom-left-blue-corner.gif')
- fp6 = open(attachment7,'rb')
- bottomleftblueimg = MIMEImage(fp6.read())
- fp6.close()
- bottomleftblueimg.add_header('Content-ID',"<bottom-left-blue-image>")
- bottomleftblueimg.add_header('Content-Disposition', 'inline', filename='bottom-left-blue-corner.gif')
- attachment8 = os.path.join(mail_template_path,'bottom-right-blue-corner.gif')
- fp7 = open(attachment8,'rb')
- bottomrightblueimg = MIMEImage(fp7.read())
- fp7.close()
- bottomrightblueimg.add_header('Content-ID',"<bottom-right-blue-image>")
- bottomrightblueimg.add_header('Content-Disposition', 'inline', filename='bottom-right-blue-corner.gif')
- attachment9 = os.path.join(mail_template_path,'bottom-left-brown-corner.gif')
- fp8 = open(attachment9,'rb')
- bottomleftbrownimg = MIMEImage(fp8.read())
- fp8.close()
- bottomleftbrownimg.add_header('Content-ID',"<bottom-left-brown-image>")
- bottomleftbrownimg.add_header('Content-Disposition', 'inline', filename='bottom-left-brown-corner.gif')
- attachment10 = os.path.join(mail_template_path,'bottom-right-brown-corner.gif')
- fp9 = open(attachment10,'rb')
- bottomrightbrownimg = MIMEImage(fp9.read())
- fp9.close()
- bottomrightbrownimg.add_header('Content-ID',"<bottom-right-brown-image>")
- bottomrightbrownimg.add_header('Content-Disposition', 'inline', filename='bottom-right-brown-corner.gif')
- attachment11 = os.path.join(mail_template_path,'fb.jpg')
- fp10 = open(attachment11,'rb')
- fbimg = MIMEImage(fp10.read())
- fp10.close()
- fbimg.add_header('Content-ID',"<fb-image>")
- fbimg.add_header('Content-Disposition', 'inline', filename='fb.jpg')
- attachment12 = os.path.join(mail_template_path,'tw.jpg')
- fp11 = open(attachment12,'rb')
- twimg = MIMEImage(fp11.read())
- fp11.close()
- twimg.add_header('Content-ID',"<tw-image>")
- twimg.add_header('Content-Disposition', 'inline', filename='tw.jpg')
- attachment13 = os.path.join(mail_template_path,'lnk.jpg')
- fp12 = open(attachment13,'rb')
- lknimg = MIMEImage(fp12.read())
- fp12.close()
- lknimg.add_header('Content-ID',"<link-image>")
- lknimg.add_header('Content-Disposition', 'inline', filename='lnk.jpg')
- msgRoot.attach(img)
- msgRoot.attach(topleftwhiteimg)
- msgRoot.attach(toprightwhiteimg)
- msgRoot.attach(topleftblueimg)
- msgRoot.attach(toprightblueimg)
- msgRoot.attach(reportimg)
- msgRoot.attach(bottomleftblueimg)
- msgRoot.attach(bottomrightblueimg)
- msgRoot.attach(bottomleftbrownimg)
- msgRoot.attach(bottomrightbrownimg)
- msgRoot.attach(fbimg)
- msgRoot.attach(twimg)
- msgRoot.attach(lknimg)
- TOADDR = [msgRoot['To']]
- CCADDR = [msgRoot['Bcc']]
- s.sendmail(sender,TOADDR+CCADDR,msgRoot.as_string())
- s.quit()
- logger.info("Successfully send no alert mail to user %s"%str(user_id))
- return True
- except Exception as e:
- logger.error("Error while sending email %s"%str(e))
- return False
- # Send no alert email to user
- #Send initial report email to user
- def sendInitialInMail(report_id,user_id,instaname,email,config,mailFlag,uuid):
- if mailFlag == False:
- return True
- logger = logging.getLogger("repnuplogger")
- logger.info("Sending initial summary mail to user %s",user_id)
- host_name = config.get('smtp_settings','host')
- user_name = config.get('smtp_settings','username')
- password = config.get('smtp_settings','password')
- mail_template_path = config.get('smtp_settings','mail_template_path')
- siteurl = config.get('admin_settings','site_url')
- sender = config.get('smtp_settings','sender')
- cc_address = config.get('admin_settings','cc_email')
- #email = 'marcomtl@gmail.com';
- uuid = str(uuid)
- try:
- fo = open(os.path.join(mail_template_path,'initial_in_report.html'))
- filecontent = fo.read()
- fo.close()
- messagebody = filecontent.replace("site_url",siteurl)
- messagebody = messagebody.replace("user_uuid",uuid)
- instaname = instaname.encode('utf-8')
- messagebody = messagebody.replace("app_user_name",instaname)
- msgRoot = MIMEMultipart('related')
- msgRoot['Subject'] = "Your social media initial report for Instagram from RepNup"
- msgRoot['From'] = "RepNup <reports@repnup.com>"
- msgRoot['To'] = email
- msgRoot['Bcc'] = cc_address
- msgRoot.preamble = 'This is a multi-part message in MIME format.'
- s = smtplib.SMTP(host_name)
- s.set_debuglevel(0)
- s.ehlo()
- if s.has_extn('STARTTLS'):
- s.starttls()
- s.ehlo()
- s.login(user_name,password)
- html_body = MIMEText(messagebody,'html')
- msg= MIMEMultipart('alternative')
- msgRoot.attach(msg)
- msg.attach(html_body)
- attachment = os.path.join(mail_template_path,'logo.jpg')
- fp = open(attachment,'rb')
- img = MIMEImage(fp.read())
- fp.close()
- img.add_header('Content-ID',"<logo-image>")
- img.add_header('Content-Disposition', 'inline', filename='logo.jpg')
- attachment2 = os.path.join(mail_template_path,'top-left-white-corner.gif')
- fp1 = open(attachment2,'rb')
- topleftwhiteimg = MIMEImage(fp1.read())
- fp1.close()
- topleftwhiteimg.add_header('Content-ID',"<top-left-white-image>")
- topleftwhiteimg.add_header('Content-Disposition', 'inline', filename='top-left-white-corner.gif')
- attachment3 = os.path.join(mail_template_path,'top-right-white-corner.gif')
- fp2 = open(attachment3,'rb')
- toprightwhiteimg = MIMEImage(fp2.read())
- fp2.close()
- toprightwhiteimg.add_header('Content-ID',"<top-right-white-image>")
- toprightwhiteimg.add_header('Content-Disposition', 'inline', filename='top-right-white-corner.gif')
- attachment4 = os.path.join(mail_template_path,'top-left-blue-corner.gif')
- fp3 = open(attachment4,'rb')
- topleftblueimg = MIMEImage(fp3.read())
- fp3.close()
- topleftblueimg.add_header('Content-ID',"<top-left-blue-image>")
- topleftblueimg.add_header('Content-Disposition', 'inline', filename='top-left-blue-corner.gif')
- attachment5 = os.path.join(mail_template_path,'top-right-blue-corner.gif')
- fp4 = open(attachment5,'rb')
- toprightblueimg = MIMEImage(fp4.read())
- fp4.close()
- toprightblueimg.add_header('Content-ID',"<top-right-blue-image>")
- toprightblueimg.add_header('Content-Disposition', 'inline', filename='top-right-blue-corner.gif')
- attachment6 = os.path.join(mail_template_path, 'report_in_process.jpg')
- fp5 = open(attachment6,'rb')
- reportimg = MIMEImage(fp5.read())
- fp5.close()
- reportimg.add_header('Content-ID',"<report-image>")
- reportimg.add_header('Content-Disposition', 'inline', filename='report_in_process.jpg')
- attachment7 = os.path.join(mail_template_path,'bottom-left-blue-corner.gif')
- fp6 = open(attachment7,'rb')
- bottomleftblueimg = MIMEImage(fp6.read())
- fp6.close()
- bottomleftblueimg.add_header('Content-ID',"<bottom-left-blue-image>")
- bottomleftblueimg.add_header('Content-Disposition', 'inline', filename='bottom-left-blue-corner.gif')
- attachment8 = os.path.join(mail_template_path,'bottom-right-blue-corner.gif')
- fp7 = open(attachment8,'rb')
- bottomrightblueimg = MIMEImage(fp7.read())
- fp7.close()
- bottomrightblueimg.add_header('Content-ID',"<bottom-right-blue-image>")
- bottomrightblueimg.add_header('Content-Disposition', 'inline', filename='bottom-right-blue-corner.gif')
- attachment9 = os.path.join(mail_template_path,'bottom-left-brown-corner.gif')
- fp8 = open(attachment9,'rb')
- bottomleftbrownimg = MIMEImage(fp8.read())
- fp8.close()
- bottomleftbrownimg.add_header('Content-ID',"<bottom-left-brown-image>")
- bottomleftbrownimg.add_header('Content-Disposition', 'inline', filename='bottom-left-brown-corner.gif')
- attachment10 = os.path.join(mail_template_path,'bottom-right-brown-corner.gif')
- fp9 = open(attachment10,'rb')
- bottomrightbrownimg = MIMEImage(fp9.read())
- fp9.close()
- bottomrightbrownimg.add_header('Content-ID',"<bottom-right-brown-image>")
- bottomrightbrownimg.add_header('Content-Disposition', 'inline', filename='bottom-right-brown-corner.gif')
- attachment11 = os.path.join(mail_template_path,'fb.jpg')
- fp10 = open(attachment11,'rb')
- fbimg = MIMEImage(fp10.read())
- fp10.close()
- fbimg.add_header('Content-ID',"<fb-image>")
- fbimg.add_header('Content-Disposition', 'inline', filename='fb.jpg')
- attachment12 = os.path.join(mail_template_path,'tw.jpg')
- fp11 = open(attachment12,'rb')
- twimg = MIMEImage(fp11.read())
- fp11.close()
- twimg.add_header('Content-ID',"<tw-image>")
- twimg.add_header('Content-Disposition', 'inline', filename='tw.jpg')
- attachment13 = os.path.join(mail_template_path,'lnk.jpg')
- fp12 = open(attachment13,'rb')
- lknimg = MIMEImage(fp12.read())
- fp12.close()
- lknimg.add_header('Content-ID',"<link-image>")
- lknimg.add_header('Content-Disposition', 'inline', filename='lnk.jpg')
- msgRoot.attach(img)
- msgRoot.attach(topleftwhiteimg)
- msgRoot.attach(toprightwhiteimg)
- msgRoot.attach(topleftblueimg)
- msgRoot.attach(toprightblueimg)
- msgRoot.attach(reportimg)
- msgRoot.attach(bottomleftblueimg)
- msgRoot.attach(bottomrightblueimg)
- msgRoot.attach(bottomleftbrownimg)
- msgRoot.attach(bottomrightbrownimg)
- msgRoot.attach(fbimg)
- msgRoot.attach(twimg)
- msgRoot.attach(lknimg)
- TOADDR = [msgRoot['To']]
- CCADDR = [msgRoot['Bcc']]
- s.sendmail(sender,TOADDR+CCADDR,msgRoot.as_string())
- s.quit()
- logger.info("Successfully send summary mail to user %s"%str(user_id))
- return True
- except Exception as e:
- logger.error("Error while sending email %s"%str(e))
- return False
- # Send summary email to user
- def sendInSummaryMail(report_id,user_id,instaname,email,totalFeedCount,totalAlert,config,mailFlag,uuid):
- if mailFlag == False:
- return True
- logger = logging.getLogger("repnuplogger")
- logger.info("Sending summary mail to user %s with report id %s"%(user_id,str(report_id)))
- host_name = config.get('smtp_settings','host')
- user_name = config.get('smtp_settings','username')
- password = config.get('smtp_settings','password')
- mail_template_path = config.get('smtp_settings','mail_template_path')
- siteurl = config.get('admin_settings','site_url')
- sender = config.get('smtp_settings','sender')
- cc_address = config.get('admin_settings','cc_email')
- #email = 'margomtl@gmail.com'
- uuid = str(uuid)
- try:
- fo = open(os.path.join(mail_template_path,'summary_in_report.html'))
- filecontent = fo.read()
- fo.close()
- messagebody = filecontent.replace("site_url",siteurl)
- instaname = instaname.encode('utf-8')
- messagebody = messagebody.replace("app_user_name",instaname)
- messagebody = messagebody.replace("user_total_feed",str(totalFeedCount))
- messagebody = messagebody.replace("user_total_alerts",str(totalAlert))
- messagebody = messagebody.replace("user_uuid",uuid)
- msgRoot = MIMEMultipart('related')
- msgRoot['Subject'] = "Your social media summary report for Instagram from RepNup"
- msgRoot['From'] = "RepNup <reports@repnup.com>"
- msgRoot['To'] = email
- msgRoot['Bcc'] = cc_address
- msgRoot.preamble = 'This is a multi-part message in MIME format.'
- s = smtplib.SMTP(host_name)
- s.set_debuglevel(0)
- s.ehlo()
- if s.has_extn('STARTTLS'):
- s.starttls()
- s.ehlo()
- s.login(user_name,password)
- html_body = MIMEText(messagebody,'html')
- msg= MIMEMultipart('alternative')
- msgRoot.attach(msg)
- msg.attach(html_body)
- attachment = os.path.join(mail_template_path,'logo.jpg')
- fp = open(attachment,'rb')
- img = MIMEImage(fp.read())
- fp.close()
- img.add_header('Content-ID',"<logo-image>")
- img.add_header('Content-Disposition', 'inline', filename='logo.jpg')
- attachment2 = os.path.join(mail_template_path,'top-left-white-corner.gif')
- fp1 = open(attachment2,'rb')
- topleftwhiteimg = MIMEImage(fp1.read())
- fp1.close()
- topleftwhiteimg.add_header('Content-ID',"<top-left-white-image>")
- topleftwhiteimg.add_header('Content-Disposition', 'inline', filename='top-left-white-corner.gif')
- attachment3 = os.path.join(mail_template_path,'top-right-white-corner.gif')
- fp2 = open(attachment3,'rb')
- toprightwhiteimg = MIMEImage(fp2.read())
- fp2.close()
- toprightwhiteimg.add_header('Content-ID',"<top-right-white-image>")
- toprightwhiteimg.add_header('Content-Disposition', 'inline', filename='top-right-white-corner.gif')
- attachment4 = os.path.join(mail_template_path,'top-left-blue-corner.gif')
- fp3 = open(attachment4,'rb')
- topleftblueimg = MIMEImage(fp3.read())
- fp3.close()
- topleftblueimg.add_header('Content-ID',"<top-left-blue-image>")
- topleftblueimg.add_header('Content-Disposition', 'inline', filename='top-left-blue-corner.gif')
- attachment5 = os.path.join(mail_template_path,'top-right-blue-corner.gif')
- fp4 = open(attachment5,'rb')
- toprightblueimg = MIMEImage(fp4.read())
- fp4.close()
- toprightblueimg.add_header('Content-ID',"<top-right-blue-image>")
- toprightblueimg.add_header('Content-Disposition', 'inline', filename='top-right-blue-corner.gif')
- attachment6 = os.path.join(mail_template_path,'report_ready.jpg')
- fp5 = open(attachment6,'rb')
- reportimg = MIMEImage(fp5.read())
- fp5.close()
- reportimg.add_header('Content-ID',"<report-ready-image>")
- reportimg.add_header('Content-Disposition', 'inline', filename='report_ready.jpg')
- attachment7 = os.path.join(mail_template_path,'bottom-left-blue-corner.gif')
- fp6 = open(attachment7,'rb')
- bottomleftblueimg = MIMEImage(fp6.read())
- fp6.close()
- bottomleftblueimg.add_header('Content-ID',"<bottom-left-blue-image>")
- bottomleftblueimg.add_header('Content-Disposition', 'inline', filename='bottom-left-blue-corner.gif')
- attachment8 = os.path.join(mail_template_path,'bottom-right-blue-corner.gif')
- fp7 = open(attachment8,'rb')
- bottomrightblueimg = MIMEImage(fp7.read())
- fp7.close()
- bottomrightblueimg.add_header('Content-ID',"<bottom-right-blue-image>")
- bottomrightblueimg.add_header('Content-Disposition', 'inline', filename='bottom-right-blue-corner.gif')
- attachment9 = os.path.join(mail_template_path,'bottom-left-brown-corner.gif')
- fp8 = open(attachment9,'rb')
- bottomleftbrownimg = MIMEImage(fp8.read())
- fp8.close()
- bottomleftbrownimg.add_header('Content-ID',"<bottom-left-brown-image>")
- bottomleftbrownimg.add_header('Content-Disposition', 'inline', filename='bottom-left-brown-corner.gif')
- attachment10 = os.path.join(mail_template_path,'bottom-right-brown-corner.gif')
- fp9 = open(attachment10,'rb')
- bottomrightbrownimg = MIMEImage(fp9.read())
- fp9.close()
- bottomrightbrownimg.add_header('Content-ID',"<bottom-right-brown-image>")
- bottomrightbrownimg.add_header('Content-Disposition', 'inline', filename='bottom-right-brown-corner.gif')
- attachment11 = os.path.join(mail_template_path,'fb.jpg')
- fp10 = open(attachment11,'rb')
- fbimg = MIMEImage(fp10.read())
- fp10.close()
- fbimg.add_header('Content-ID',"<fb-image>")
- fbimg.add_header('Content-Disposition', 'inline', filename='fb.jpg')
- attachment12 = os.path.join(mail_template_path,'tw.jpg')
- fp11 = open(attachment12,'rb')
- twimg = MIMEImage(fp11.read())
- fp11.close()
- twimg.add_header('Content-ID',"<tw-image>")
- twimg.add_header('Content-Disposition', 'inline', filename='tw.jpg')
- attachment13 = os.path.join(mail_template_path,'lnk.jpg')
- fp12 = open(attachment13,'rb')
- lknimg = MIMEImage(fp12.read())
- fp12.close()
- lknimg.add_header('Content-ID',"<link-image>")
- lknimg.add_header('Content-Disposition', 'inline', filename='lnk.jpg')
- msgRoot.attach(img)
- msgRoot.attach(topleftwhiteimg)
- msgRoot.attach(toprightwhiteimg)
- msgRoot.attach(topleftblueimg)
- msgRoot.attach(toprightblueimg)
- msgRoot.attach(reportimg)
- msgRoot.attach(bottomleftblueimg)
- msgRoot.attach(bottomrightblueimg)
- msgRoot.attach(bottomleftbrownimg)
- msgRoot.attach(bottomrightbrownimg)
- msgRoot.attach(fbimg)
- msgRoot.attach(twimg)
- msgRoot.attach(lknimg)
- TOADDR = [msgRoot['To']]
- CCADDR = [msgRoot['Bcc']]
- s.sendmail(sender,TOADDR+CCADDR,msgRoot.as_string())
- s.quit()
- logger.info("Successfully send summary mail to user %s"%str(user_id))
- return True
- except Exception as e:
- logger.error("Error while sending email %s"%str(e))
- return False
- # process to send email to admins that instagram user is ready to review
- def in_notify_admin(type,user_id,db_conn,g_admin_emails,config):
- logger = logging.getLogger("repnuplogger")
- inuser = db_conn.selectOne('tbl_instagram_users',"user_id='"+str(user_id)+"'",'instagramId','fullName','text_status','media_status')
- logger.info("Sending mail to admin to review user for instagram %s"%str(inuser[0]))
- host_name = config.get('smtp_settings','host')
- user_name = config.get('smtp_settings','username')
- password = config.get('smtp_settings','password')
- mail_template_path = config.get('smtp_settings','mail_template_path')
- siteurl = config.get('admin_settings','site_url')
- sender = config.get('smtp_settings','sender')
- cc_address = config.get('admin_settings','cc_email')
- if inuser:
- if str(inuser[2]) =="3":
- try:
- fo = open(os.path.join(mail_template_path,'admin_report_ready.html'))
- filecontent = fo.read()
- fo.close()
- messagebody = filecontent.replace("site_url",siteurl)
- name = inuser[1].encode('utf-8')
- messagebody = messagebody.replace("fb_user_id",str(user_id))
- messagebody = messagebody.replace("fb_user_name",name)
- msgRoot = MIMEMultipart('related')
- if type ==1:
- msgRoot['Subject'] = "Please review text for " + name
- else :
- msgRoot['Subject'] = "Please review images for " + name
- msgRoot['From'] = "RepNup <reports@repnup.com>"
- msgRoot['To'] = g_admin_emails
- msgRoot.preamble = 'This is a multi-part message in MIME format.'
- s = smtplib.SMTP(host_name)
- s.set_debuglevel(0)
- s.ehlo()
- if s.has_extn('STARTTLS'):
- s.starttls()
- s.ehlo()
- s.login(user_name,password)
- html_body = MIMEText(messagebody,'html')
- msg= MIMEMultipart('alternative')
- msgRoot.attach(msg)
- msg.attach(html_body)
- attachment = os.path.join(mail_template_path,'rep.png')
- fp = open(attachment,'rb')
- img = MIMEImage(fp.read())
- fp.close()
- img.add_header('Content-ID',"<header-image>")
- img.add_header('Content-Disposition', 'inline', filename='rep.png')
- attachment2 = os.path.join(mail_template_path,'fb.png')
- fp1 = open(attachment2,'rb')
- fbimg = MIMEImage(fp1.read())
- fp1.close()
- fbimg.add_header('Content-ID',"<fb-icon-image>")
- fbimg.add_header('Content-Disposition', 'inline', filename='fb.png')
- attachment3 = os.path.join(mail_template_path,'tw.png')
- fp2 = open(attachment3,'rb')
- twimg = MIMEImage(fp2.read())
- fp2.close()
- twimg.add_header('Content-ID',"<tw-icon-image>")
- twimg.add_header('Content-Disposition', 'inline', filename='tw.png')
- msgRoot.attach(img)
- TOADDR = [msgRoot['To']]
- s.sendmail(sender,TOADDR,msgRoot.as_string())
- s.quit()
- rectime = time.strftime('%Y-%m-%d %H:%M:%S')
- if type ==1:
- db_conn.updateRec('tbl_users',"id='"+str(user_id)+"'",mail_status="admin_review_mail",instagramStatus=4,modified=rectime)
- else:
- db_conn.updateRec('tbl_users',"id='"+str(user_id)+"'",mail_status="admin_review_mail",instagramStatus=8,modified=rectime)
- logger.info("Successfully send mail to admin to review user %s"%str(inuser[0]))
- return True
- except Exception as e:
- logger.error("Error while sending email to admin %s"%str(e))
- return False
- else:
- return False
- def sendNoDetailInAlertMail(report_id,user_id,instaname,email,totalTextCount,totalMediaCount,config,mailFlag,uuid):
- if mailFlag == False:
- return True
- logger = logging.getLogger("repnuplogger")
- logger.info("Sending no detail alert mail to user %s", user_id)
- host_name = config.get('smtp_settings', 'host')
- user_name = config.get('smtp_settings', 'username')
- password = config.get('smtp_settings', 'password')
- mail_template_path = config.get('smtp_settings', 'mail_template_path')
- siteurl = config.get('admin_settings', 'site_url')
- sender = config.get('smtp_settings', 'sender')
- cc_address = config.get('admin_settings', 'cc_email')
- #email = 'marcomtl@gmail.com'
- uuid = str(uuid)
- try:
- fo = open(os.path.join(mail_template_path, 'no_alert_detail_in_report.html'))
- filecontent = fo.read()
- fo.close()
- messagebody = filecontent.replace("site_url", siteurl)
- instaname = instaname.encode('utf-8')
- messagebody = messagebody.replace("app_user_name", instaname)
- messagebody = messagebody.replace("total_text", str(totalTextCount))
- messagebody = messagebody.replace("total_media", str(totalMediaCount))
- messagebody = messagebody.replace("user_uuid", uuid)
- msgRoot = MIMEMultipart('related')
- msgRoot['Subject'] = "Your social media report for Instagram from RepNup"
- msgRoot['From'] = "RepNup <reports@repnup.com>"
- msgRoot['To'] = email
- msgRoot['Bcc'] = cc_address
- msgRoot.preamble = 'This is a multi-part message in MIME format.'
- s = smtplib.SMTP(host_name)
- s.set_debuglevel(0)
- s.ehlo()
- if s.has_extn('STARTTLS'):
- s.starttls()
- s.ehlo()
- s.login(user_name,password)
- html_body = MIMEText(messagebody,'html')
- msg= MIMEMultipart('alternative')
- msgRoot.attach(msg)
- msg.attach(html_body)
- attachment = os.path.join(mail_template_path,'logo.jpg')
- fp = open(attachment,'rb')
- img = MIMEImage(fp.read())
- fp.close()
- img.add_header('Content-ID',"<logo-image>")
- img.add_header('Content-Disposition', 'inline', filename='logo.jpg')
- attachment2 = os.path.join(mail_template_path,'top-left-white-corner.gif')
- fp1 = open(attachment2,'rb')
- topleftwhiteimg = MIMEImage(fp1.read())
- fp1.close()
- topleftwhiteimg.add_header('Content-ID',"<top-left-white-image>")
- topleftwhiteimg.add_header('Content-Disposition', 'inline', filename='top-left-white-corner.gif')
- attachment3 = os.path.join(mail_template_path,'top-right-white-corner.gif')
- fp2 = open(attachment3,'rb')
- toprightwhiteimg = MIMEImage(fp2.read())
- fp2.close()
- toprightwhiteimg.add_header('Content-ID',"<top-right-white-image>")
- toprightwhiteimg.add_header('Content-Disposition', 'inline', filename='top-right-white-corner.gif')
- attachment4 = os.path.join(mail_template_path,'top-left-blue-corner.gif')
- fp3 = open(attachment4,'rb')
- topleftblueimg = MIMEImage(fp3.read())
- fp3.close()
- topleftblueimg.add_header('Content-ID',"<top-left-blue-image>")
- topleftblueimg.add_header('Content-Disposition', 'inline', filename='top-left-blue-corner.gif')
- attachment5 = os.path.join(mail_template_path,'top-right-blue-corner.gif')
- fp4 = open(attachment5,'rb')
- toprightblueimg = MIMEImage(fp4.read())
- fp4.close()
- toprightblueimg.add_header('Content-ID',"<top-right-blue-image>")
- toprightblueimg.add_header('Content-Disposition', 'inline', filename='top-right-blue-corner.gif')
- attachment6 = os.path.join(mail_template_path,'report_ready.jpg')
- fp5 = open(attachment6,'rb')
- reportimg = MIMEImage(fp5.read())
- fp5.close()
- reportimg.add_header('Content-ID',"<report-ready-image>")
- reportimg.add_header('Content-Disposition', 'inline', filename='report_ready.jpg')
- attachment7 = os.path.join(mail_template_path,'bottom-left-blue-corner.gif')
- fp6 = open(attachment7,'rb')
- bottomleftblueimg = MIMEImage(fp6.read())
- fp6.close()
- bottomleftblueimg.add_header('Content-ID',"<bottom-left-blue-image>")
- bottomleftblueimg.add_header('Content-Disposition', 'inline', filename='bottom-left-blue-corner.gif')
- attachment8 = os.path.join(mail_template_path,'bottom-right-blue-corner.gif')
- fp7 = open(attachment8,'rb')
- bottomrightblueimg = MIMEImage(fp7.read())
- fp7.close()
- bottomrightblueimg.add_header('Content-ID',"<bottom-right-blue-image>")
- bottomrightblueimg.add_header('Content-Disposition', 'inline', filename='bottom-right-blue-corner.gif')
- attachment9 = os.path.join(mail_template_path,'bottom-left-brown-corner.gif')
- fp8 = open(attachment9,'rb')
- bottomleftbrownimg = MIMEImage(fp8.read())
- fp8.close()
- bottomleftbrownimg.add_header('Content-ID',"<bottom-left-brown-image>")
- bottomleftbrownimg.add_header('Content-Disposition', 'inline', filename='bottom-left-brown-corner.gif')
- attachment10 = os.path.join(mail_template_path,'bottom-right-brown-corner.gif')
- fp9 = open(attachment10,'rb')
- bottomrightbrownimg = MIMEImage(fp9.read())
- fp9.close()
- bottomrightbrownimg.add_header('Content-ID',"<bottom-right-brown-image>")
- bottomrightbrownimg.add_header('Content-Disposition', 'inline', filename='bottom-right-brown-corner.gif')
- attachment11 = os.path.join(mail_template_path,'fb.jpg')
- fp10 = open(attachment11,'rb')
- fbimg = MIMEImage(fp10.read())
- fp10.close()
- fbimg.add_header('Content-ID',"<fb-image>")
- fbimg.add_header('Content-Disposition', 'inline', filename='fb.jpg')
- attachment12 = os.path.join(mail_template_path,'tw.jpg')
- fp11 = open(attachment12,'rb')
- twimg = MIMEImage(fp11.read())
- fp11.close()
- twimg.add_header('Content-ID',"<tw-image>")
- twimg.add_header('Content-Disposition', 'inline', filename='tw.jpg')
- attachment13 = os.path.join(mail_template_path,'lnk.jpg')
- fp12 = open(attachment13,'rb')
- lknimg = MIMEImage(fp12.read())
- fp12.close()
- lknimg.add_header('Content-ID',"<link-image>")
- lknimg.add_header('Content-Disposition', 'inline', filename='lnk.jpg')
- msgRoot.attach(img)
- msgRoot.attach(topleftwhiteimg)
- msgRoot.attach(toprightwhiteimg)
- msgRoot.attach(topleftblueimg)
- msgRoot.attach(toprightblueimg)
- msgRoot.attach(reportimg)
- msgRoot.attach(bottomleftblueimg)
- msgRoot.attach(bottomrightblueimg)
- msgRoot.attach(bottomleftbrownimg)
- msgRoot.attach(bottomrightbrownimg)
- msgRoot.attach(fbimg)
- msgRoot.attach(twimg)
- msgRoot.attach(lknimg)
- TOADDR = [msgRoot['To']]
- CCADDR = [msgRoot['Bcc']]
- msgRoot.attach(img)
- msgRoot.attach(fbimg)
- msgRoot.attach(twimg)
- s.sendmail(sender,TOADDR+CCADDR,msgRoot.as_string())
- s.quit()
- logger.info("Successfully send no detailed alert mail to user %s"%str(user_id))
- return True
- except Exception as e:
- logger.error("Error while sending email %s"%str(e))
- return False
- # Send detail report email to user
- def sendDetailInReportMail(report_id,user_id,instaname,email,config,mailFlag,uuid):
- if mailFlag == False:
- return True
- logger = logging.getLogger("repnuplogger")
- logger.info("Sending detail report to user %s",user_id)
- host_name = config.get('smtp_settings','host')
- user_name = config.get('smtp_settings','username')
- password = config.get('smtp_settings','password')
- mail_template_path = config.get('smtp_settings','mail_template_path')
- siteurl = config.get('admin_settings','site_url')
- sender = config.get('smtp_settings','sender')
- cc_address = config.get('admin_settings','cc_email')
- #email = 'marcomtl@gmail.com'
- uuid = str(uuid)
- try:
- fo = open(os.path.join(mail_template_path,'detailed_in_report.html'))
- filecontent = fo.read()
- fo.close()
- messagebody = filecontent.replace("site_url",siteurl)
- instaname = instaname.encode('utf-8')
- messagebody = messagebody.replace("app_user_name",instaname)
- messagebody = messagebody.replace("user_uuid",uuid)
- msgRoot = MIMEMultipart('related')
- msgRoot['Subject'] = "Your social media detailed report for Instagram from RepNup"
- msgRoot['From'] = "RepNup <reports@repnup.com>"
- msgRoot['To'] = email
- msgRoot['Bcc'] = cc_address
- msgRoot.preamble = 'This is a multi-part message in MIME format.'
- s = smtplib.SMTP(host_name)
- s.set_debuglevel(0)
- s.ehlo()
- if s.has_extn('STARTTLS'):
- s.starttls()
- s.ehlo()
- s.login(user_name,password)
- html_body = MIMEText(messagebody,'html')
- msg= MIMEMultipart('alternative')
- msgRoot.attach(msg)
- msg.attach(html_body)
- attachment = os.path.join(mail_template_path,'logo.jpg')
- fp = open(attachment,'rb')
- img = MIMEImage(fp.read())
- fp.close()
- img.add_header('Content-ID',"<logo-image>")
- img.add_header('Content-Disposition', 'inline', filename='logo.jpg')
- attachment2 = os.path.join(mail_template_path,'top-left-white-corner.gif')
- fp1 = open(attachment2,'rb')
- topleftwhiteimg = MIMEImage(fp1.read())
- fp1.close()
- topleftwhiteimg.add_header('Content-ID',"<top-left-white-image>")
- topleftwhiteimg.add_header('Content-Disposition', 'inline', filename='top-left-white-corner.gif')
- attachment3 = os.path.join(mail_template_path,'top-right-white-corner.gif')
- fp2 = open(attachment3,'rb')
- toprightwhiteimg = MIMEImage(fp2.read())
- fp2.close()
- toprightwhiteimg.add_header('Content-ID',"<top-right-white-image>")
- toprightwhiteimg.add_header('Content-Disposition', 'inline', filename='top-right-white-corner.gif')
- attachment4 = os.path.join(mail_template_path,'top-left-blue-corner.gif')
- fp3 = open(attachment4,'rb')
- topleftblueimg = MIMEImage(fp3.read())
- fp3.close()
- topleftblueimg.add_header('Content-ID',"<top-left-blue-image>")
- topleftblueimg.add_header('Content-Disposition', 'inline', filename='top-left-blue-corner.gif')
- attachment5 = os.path.join(mail_template_path,'top-right-blue-corner.gif')
- fp4 = open(attachment5,'rb')
- toprightblueimg = MIMEImage(fp4.read())
- fp4.close()
- toprightblueimg.add_header('Content-ID',"<top-right-blue-image>")
- toprightblueimg.add_header('Content-Disposition', 'inline', filename='top-right-blue-corner.gif')
- attachment6 = os.path.join(mail_template_path,'report_ready.jpg')
- fp5 = open(attachment6,'rb')
- reportimg = MIMEImage(fp5.read())
- fp5.close()
- reportimg.add_header('Content-ID',"<report-ready-image>")
- reportimg.add_header('Content-Disposition', 'inline', filename='report_ready.jpg')
- attachment7 = os.path.join(mail_template_path,'bottom-left-blue-corner.gif')
- fp6 = open(attachment7,'rb')
- bottomleftblueimg = MIMEImage(fp6.read())
- fp6.close()
- bottomleftblueimg.add_header('Content-ID',"<bottom-left-blue-image>")
- bottomleftblueimg.add_header('Content-Disposition', 'inline', filename='bottom-left-blue-corner.gif')
- attachment8 = os.path.join(mail_template_path,'bottom-right-blue-corner.gif')
- fp7 = open(attachment8,'rb')
- bottomrightblueimg = MIMEImage(fp7.read())
- fp7.close()
- bottomrightblueimg.add_header('Content-ID',"<bottom-right-blue-image>")
- bottomrightblueimg.add_header('Content-Disposition', 'inline', filename='bottom-right-blue-corner.gif')
- attachment9 = os.path.join(mail_template_path,'bottom-left-brown-corner.gif')
- fp8 = open(attachment9,'rb')
- bottomleftbrownimg = MIMEImage(fp8.read())
- fp8.close()
- bottomleftbrownimg.add_header('Content-ID',"<bottom-left-brown-image>")
- bottomleftbrownimg.add_header('Content-Disposition', 'inline', filename='bottom-left-brown-corner.gif')
- attachment10 = os.path.join(mail_template_path,'bottom-right-brown-corner.gif')
- fp9 = open(attachment10,'rb')
- bottomrightbrownimg = MIMEImage(fp9.read())
- fp9.close()
- bottomrightbrownimg.add_header('Content-ID',"<bottom-right-brown-image>")
- bottomrightbrownimg.add_header('Content-Disposition', 'inline', filename='bottom-right-brown-corner.gif')
- attachment11 = os.path.join(mail_template_path,'fb.jpg')
- fp10 = open(attachment11,'rb')
- fbimg = MIMEImage(fp10.read())
- fp10.close()
- fbimg.add_header('Content-ID',"<fb-image>")
- fbimg.add_header('Content-Disposition', 'inline', filename='fb.jpg')
- attachment12 = os.path.join(mail_template_path,'tw.jpg')
- fp11 = open(attachment12,'rb')
- twimg = MIMEImage(fp11.read())
- fp11.close()
- twimg.add_header('Content-ID',"<tw-image>")
- twimg.add_header('Content-Disposition', 'inline', filename='tw.jpg')
- attachment13 = os.path.join(mail_template_path,'lnk.jpg')
- fp12 = open(attachment13,'rb')
- lknimg = MIMEImage(fp12.read())
- fp12.close()
- lknimg.add_header('Content-ID',"<link-image>")
- lknimg.add_header('Content-Disposition', 'inline', filename='lnk.jpg')
- msgRoot.attach(img)
- msgRoot.attach(topleftwhiteimg)
- msgRoot.attach(toprightwhiteimg)
- msgRoot.attach(topleftblueimg)
- msgRoot.attach(toprightblueimg)
- msgRoot.attach(reportimg)
- msgRoot.attach(bottomleftblueimg)
- msgRoot.attach(bottomrightblueimg)
- msgRoot.attach(bottomleftbrownimg)
- msgRoot.attach(bottomrightbrownimg)
- msgRoot.attach(fbimg)
- msgRoot.attach(twimg)
- msgRoot.attach(lknimg)
- TOADDR = [msgRoot['To']]
- CCADDR = [msgRoot['Bcc']]
- s.sendmail(sender,TOADDR+CCADDR,msgRoot.as_string())
- s.quit()
- logger.info("Successfully send detail report mail to user %s"%str(user_id))
- return True
- except Exception as e:
- logger.error("Error while sending email %s"%str(e))
- return False
- def sendContiniousReportMail(report_id, user_id, fbid, fbname, email, totalImageAlert, totalImageCount, config, mailFlag, uuid):
- if mailFlag == False:
- return True
- logger = logging.getLogger("repnuplogger")
- logger.info("Sending detail report to user %s",user_id)
- host_name = config.get('smtp_settings','host')
- user_name = config.get('smtp_settings','username')
- password = config.get('smtp_settings','password')
- mail_template_path = config.get('smtp_settings','mail_template_path')
- siteurl = config.get('admin_settings','site_url')
- sender = config.get('smtp_settings','sender')
- cc_address = config.get('admin_settings','cc_email')
- uuid = str(uuid)
- #email = 'marcomtl@gmail.com'
- if totalImageCount < totalImageAlert:
- totalImageCount = totalImageAlert
- try:
- fo = open(os.path.join(mail_template_path,'detailed_report.html'))
- filecontent = fo.read()
- fo.close()
- messagebody = filecontent.replace("site_url",siteurl)
- fbuser_name = fbname.encode('utf-8')
- messagebody = messagebody.replace("app_user_name",fbuser_name)
- messagebody = messagebody.replace("image_alert_count",str(totalImageAlert))
- messagebody = messagebody.replace("total_image_count",str(totalImageCount))
- messagebody = messagebody.replace("user_uuid",uuid)
- msgRoot = MIMEMultipart('related')
- msgRoot['Subject'] = "Your social media detailed report from RepNup"
- msgRoot['From'] = "RepNup <reports@repnup.com>"
- msgRoot['To'] = email
- msgRoot['Bcc'] = cc_address
- msgRoot.preamble = 'This is a multi-part message in MIME format.'
- s = smtplib.SMTP(host_name)
- s.set_debuglevel(0)
- s.ehlo()
- if s.has_extn('STARTTLS'):
- s.starttls()
- s.ehlo()
- s.login(user_name,password)
- html_body = MIMEText(messagebody,'html')
- msg= MIMEMultipart('alternative')
- msgRoot.attach(msg)
- msg.attach(html_body)
- attachment = os.path.join(mail_template_path,'logo.jpg')
- fp = open(attachment,'rb')
- img = MIMEImage(fp.read())
- fp.close()
- img.add_header('Content-ID',"<logo-image>")
- img.add_header('Content-Disposition', 'inline', filename='logo.jpg')
- attachment2 = os.path.join(mail_template_path,'top-left-white-corner.gif')
- fp1 = open(attachment2,'rb')
- topleftwhiteimg = MIMEImage(fp1.read())
- fp1.close()
- topleftwhiteimg.add_header('Content-ID',"<top-left-white-image>")
- topleftwhiteimg.add_header('Content-Disposition', 'inline', filename='top-left-white-corner.gif')
- attachment3 = os.path.join(mail_template_path,'top-right-white-corner.gif')
- fp2 = open(attachment3,'rb')
- toprightwhiteimg = MIMEImage(fp2.read())
- fp2.close()
- toprightwhiteimg.add_header('Content-ID',"<top-right-white-image>")
- toprightwhiteimg.add_header('Content-Disposition', 'inline', filename='top-right-white-corner.gif')
- attachment4 = os.path.join(mail_template_path,'top-left-blue-corner.gif')
- fp3 = open(attachment4,'rb')
- topleftblueimg = MIMEImage(fp3.read())
- fp3.close()
- topleftblueimg.add_header('Content-ID',"<top-left-blue-image>")
- topleftblueimg.add_header('Content-Disposition', 'inline', filename='top-left-blue-corner.gif')
- attachment5 = os.path.join(mail_template_path,'top-right-blue-corner.gif')
- fp4 = open(attachment5,'rb')
- toprightblueimg = MIMEImage(fp4.read())
- fp4.close()
- toprightblueimg.add_header('Content-ID',"<top-right-blue-image>")
- toprightblueimg.add_header('Content-Disposition', 'inline', filename='top-right-blue-corner.gif')
- attachment6 = os.path.join(mail_template_path,'report_ready.jpg')
- fp5 = open(attachment6,'rb')
- reportimg = MIMEImage(fp5.read())
- fp5.close()
- reportimg.add_header('Content-ID',"<report-ready-image>")
- reportimg.add_header('Content-Disposition', 'inline', filename='report_ready.jpg')
- attachment7 = os.path.join(mail_template_path,'bottom-left-blue-corner.gif')
- fp6 = open(attachment7,'rb')
- bottomleftblueimg = MIMEImage(fp6.read())
- fp6.close()
- bottomleftblueimg.add_header('Content-ID',"<bottom-left-blue-image>")
- bottomleftblueimg.add_header('Content-Disposition', 'inline', filename='bottom-left-blue-corner.gif')
- attachment8 = os.path.join(mail_template_path,'bottom-right-blue-corner.gif')
- fp7 = open(attachment8,'rb')
- bottomrightblueimg = MIMEImage(fp7.read())
- fp7.close()
- bottomrightblueimg.add_header('Content-ID',"<bottom-right-blue-image>")
- bottomrightblueimg.add_header('Content-Disposition', 'inline', filename='bottom-right-blue-corner.gif')
- attachment9 = os.path.join(mail_template_path,'bottom-left-brown-corner.gif')
- fp8 = open(attachment9,'rb')
- bottomleftbrownimg = MIMEImage(fp8.read())
- fp8.close()
- bottomleftbrownimg.add_header('Content-ID',"<bottom-left-brown-image>")
- bottomleftbrownimg.add_header('Content-Disposition', 'inline', filename='bottom-left-brown-corner.gif')
- attachment10 = os.path.join(mail_template_path,'bottom-right-brown-corner.gif')
- fp9 = open(attachment10,'rb')
- bottomrightbrownimg = MIMEImage(fp9.read())
- fp9.close()
- bottomrightbrownimg.add_header('Content-ID',"<bottom-right-brown-image>")
- bottomrightbrownimg.add_header('Content-Disposition', 'inline', filename='bottom-right-brown-corner.gif')
- attachment11 = os.path.join(mail_template_path,'fb.jpg')
- fp10 = open(attachment11,'rb')
- fbimg = MIMEImage(fp10.read())
- fp10.close()
- fbimg.add_header('Content-ID',"<fb-image>")
- fbimg.add_header('Content-Disposition', 'inline', filename='fb.jpg')
- attachment12 = os.path.join(mail_template_path,'tw.jpg')
- fp11 = open(attachment12,'rb')
- twimg = MIMEImage(fp11.read())
- fp11.close()
- twimg.add_header('Content-ID',"<tw-image>")
- twimg.add_header('Content-Disposition', 'inline', filename='tw.jpg')
- attachment13 = os.path.join(mail_template_path,'lnk.jpg')
- fp12 = open(attachment13,'rb')
- lknimg = MIMEImage(fp12.read())
- fp12.close()
- lknimg.add_header('Content-ID',"<link-image>")
- lknimg.add_header('Content-Disposition', 'inline', filename='lnk.jpg')
- msgRoot.attach(img)
- msgRoot.attach(topleftwhiteimg)
- msgRoot.attach(toprightwhiteimg)
- msgRoot.attach(topleftblueimg)
- msgRoot.attach(toprightblueimg)
- msgRoot.attach(reportimg)
- msgRoot.attach(bottomleftblueimg)
- msgRoot.attach(bottomrightblueimg)
- msgRoot.attach(bottomleftbrownimg)
- msgRoot.attach(bottomrightbrownimg)
- msgRoot.attach(fbimg)
- msgRoot.attach(twimg)
- msgRoot.attach(lknimg)
- TOADDR = [msgRoot['To']]
- CCADDR = [msgRoot['Bcc']]
- s.sendmail(sender,TOADDR+CCADDR,msgRoot.as_string())
- s.quit()
- logger.info("Successfully send detail report mail to user %s"%str(user_id))
- return True
- except Exception as e:
- logger.error("Error while sending email %s"%str(e))
- return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement