Ejemplo n.º 1
0
 def _update_company_email_pattern(self, data):
     if not data: return 0
     qry = {'where':json.dumps({'domain': data['domain']})}
     companies = Parse().get('Company', qry).json()
     while "error" in companies.keys():
         time.sleep(3)
         companies = Parse().get('Company', qry).json()
     companies = companies['results']
     pattern = {'email_pattern': data['company_email_pattern']}
     if data['company_email_pattern'] == []: 
         pattern['email_guess'] = []
     #_pusher['customero'].trigger(data["domain"], pattern)
     for company in companies:
         #print data
         data = {'email_pattern':data['company_email_pattern'], 
                 'email_pattern_research': arrow.utcnow().timestamp}
         r = Parse().update('Company/'+company['objectId'], data)
         # pusher -->
         print r.json()
         try:
           ''' print data["domain"] '''
         except:
           ''' print "wtf error ", data '''
Ejemplo n.º 2
0
    def _update_company_info(self, data, api_key="", name=""):
        print "DATA"
        print data 
        company_name = self.remove_accents(data['company_name'])
        qry = {'where':json.dumps({'company_name':data['company_name']})}
        qry_1 ={'where':json.dumps({'company_name': company_name})}
        qry = {"where":json.dumps({"$or":[{"company_name":data["company_name"], "company_name": company_name}]})}
        company = Parse().get('Company', qry).json()
        while "results" not in company.keys():
            time.sleep(0.5)
            company = Parse().get('Company', qry).json()

        companies = company['results']
        data = self._unparsify_data(data)

        if companies == []:
            company = Parse().create('Company', data).json()
            while "objectId" not in company.keys():
                time.sleep(0.5)
                company = Parse().create('Company', data).json()
                print "retrying", company
            print company
            companies = [Parse()._pointer('Company',company['objectId'])]

        print data["company_name"]
        company_name = data["company_name"].replace(' ','-')
        #_pusher['customero'].trigger(company_name, {'company': data})

        print "__STARTED", len(companies)
        for company in companies:
            print "UPDATING COMPANY"
            #TODO batch_df update
            print Parse().update('Company/'+company['objectId'], data).json()
            _company = Parse()._pointer('Company', company['objectId'])
            classes = ['Prospect','CompanyProspect','PeopleSignal','CompanySignal']
            objects = []
            for _class in classes:
                df = pd.DataFrame()
                objects = Parse().get(_class, qry).json()['results']
                data = {'company':_company, 
                        'company_research': arrow.utcnow().timestamp}
                df["objectId"] = [i["objectId"] for i in objects]
                Parse()._batch_df_update(_class, df, data)

            #TODO - batch update
            for obj in objects:
                print "UPDATED", _class, obj
                _id = obj['objectId']
                print Parse().update(_class+"/"+_id, data).json()
                #TODO - add name email guess - what is this code below
                name = ""
                if _class == 'Prospect':
                    print company
                    domain = company["domain"]
                    #q.enqueue(EmailGuess().search_sources, domain, "", api_key)

        return "updated"

        # TODO BATCHIFY
        print "CREATING COMPANY"
        company = Parse().create('Company', data).json()
        _company = Parse()._pointer('Company', company['objectId'])
        classes = ['Prospect','CompanyProspect','PeopleSignal','CompanySignal']
        for _class in classes:
            objects = Parse().get(_class, qry).json()['results']
            for obj in objects:
                print "UPDATED", _class, obj
                _id = obj['objectId']
                print Parse().update(_class+"/"+_id, {'company':_company}).json()
                p['customero'].trigger(data["company_name"], {'company': data})