del (monconn_jobs_local) del (mysql_conn) ######################################################################################################### ############----------------- Main Function ######################################################################################################### if __name__ == '__main__': ######################################################################################################### ############----------------- Try Except to avoid Failure of code ######################################################################################################### try: send_email([ '*****@*****.**', '*****@*****.**' ], "Revival Mailer Weekly", "Jobs Processing from SQL Started!!!") ######################################################################################################### ############----------------- Start the timer ######################################################################################################### print 'preProcessing Jobs...', time.ctime() start_time = time.time() htmls = HTMLStripper() ######################################################################################################### ############----------------- Loading the mapping for Bag of Words ######################################################################################################### print 'Loading the mappings for bow' synMappingFileName = '../Features/rawData/LSI/Model_UnifiedTKE/unifiedtkelist.csv' keywordIdMappingFileName = '../Features/rawData/LSI/Model_UnifiedTKE/unifiedtkelist_numbered.csv' #This file is created
monconn_recommendations.close() ######################################################################################################### ############----------------- Main Function ######################################################################################################### if __name__ == '__main__': ######################################################################################################### ############----------------- Try Except to avoid Failure of code ######################################################################################################### try: send_email([ '*****@*****.**', '*****@*****.**' ], "SJ Onsite", "Similar Jobs Onsite Creation started !! ") ######################################################################################################### ############----------------- Start the timer ######################################################################################################### start_time = time.time() print "Started at time", start_time, "seconds" ######################################################################################################### ############----------------- Remove the previous Mongo dump of Similar Jobs ######################################################################################################### tablename = 'JobSuggestions' monconn_recommendations = MongoConnect(tablename, host='localhost', database='similar_jobs_onsite')
monconn_recommendations.saveToTable(row) if __name__ == '__main__': ######################################################################################################### ############-----------------Try Except to provide alert in case of code failure ######################################################################################################### try: send_email(['*****@*****.**', '*****@*****.**'],"Job Alert Mailer","Candidate DB Updation Started!!") ######################################################################################################### ############----------------- Loading the mappings for bow ######################################################################################################### print "Loading Mapping for BOW" synMappingFileName = '/data/Projects/JobAlerts/Features/rawData/LSI/Model_UnifiedTKE/unifiedtkelist.csv' keywordIdMappingFileName = '/data/Projects/JobAlerts/Features/rawData/LSI/Model_UnifiedTKE/unifiedtkelist_numbered.csv' mb = MyBOW(synMappingFileName, keywordIdMappingFileName) ######################################################################################################### ############-----------------Creating the connection to candidates_processed_5 and dropping if already exist #########################################################################################################
MONGO_PORT = 27017 connection = Connection(MONGO_HOST, MONGO_PORT) #leave blank for local db #db=Database(connection,'JobAlerts') db = Database(connection, 'mailer_monthly') #db.authenticate('sumoplus','sumoplus') return db ######################################################################################################### ############-----------------Try Except to provide alert in case of code failure ######################################################################################################### try: send_email([ '*****@*****.**', '*****@*****.**' ], "Revival Monthly", "Candidates Processeing Started !!") date = datetime.datetime.now() print date startdate, enddate = getMonthlyLoginRangeFor(date) print startdate days_from = (date - startdate).days print enddate days_to = (date - enddate).days ######################################################################################################### ############-----------------Loading the mappings for Bag of Words ######################################################################################################### print 'Loading the mappings for bow' synMappingFileName = '../Features/rawData/LSI/Model_UnifiedTKE/unifiedtkelist.csv' keywordIdMappingFileName = '../Features/rawData/LSI/Model_UnifiedTKE/unifiedtkelist_numbered.csv' #This file is created
######################################################################################################### ############-----------------Main Function ######################################################################################################### if __name__ == '__main__': ######################################################################################################### ############-----------------Try Except to provide alert in case of code failure ######################################################################################################### try: send_email( [ '*****@*****.**', '*****@*****.**' ], "Applies Incremental - JAM", 'Incremental Applications Extraction started!!!\n Collection Name : candidate_applications \n DB Name : JobAlerts' ) ######################################################################################################### ############-----------------Finding the date 183 days before today's date ######################################################################################################### todayDate = date.today() previousDate = todayDate + relativedelta(days=-183) day1 = datetime.combine(previousDate, time(0, 0)) ######################################################################################################### ############-----------------Connection to the candidate_applications on Mongo(172.22.66.233) ######################################################################################################### print 'Connecting to Mongodb..'
MONGO_PORT = 27017 connection = Connection(MONGO_HOST, MONGO_PORT) #leave blank for local db #db=Database(connection,'JobAlerts') db = Database(connection, 'JobAlerts') #db.authenticate('sumoplus','sumoplus') return db ######################################################################################################### ############-----------------Try Except to provide alert in case of code failure ######################################################################################################### try: send_email( [ '*****@*****.**', '*****@*****.**' ], "Spam Bounce Removal - JAM", 'Spam Bounce Removal Started!!\nDB Name : candidates_processed_4') ######################################################################################################### ############-----------------Loading the mappings for Bag of Words ######################################################################################################### print 'Loading the mappings for bow' synMappingFileName = '../Features/rawData/LSI/Model_UnifiedTKE/unifiedtkelist.csv' keywordIdMappingFileName = '../Features/rawData/LSI/Model_UnifiedTKE/unifiedtkelist_numbered.csv' #This file is created mb = MyBOW(synMappingFileName, keywordIdMappingFileName) print 'Loading the mappings for bow...finished' ######################################################################################################### ############-----------------Creating Mongo Connection for candidates database #########################################################################################################
MONGO_HOST = 'localhost' MONGO_PORT = 27017 connection = Connection(MONGO_HOST, MONGO_PORT) #leave blank for local db #db=Database(connection,'JobAlerts') db = Database(connection, 'mailer_weekly') #db.authenticate('sumoplus','sumoplus') return db ######################################################################################################### ############-----------------Try Except to provide alert in case of code failure ######################################################################################################### try: send_email([ '*****@*****.**', '*****@*****.**' ], "Revival Mailer Weekly", 'Candidates Processing Started !!!') date = datetime.datetime.now() print date startdate, enddate = getWeeklyLoginRangeFor(date) print startdate days_from = (date - startdate).days print enddate days_to = (date - enddate).days ######################################################################################################### ############-----------------Loading the mappings for Bag of Words ######################################################################################################### print 'Loading the mappings for bow' synMappingFileName = '../Features/rawData/LSI/Model_UnifiedTKE/unifiedtkelist.csv'
from Features.LSI_common.MyBOW import MyBOW #Custom Module - /data/Projects/MidoutMailer/Features/LSI_common/MyBOW.py ################################################################################################################# ############----------------- Main Function ################################################################################################################# if __name__ == '__main__': ######################################################################################################### ############-----------------Try Except to provide alert in case of code failure ######################################################################################################### try: send_email([ '*****@*****.**', '*****@*****.**' ], "Midout Mailers", "Midouts Candidates Processing Started!!!!") print 'Mongo connect module:' username = '******' password = '******' ######################################################################################################### ############----------------- Dictionary for LookupExperience ######################################################################################################### print "Loading Dictionary for Experience" tableName = 'LookupExperience' monconn_users = MongoConnect(tableName, host='172.22.65.88', port=27018,
############----------------- Printing all the numbers obtained ######################################################################################################### print "jobs_processed_count", jobs_processed_count print "jobs_processed_tech_dump_count", jobs_processed_tech_dump_count print "candidates_count", candidates_count print "recommendations_count", recommendations_count ######################################################################################################### ############----------------- Alert Mailer in case any number in smaller than permissible limit ######################################################################################################### if jobs_processed_count > jobs_processed_tech_dump_count or jobs_processed_count < 3000: send_email( [ '*****@*****.**', '*****@*****.**', '*****@*****.**' ], "Urgent!!!", "Job Alert Mailer : Jobs Count is Less!!!!!\nCall Akash (+91-8527716555) or Kanika (+91-9560649296) asap." ) else: pass if recommendations_count < 2500000: send_email( [ '*****@*****.**', '*****@*****.**', '*****@*****.**' ], "Urgent!!!", "Job Alert Mailer : Recommendations Count is Less!!!!!\nCall Akash (+91-8527716555) or Kanika (+91-9560649296) asap." )
del (monconn_jobs_local) del (mysql_conn) ######################################################################################################### ############----------------- Main Function ######################################################################################################### if __name__ == '__main__': ######################################################################################################### ############----------------- Try Except to avoid Failure of code ######################################################################################################### try: send_email([ '*****@*****.**', '*****@*****.**' ], "SJ Onsite", "1 Months Jobs Processeing Started !!") ######################################################################################################### ############----------------- Start the timer ######################################################################################################### print 'preProcessing Jobs...', time.ctime() start_time = time.time() htmls = HTMLStripper() ######################################################################################################### ############----------------- Loading the mapping for Bag of Words ######################################################################################################### print 'Loading the mappings for bow' synMappingFileName = '../Features/rawData/LSI/Model_UnifiedTKE/unifiedtkelist.csv' keywordIdMappingFileName = '../Features/rawData/LSI/Model_UnifiedTKE/unifiedtkelist_numbered.csv' #This file is created
from collections import defaultdict from pprint import pprint from Utils.Utils_1 import cleanToken from bson.objectid import ObjectId from datetime import datetime, timedelta #Custom Modules from DataConnections.MongoConnect.MongoConnect import MongoConnect #Custom Module - /data/Projects/JobAlerts/DataConnections/MongoConnect/MongoConnect.py from Notifier.Notifier import send_email #Custom Module - /data/Projects/JobAlerts/Notifier/Notifier.py ######################################################################################################### ############-----------------Credentials for server ######################################################################################################### send_email( ['*****@*****.**', '*****@*****.**'], "Resume Dump Incremental - JAM", 'Resume Details Dump Incremental Started!!\n Collection Name : candidate_data \n DB Name : ResumeDump' ) username = '******' password = '******' tableName = 'ResumeParserDump' date1 = datetime.now() - timedelta(days=2) print "Date : ", datetime.now() ######################################################################################################### ############-----------------Try Except to provide alert in case of code failure ######################################################################################################### try: ######################################################################################################### ############-----------------Creating a mongo connection to miscellaneous DB #########################################################################################################
MONGO_HOST, MONGO_PORT) #######---------- Leave blank for local DB #db=Database(connection,'JobAlerts') db = Database(connection, 'JobAlerts') #db.authenticate('sumoplus','sumoplus') return db ######################################################################################################### ############-----------------Try Except to provide alert in case of code failure ######################################################################################################### try: send_email( [ '*****@*****.**', '*****@*****.**' ], "Users Incremental - JAM", 'Candidates Extraction from SOLR Started!!\n Collection Name : candidates_processed_4 \n DB Name : JobAlerts' ) ######################################################################################################### ############-----------------Loading the mappings for Bag of Words ######################################################################################################### print 'Loading the mappings for bow' synMappingFileName = '../Features/rawData/LSI/Model_UnifiedTKE/unifiedtkelist.csv' keywordIdMappingFileName = '../Features/rawData/LSI/Model_UnifiedTKE/unifiedtkelist_numbered.csv' #This file is created mb = MyBOW(synMappingFileName, keywordIdMappingFileName) print 'Loading the mappings for bow...finished' ######################################################################################################### ############-----------------Finding the date 183 days before today's date
del (monconn_jobs_local) del (mysql_conn) ######################################################################################################### ############----------------- Main Function ######################################################################################################### if __name__ == '__main__': ######################################################################################################### ############----------------- Try Except to avoid Failure of code ######################################################################################################### try: send_email([ '*****@*****.**', '*****@*****.**' ], "Midout Mailers", "Tech Dump Jobs Processeing Started !!") ######################################################################################################### ############----------------- Start the timer ######################################################################################################### print 'preProcessing Jobs...', time.ctime() start_time = time.time() htmls = HTMLStripper() ######################################################################################################### ############----------------- Loading the mapping for Bag of Words ######################################################################################################### print 'Loading the mappings for bow' synMappingFileName = '../Features/rawData/LSI/Model_UnifiedTKE/unifiedtkelist.csv' keywordIdMappingFileName = '../Features/rawData/LSI/Model_UnifiedTKE/unifiedtkelist_numbered.csv' #This file is created
############----------------- Main Function ######################################################################################################### if __name__ == '__main__': ######################################################################################################### ############----------------- Try Except to avoid Failure of code ######################################################################################################### try: ######################################################################################################### ############----------------- Start the timer ######################################################################################################### send_email([ '*****@*****.**', '*****@*****.**' ], "Revival Mailer Weekly", 'Recommendations generation Started!!!') start_time = time.time() print "Started at time", start_time, "seconds" ######################################################################################################### ############----------------- Drop the existing collection ######################################################################################################### tablename = 'WeeklyMsgQueue' monconn_recommendations = MongoConnect(tablename, host='localhost', database='mailer_weekly') monconn_recommendations.dropTable() monconn_recommendations.close() #########################################################################################################
def preProcessChunk(chunkID): ######################################################################################################### ############----------------- SQL Credentials ######################################################################################################### ''' host="172.22.65.157" user="******" password="******" database="SumoPlus" unix_socket="/tmp/mysql.sock" port = 3308 ''' host = "172.22.66.204" user = "******" password = "******" database = "SumoPlus" unix_socket = "/tmp/mysql.sock" port = 3306 ######################################################################################################### ############----------------- Creating the SQL Query ######################################################################################################### print "Loading Jobs From MySql...." mysql_conn = MySQLConnect(database, host, user, password, unix_socket, port) cmd1 = '''drop table if exists SumoPlus.XY''' cmd2 = '''create table SumoPlus.XY as SELECT company_account_id,SUM(final_sale_price)as price,enabled,MAX(expiry_date)as expiry_date from SumoPlus.backoffice_accountsales a1 where enabled in (select min(enabled) from SumoPlus.backoffice_accountsales where a1.company_account_id=company_account_id) group by 1 ''' cmd3 = '''ALTER TABLE SumoPlus.XY add index company_account_id (company_account_id)''' cmd4 = '''SELECT rj.jobid as Jobid, rj.jobtitle as JobTitle, rj.description as JD, rj.isbocreated as back_office_job, rj.publisheddate as publisheddate, rj.republisheddate as republisheddate, rj.companyid_id as Company_id, rj.displayname as Company_name, la1.text_value_MAX as SalaryMax, la2.text_value_MIN as SalaryMin, le1.display as ExpMin, le2.display as ExpMax, li.industry_desc as Industry, group_concat(c.AttValueCustom,'') as keySkills, group_concat(fn.field_enu,'') as function, group_concat(l.city_desc,'') as location, group_concat(fn.sub_field_enu,'') as subfunction, case account_type when 0 THEN "Company" when 1 THEN "Consultant" when 2 THEN "Others" when 3 THEN "Enterprise" ELSE "Not Specified" END AS account_type, IF(XY.enabled = 1 AND XY.price != 0 AND XY.expiry_date > CURDATE(),'Paid','Free') AS 'flag' from (select * from recruiter_job where recruiter_job.jobstatus in (3,9) and (DATEDIFF( CURDATE(),DATE(recruiter_job.publisheddate)) < 16 OR DATEDIFF( CURDATE(),DATE(recruiter_job.republisheddate)) < 16) ) AS rj left join lookup_annualsalary AS la1 on rj.salarymax = la1.salary_id left join lookup_annualsalary AS la2 on rj.salarymin = la2.salary_id left join lookup_experience AS le1 on rj.minexperience = le1.value left join lookup_experience AS le2 on rj.maxexperience = le2.value left join recruiter_jobattribute as c on rj.jobid = c.jobid_id left join lookup_industry AS li on rj.industry=li.industry_id left join lookup_subfunctionalarea_new163 AS fn on fn.sub_field_id = c.AttValue AND c.AttType = 12 left join lookup_city_new512 AS l on l.city_id = c.AttValue AND c.AttType = 13 left join SumoPlus.XY AS XY on XY.company_account_id = rj.companyid_id left join SumoPlus.backoffice_companyaccount AS F on F.id= rj.companyid_id WHERE c.AttType in (3,12,13) group by rj.jobid ''' cmd5 = '''drop table if exists SumoPlus.XY ''' ######################################################################################################### ############----------------- Executing the SQL Query ######################################################################################################### print 'chnukID:', chunkID, ': Loading jobs from SQL....', time.ctime() mysql_conn.query(cmd1) mysql_conn.query(cmd2) mysql_conn.query(cmd3) jobs = mysql_conn.query(cmd4) mysql_conn.query(cmd5) print 'chunkID:', chunkID, ': Loading jobs from SQL....completed..', time.ctime( ) print 'chunkid:', chunkID, ' : Number of jobs loaded: ', len(jobs) ######################################################################################################### ############-----------------Connecting to Jobs Collections Mongo (172.22.66.233) ######################################################################################################### print 'Connecting to Mongodb..' tableName = 'jobs_processed' monconn_jobs_local = MongoConnect(tableName, host='localhost', database='mailer_weekly') monconn_jobs_local_cur = monconn_jobs_local.getCursor() print 'Connecting to Mongodb...finished' ######################################################################################################### ############-----------------Processing the Jobs data extracted from SQL ######################################################################################################### i = 0 for job in jobs: if i % 1000 == 0: print '\tchunkID:', chunkID, ' numRecords:', i, ' completed in ', time.time( ) - start_time, ' seconds' job_id = job['Jobid'] job_title = cleanToken(job['JobTitle']) job_maxexp = cleanToken(job['ExpMax']) job_minexp = cleanToken(job['ExpMin']) job_maxsal = cleanToken(job['SalaryMax']) job_minsal = cleanToken(job['SalaryMin']) job_jd = cleanHTML(cleanToken(job['JD'])) job_industry = cleanToken(job['Industry']) job_location = removeDup(job['location']) job_subfunction = removeDup(cleanToken(job['subfunction'])) job_function = removeDup(cleanToken(job['function'])) job_skills = removeDup(cleanToken(job['keySkills'])) job_flag = job['flag'] job_accounttype = job['account_type'] job_company_id = job['Company_id'] job_company_name = cleanToken(job['Company_name']) job_published_date = job['publisheddate'] job_republished_date = job['republisheddate'] job_back_office = int(job['back_office_job']) job_location = job_location.replace(', ', ',').lower().split(',') if job_company_id == 421880: #######---------- Altimetrik Jobs removed continue ######################################################################################################### ############-----------------Creating Bag of Words for Text ######################################################################################################### text = 5 * (" " + job_title) + ' ' + 5 * ( " " + job_skills) + ' ' + 1 * (" " + job_jd) + ' ' + 2 * ( " " + job_industry) + ' ' + 2 * ( " " + job_function) + ' ' + 2 * (" " + job_subfunction) text = text.replace('candidates', ' ') job_bow = mb.getBow(text, getbowdict=0) ######################################################################################################### ############-----------------Creating Job document to be saved in Mongo ######################################################################################################### document = {'job_id': job_id, 'job_title': job_title,'job_function':job_function, \ 'job_maxexp': job_maxexp, 'job_minexp': job_minexp,\ 'job_location':job_location, 'job_subfunction':job_subfunction,\ 'job_maxsal':job_maxsal,'job_minsal':job_minsal, 'job_skills': job_skills, \ 'job_bow': job_bow, 'job_industry': job_industry, 'job_jd': job_jd, \ 'job_flag':job_flag,'job_accounttype':job_accounttype, \ 'job_company_id':job_company_id,'job_company_name':job_company_name, 'job_published':job_published_date,'job_republished':job_republished_date,'job_back_office':job_back_office } ######################################################################################################### ############-----------------Saving the document in Job collection Mongo (172.22.66.233) ######################################################################################################### monconn_jobs_local.saveToTable(document) i += 1 print "Processing finished....." print 'chunkID:', chunkID, ' Total time taken is: ', time.time( ) - start_time, ' seconds.' end_time = time.time() time_taken = end_time - start_time send_email([ '*****@*****.**', '*****@*****.**' ], "Revival Mailer Weekly", 'Jobs Processed ' + str(i) + ' in :' + str(end_time - start_time) + ' seconds') ######################################################################################################### ############-----------------Changing the status of completion and deleting the mongo connections ######################################################################################################### del (monconn_jobs_local) del (mysql_conn)
def preProcessChunk(chunkID): ######################################################################################################### ############----------------- SQL Credentials ######################################################################################################### ''' host="172.22.65.157" user="******" password="******" database="SumoPlus" unix_socket="/tmp/mysql.sock" port = 3308 ''' host = "172.22.66.204" user = "******" password = "******" database = "SumoPlus" unix_socket = "/tmp/mysql.sock" port = 3306 ######################################################################################################### ############----------------- Creating the SQL Query ######################################################################################################### print "Loading Jobs From MySql...." mysql_conn = MySQLConnect(database, host, user, password, unix_socket, port) cmd1 = '''drop table if exists SumoPlus.XY''' cmd2 = '''create table SumoPlus.XY as SELECT company_account_id,SUM(final_sale_price)as price,enabled,MAX(expiry_date)as expiry_date from SumoPlus.backoffice_accountsales a1 where enabled in (select min(enabled) from SumoPlus.backoffice_accountsales where a1.company_account_id=company_account_id) group by 1 ''' cmd3 = '''ALTER TABLE SumoPlus.XY add index company_account_id (company_account_id)''' cmd4 = '''SELECT rj.jobid as Jobid, rj.jobtitle as JobTitle, rj.description as JD, rj.companyid_id as Company_id, rj.publisheddate as publisheddate, rj.displayname as Company_name, la1.text_value_MAX as SalaryMax, la2.text_value_MIN as SalaryMin, le1.display as ExpMin, le2.display as ExpMax, li.industry_desc as Industry, group_concat(c.AttValueCustom,'') as keySkills, group_concat(fn.field_enu,'') as function, group_concat(l.city_desc,'') as location, group_concat(fn.sub_field_enu,'') as subfunction, case account_type when 0 THEN "Company" when 1 THEN "Consultant" when 2 THEN "Others" when 3 THEN "Enterprise" ELSE "Not Specified" END AS account_type, IF(XY.enabled = 1 AND XY.price != 0 AND XY.expiry_date > CURDATE(),'Paid','Free') AS 'flag' from (select * from recruiter_job where recruiter_job.jobstatus in (3,9) and (DATEDIFF( CURDATE(),DATE(recruiter_job.publisheddate)) < 20 OR DATEDIFF( CURDATE(),DATE(recruiter_job.republisheddate)) < 20) ) AS rj left join lookup_annualsalary AS la1 on rj.salarymax = la1.salary_id left join lookup_annualsalary AS la2 on rj.salarymin = la2.salary_id left join lookup_experience AS le1 on rj.minexperience = le1.value left join lookup_experience AS le2 on rj.maxexperience = le2.value left join recruiter_jobattribute as c on rj.jobid = c.jobid_id left join lookup_industry AS li on rj.industry=li.industry_id left join lookup_subfunctionalarea_new163 AS fn on fn.sub_field_id = c.AttValue AND c.AttType = 12 left join lookup_city_new512 AS l on l.city_id = c.AttValue AND c.AttType = 13 left join SumoPlus.XY AS XY on XY.company_account_id = rj.companyid_id left join SumoPlus.backoffice_companyaccount AS F on F.id= rj.companyid_id WHERE c.AttType in (3,12,13) group by rj.jobid ''' cmd5 = '''drop table if exists SumoPlus.XY ''' ######################################################################################################### ############----------------- Executing the SQL Query ######################################################################################################### print 'chnukID:', chunkID, ': Loading jobs from SQL....', time.ctime() mysql_conn.query(cmd1) mysql_conn.query(cmd2) mysql_conn.query(cmd3) jobs = mysql_conn.query(cmd4) mysql_conn.query(cmd5) print 'chunkID:', chunkID, ': Loading jobs from SQL....completed..', time.ctime( ) print 'chunkid:', chunkID, ' : Number of jobs loaded: ', len(jobs) ######################################################################################################### ############----------------- Connecting to Jobs Tech Dump Collections Mongo (172.22.66.233) ######################################################################################################### print 'Connecting to Mongodb..' tableName = 'JobDesc_weekly' monconn_jobs_local = MongoConnect(tableName, host='localhost', database='JobDescDB') monconn_jobs_local_cur = monconn_jobs_local.getCursor() print 'Connecting to Mongodb...finished' ######################################################################################################### ############-----------------Processing the Jobs data extracted from SQL ######################################################################################################### i = 0 for job in jobs: if i % 1000 == 0: print '\tchunkID:', chunkID, ' numRecords:', i, ' completed in ', time.time( ) - start_time, ' seconds' _id = job['Jobid'] comp_name = cleanToken_1(job.get('Company_name', None)) loc = (removeDup(job.get('location', None))).replace(', ', ',').split(',') min_exp = job.get('ExpMin', None) title = cleanToken_1(job.get('JobTitle', None)) max_exp = job.get('ExpMax', None) pub_date = job.get('publisheddate', None) id = job['Jobid'] job_flag = job.get('flag') p = 0 if job_flag == "Paid": p = 1 else: p = 0 desc = None ######################################################################################################### ############-----------------Creating Job document to be saved in Mongo ######################################################################################################### document = { '_id': _id, 'comp_name': comp_name, 'loc': loc, 'min_exp': min_exp, 'title': title, 'max_exp': max_exp, 'pub_date': pub_date, 'id': id, 'p': p, 'desc': desc } ######################################################################################################### ############-----------------Saving the document in Job collection Mongo (172.22.66.233) ######################################################################################################### monconn_jobs_local.saveToTable(document) i += 1 print "Processing finished....." print 'chunkID:', chunkID, ' Total time taken is: ', time.time( ) - start_time, ' seconds.' end_time = time.time() time_taken = end_time - start_time send_email([ '*****@*****.**', '*****@*****.**' ], "Revival Mailer Weekly", 'TEch Dump Jobs Processed ' + str(i) + ' in :' + str(end_time - start_time) + ' seconds') ######################################################################################################### ############-----------------Deleting the mongo connections ######################################################################################################### del (monconn_jobs_local) del (mysql_conn)
monconn_recommendations.close() ######################################################################################################### ############----------------- Main Function ######################################################################################################### if __name__ == '__main__': ######################################################################################################### ############----------------- Try Except to avoid Failure of code ######################################################################################################### try: send_email([ '*****@*****.**', '*****@*****.**' ], "Revival Monthly", "Recommendation Generation Started !!") ######################################################################################################### ############----------------- Start the timer ######################################################################################################### start_time = time.time() print "Started at time", start_time, "seconds" ######################################################################################################### ############----------------- Drop the existing collection ######################################################################################################### tablename = 'MonthlyMsgQueue' monconn_recommendations = MongoConnect(tablename, host='localhost', database='mailer_monthly')
def preProcessChunk(chunkID): ######################################################################################################### ############----------------- SQL Credentials ######################################################################################################### #Connect to SQL table and get the jobs data #host="172.16.66.64" #user="******" #password="******" ''' host="172.22.65.157" user="******" password="******" database="SumoPlus" unix_socket="/tmp/mysql.sock" port = 3308 ''' host="172.22.66.204" user="******" password="******" database="SumoPlus" unix_socket="/tmp/mysql.sock" port = 3306 ######################################################################################################### ############----------------- Creating the SQL Query ######################################################################################################### print "Loading Jobs From MySql...." mysql_conn = MySQLConnect(database, host, user, password, unix_socket, port) #cmd = '''SELECT rj.jobid as Jobid,rj.jobtitle as JobTitle,rj.description as JD,la1.text_value_MAX as SalaryMax,la2.text_value_MIN as SalaryMin,le1.display as ExpMin,le2.display as ExpMax,li.industry_desc as Industry,c.AttValueCustom as keySkills,l.city_desc as location,fn.field_enu as function,fn.sub_field_enu as subfunction from recruiter_job AS rj left join lookup_annualsalary AS la1 on rj.salarymax = la1.salary_id left join lookup_annualsalary AS la2 on rj.salarymin = la2.salary_id left join lookup_experience AS le1 on rj.minexperience = le1.value left join lookup_experience AS le2 on rj.maxexperience = le2.value left join recruiter_jobattribute as c on rj.jobid = c.jobid_id left join lookup_industry AS li on rj.industry=li.industry_id left join lookup_subfunctionalarea_new163 AS fn on fn.sub_field_id = c.AttValue AND c.AttType = 12 left join lookup_city_new512 AS l on l.city_id = c.AttValue AND c.AttType = 13 WHERE rj.jobstatus in (3,5,6,9) and c.AttType in (3,12,13) and (DATEDIFF( CURDATE(),DATE(rj.publisheddate)) < 4 OR DATEDIFF( CURDATE(),DATE(rj.republisheddate)) < 4) and rj.jobid%''' + str(numChunks) + '=' + str(chunkID) #cmd = '''SELECT rj.jobid as Jobid,rj.jobtitle as JobTitle,rj.description as JD,la1.text_value_MAX as SalaryMax,la2.text_value_MIN as SalaryMin,le1.display as ExpMin,le2.display as ExpMax,li.industry_desc as Industry,c.AttValueCustom as keySkills,l.city_desc as location,fn.field_enu as function,fn.sub_field_enu as subfunction from recruiter_job AS rj left join lookup_annualsalary AS la1 on rj.salarymax = la1.salary_id left join lookup_annualsalary AS la2 on rj.salarymin = la2.salary_id left join lookup_experience AS le1 on rj.minexperience = le1.value left join lookup_experience AS le2 on rj.maxexperience = le2.value left join recruiter_jobattribute as c on rj.jobid = c.jobid_id left join lookup_industry AS li on rj.industry=li.industry_id left join lookup_subfunctionalarea_new163 AS fn on fn.sub_field_id = c.AttValue AND c.AttType = 12 left join lookup_city_new512 AS l on l.city_id = c.AttValue AND c.AttType = 13 WHERE rj.jobstatus in (3,5,6,9) and c.AttType in (3,12,13) and (DATEDIFF( CURDATE(),DATE(rj.publisheddate)) < 4 OR DATEDIFF( CURDATE(),DATE(rj.republisheddate)) < 4)''' #print cmd cmd='''SELECT rj.jobid as Jobid, rj.jobtitle as JobTitle, rj.description as JD, la1.text_value_MAX as SalaryMax, la2.text_value_MIN as SalaryMin, le1.display as ExpMin, le2.display as ExpMax, li.industry_desc as Industry, group_concat(c.AttValueCustom,'') as keySkills, group_concat(fn.field_enu,'') as function, group_concat(l.city_desc,'') as location, group_concat(fn.sub_field_enu,'') as subfunction from (select * from recruiter_job where recruiter_job.jobstatus in (3,9) and (DATEDIFF( CURDATE(),DATE(recruiter_job.publisheddate)) < 8 OR DATEDIFF( CURDATE(),DATE(recruiter_job.republisheddate)) < 8) ) AS rj left join lookup_annualsalary AS la1 on rj.salarymax = la1.salary_id left join lookup_annualsalary AS la2 on rj.salarymin = la2.salary_id left join lookup_experience AS le1 on rj.minexperience = le1.value left join lookup_experience AS le2 on rj.maxexperience = le2.value left join recruiter_jobattribute as c on rj.jobid = c.jobid_id left join lookup_industry AS li on rj.industry=li.industry_id left join lookup_subfunctionalarea_new163 AS fn on fn.sub_field_id = c.AttValue AND c.AttType = 12 left join lookup_city_new512 AS l on l.city_id = c.AttValue AND c.AttType = 13 WHERE c.AttType in (3,12,13) group by rj.jobid ''' ######################################################################################################### ############----------------- Executing the SQL Query ######################################################################################################### print 'chnukID:', chunkID, ': Loading jobs from SQL....', time.ctime() jobs = mysql_conn.query(cmd) print 'chunkID:', chunkID,': Loading jobs from SQL....completed..', time.ctime() print 'chunkid:', chunkID, ' : Number of jobs loaded: ', len(jobs) ######################################################################################################### ############-----------------Connecting to Jobs Collections Mongo (172.22.66.233) ######################################################################################################### print 'Connecting to Mongodb..' tableName = 'jobs_processed_midout' monconn_jobs_local = MongoConnect(tableName , host = 'localhost', database = 'Midout_Mailers') monconn_jobs_local_cur = monconn_jobs_local.getCursor() print 'Connecting to Mongodb...finished' ######################################################################################################### ############-----------------Processing the Jobs data extracted from SQL ######################################################################################################### i = 0 for job in jobs: #pprint(job) #print i if i%1000 == 0: print '\tchunkID:', chunkID, ' numRecords:' , i, ' completed in ', time.time() - start_time, ' seconds' job_id = job['Jobid'] job_title = cleanToken(job['JobTitle']) job_maxexp = cleanToken(job['ExpMax']) job_minexp = cleanToken(job['ExpMin']) job_maxsal = cleanToken(job['SalaryMax']) job_minsal = cleanToken(job['SalaryMin']) job_jd = cleanHTML(cleanToken(job['JD']) ) job_industry = cleanToken(job['Industry']) job_location=removeDup(job['location']) job_subfunction=removeDup(job['subfunction']) job_function=removeDup(job['function']) job_skills=removeDup(cleanToken(job['keySkills'])) ######################################################################################################### ############-----------------Creating Bag of Words for Text ######################################################################################################### text = 5*(" "+job_title) + ' ' + 5*(" "+job_skills) + ' ' + 1*(" "+job_jd) +' '+2*(" "+job_industry)+' '+2*(" "+job_function)+' '+2*(" "+job_subfunction) text = text.replace('candidates', ' ') job_bow = mb.getBow(text, getbowdict = 0) ######################################################################################################### ############-----------------Creating Job document to be saved in Mongo ######################################################################################################### document = {'job_id': job_id, 'job_title': job_title,'job_function':job_function, \ 'job_maxexp': job_maxexp, 'job_minexp': job_minexp,\ 'job_location':job_location, 'job_subfunction':job_subfunction,\ 'job_maxsal':job_maxsal,'job_minsal':job_minsal, 'job_skills': job_skills, \ 'job_bow': job_bow, 'job_industry': job_industry, 'job_jd': job_jd } ######################################################################################################### ############-----------------Saving the document in Job collection Mongo (172.22.66.233) ######################################################################################################### monconn_jobs_local.saveToTable(document) i += 1 print "Processing finished....." print 'chunkID:', chunkID, ' Total time taken is: ', time.time() - start_time, ' seconds.' end_time = time.time() time_taken = end_time - start_time send_email(['*****@*****.**', '*****@*****.**'],"Midout Mailers",'Jobs Processed '+str(i)+' in :' + str(end_time - start_time) + ' seconds') #os.system(' echo "Jobs Processed '+str(i)+' in :' + str(end_time - start_time) + ' seconds' +' " | mutt -s "Midout Mailers" [email protected] ,[email protected]') del(monconn_jobs_local) del(mysql_conn)