コード例 #1
0
ファイル: views.py プロジェクト: blaise1003/LinkedInLayer
def linkedin_auth_cont(request):
    """ LinkedIn auth process """

    logger.info("Linkedin Contact View")
    error_url = urlresolvers.reverse('error')
    if request.GET:
        logger.info("----------------------------------")
        logger.info("GET")
        oauth_verifier = request.GET.get('oauth_verifier', '')
        logger.info("Linkedin Verifier code : %s" % oauth_verifier)
        access_token = linkedin_api.access_token(oauth_verifier)
        if access_token == True:
            import pdb;pdb.set_trace()
            linkedin_item = linkedin_api.get_search({ 'keywords': "{abstract}"})
            contacts = []
            try:
                openerp_api = OpenErpAPI(
                    openerp_info['HOST'],
                    openerp_info['PORT'],
                    openerp_info['DBNAME'],
                    openerp_info['USER'],
                    openerp_info['PASSWORD'])
                contacts = openerp_api.search_contacts()
            except Exception, e:
                logger.error("ERROR on OpenErp : %s" % e)
                return HttpResponseRedirect(error_url)

            logger.info(contacts.__repr__())
            # Search employess on Linkedin
            for empl in contacts:
                logger.info(empl.__repr__())
                if empl['last_name'] and empl['first_name'] and empl['partner_id']:
                    linkedin_item = linkedin_api.get_search({ 'name': empl['first_name'].replace(' ', '+') +'+'+ empl['last_name'].replace(' ', '+'), 'company': empl['partner_id'][1]})
                    linkedin_extra_info = []
                    for item in linkedin_item:
                        linkedin_extra_info.append(linkedin_api.get_profile(member_id=item.id, fields=FIELDS))
                    if len(linkedin_item) == 0:
                        logger.warning("No Profile found on Linkedin for : %s %s" % (empl['first_name'], empl['last_name']))
                    elif len(linkedin_item) > 1:
                        logger.warning("Too many profiles found on Linkedin for : %s %s" % (empl['first_name'], empl['last_name']))
                        i=0
                        for item in linkedin_item:
                            # openerp_api.update_backlog(empl, item, linkedin_extra_info[i], 'res.partner.contact')
                            logger.info("Update Linkedin info on OpenErp for : %s %s" % (empl['first_name'], empl['last_name']))
                            create_update_contact(item, linkedin_extra_info[i])
                            i=i+1
                    else:
                        logger.info("Update Linkedin info on OpenErp for : %s %s" % (empl['first_name'], empl['last_name']))
                        # openerp_api.update_profile(empl, linkedin_item[0], linkedin_extra_info[0], 'res.partner.contact')
                        create_update_contact(linkedin_item[0], linkedin_extra_info[0])
                else:
                    logger.warning("Not enough information")
        else:
            logger.error("ERROR")
            return HttpResponseRedirect(error_url)
コード例 #2
0
ファイル: views.py プロジェクト: blaise1003/LinkedInLayer
def linkedin_auth_empl(request):
    """ LinkedIn auth process """

    logger.info("Linkedin Contact View")
    error_url = urlresolvers.reverse('error')
    if request.GET:
        logger.info("----------------------------------")
        logger.info("GET")
        oauth_verifier = request.GET.get('oauth_verifier', '')
        logger.info("Linkedin Verifier code : %s" % oauth_verifier)
        access_token = linkedin_api.access_token(oauth_verifier)
        if access_token == True:
            employees = []
            try:
                openerp_api = OpenErpAPI(
                    openerp_info['HOST'],
                    openerp_info['PORT'],
                    openerp_info['DBNAME'],
                    openerp_info['USER'],
                    openerp_info['PASSWORD'])
                employees = openerp_api.search_employees()
            except Exception, e:
                logger.error("ERROR on OpenErp : %s" % e)
                return HttpResponseRedirect(error_url)

            logger.info(employees.__repr__())
            # Search employess on Linkedin
            for empl in employees:
                linkedin_item = linkedin_api.get_search({
                    'name': empl['name'].replace(' ', '+'),
                    'company': empl['company_id'][1]
                })
                linkedin_extra_info = []
                for item in linkedin_item:
                    linkedin_extra_info.append(linkedin_api.get_profile(
                                        member_id=item.id, fields=FIELDS))
                if len(linkedin_item) == 0:
                    logger.warning("No Profile found on Linkedin for : %s" % \
                                                            empl['name'])
                elif len(linkedin_item) > 1:
                    logger.warning("Too many profiles found on Linkedin for : %s" % empl['name'])
                    i=0
                    for item in linkedin_item:
                        openerp_api.update_backlog(empl, item, linkedin_extra_info[i], 'hr.employee')
                        i=i+1
                else:
                    logger.info("Update Linkedin info on OpenErp for : %s" % empl['name'])
                    # openerp_api.update_profile(empl, linkedin_item[0], linkedin_extra_info[0], 'hr.employee')
                    update_create_contact(empl, linkedin_item[0], linkedin_extra_info[0])
        else:
            logger.error("ERROR")
            return HttpResponseRedirect(error_url)