def add_entity(self, data): """ adds entity """ e = Entity() fields = self.get_fields_quick(data) for k, v in fields.iteritems(): setattr(e, k, v) e.save() sys.stdout.write(e.name.encode("utf8") + " added\n") return e
def add_institution(self,data): ed = Entity() ed.name = data['inst_name'] # ed.li_uniq_id = data['inst_uniq_id'] ed.type = 'organization' ed.sub_type = 'ed-institution' ed.li_type = 'school' ed.save() return ed
def add_institution(self,data): ed = Entity() ed.name = data['inst_name'] ed.type = 'organization' ed.subtype = 'ed-institution' ed.li_type = 'school' # ed.li_uniq_id = data['inst_uniq_id'] ## this will always be None ## No it won't.... but we don't need it anyway ed.save() if self.logging: print 'Add Institution: (' + str(ed.id) + ') ' + ed.name return ed
def add_unverified_company(self, data): """ Special case in which no co_uniq_name found, so we can't hit the LI API. Tries to create a stub company. Return: Entity || None """ if data["entity_name"] is not None: co = Entity() co.name = data["entity_name"] co.type = "organization" co.status = "unverified" co.save() return co else: return None
def add_org(self, permalink, cb_type): if cb_type == "financial_org": cb_type = "financial-organization" cb_url = self.get_cb_url("info", cb_type, permalink=permalink) data = self.get_json(cb_url) # ensure data was returned if data: founded_date = self.construct_date(data["founded_year"], data["founded_month"], data["founded_day"]) org = Entity( name=data["name"], cb_permalink=data["permalink"], description=data["description"], web_url=data["homepage_url"], blog_url=data["blog_url"], twitter_handle=data["twitter_username"], founded_date=founded_date, ) org.save() return org
def add_company(self,id=None,name=None): # get company profile from LinkedIn if name is not None: data = self.fetch_co_li_profile(name=name) elif id is not None: data = self.fetch_co_li_profile(co_id=id) # if nothing returned from LI, return None if data is None: # TODO add company if name is not None: print "EDGE CASE: add_company, no data returned from LI: " + name if id is not None: print "EDGE CASE: add_company, no data returned from LI: " + str(id) return None # add to database co = Entity() co.name = data['name'] co.type = 'organization' ## V2 Edit -- make sure we get that id if 'id' in data: co.li_uniq_id = data['id'] if 'universalName' in data: co.li_univ_name = data['universalName'] if 'companyType' in data: # try to convert raw LI code to something more readble try: li_type = self.company_types[data['companyType']['code']] except: li_type = data['companyType']['code'] co.li_type = li_type if 'ticker' in data: co.ticker = data['ticker'] if 'websiteUrl' in data: co.web_url = data['websiteUrl'] # co.domain = data['industries'] # co.li_status = data['status'] if 'blog-url' in data: co.blog_url = data['blog-url'] if 'twitterId' in data: co.twitter_handle = data['twitterId'] if 'employeeCountRange' in data: co.size_range = data['employeeCountRange']['name'] if 'description' in data: co.description = data['description'] if 'stockExchange' in data: co.stock_exchange = data['stockExchange']['code'] co.li_last_scanned = datetime.now() co.save() # add industries # TODO add manager that handles this any time domain is added to co if 'industries' in data: for i in data['industries']['values']: # check to see if industry already exists industry = self.get_industry(i['name'],i['code']) if industry: # add industry to domain of company co.domains.add(industry) if self.logging: print '@addCompany(), found existing industry' else: # create new industry if self.logging: print "@ addCompany(), creating new industry: " + i['name'] + ' - ' + str(i['code']) industry = Industry() industry.name=i['name'] industry.li_code=int(i['code']) if industry.li_code in self.industry_groups: industry.li_group=self.industry_groups[industry.li_code] industry.save() # add to domain of company co.domains.add(industry) # check to see if company has a logo url if 'logoUrl' in data: # get company logo self.save_li_image(co,data['logoUrl']) # check to see if locations in company profile if 'locations' in data: # add offices if 'values' in data['locations']: for l in data['locations']['values']: self.add_office(co,l) if self.logging: print 'Add Company: (' + str(co.id) + ') ' + co.name + ' ' + str(co.li_uniq_id) return co
def add_institution(self, name): inst = Entity(type="school", name=name) inst.save() return inst
def add_to_profile(request): # check for form submission if request.POST: from accounts.forms import AddEducationForm, AddExperienceForm, AddGeographyForm, AddGoalForm, AddProfilePicForm from django.core.files import File import accounts.tasks as tasks if request.POST['type'] == "profile_pic": # bind form form = AddProfilePicForm(request.POST,request.FILES) # validate form if form.is_valid(): # create picture object img_filename = request.user.profile.std_name() + ".jpg" pic = Picture() pic.person = request.user.profile pic.source = 'user' pic.save() with open('tmp_img','wb') as f: f.write(request.FILES['pic'].read()) with open('tmp_img','r') as f: img_file = File(f) pic.pic.save(img_filename,img_file,True) os.remove('tmp_img') response = { 'result':'success', 'pic':pic.pic.url } else: response = { 'result':'failure', 'position':form.errors } return HttpResponse(json.dumps(response)) if request.POST['type'] == "education": # bind form form = AddEducationForm(request.POST) # validate form if form.is_valid(): try: school = Entity.objects.get(name=form.cleaned_data['school']) except MultipleObjectsReturned: school = Entity.objects.filter(name=form.cleaned_data['school'])[0] except ObjectDoesNotExist: school = Entity(name=form.cleaned_data['school']) school.save() ed = Position(type="education",entity=school,end_date=form.cleaned_data['end_date'],degree=form.cleaned_data['degree'],field=form.cleaned_data['field'],person=request.user) ed.save() # kick off task to process for career matches tasks.match_position(ed) position_data = { 'degree':ed.degree, 'pos_id':ed.id, 'field':ed.field, 'entity':ed.entity.name } response = { 'result':'success', 'position':position_data } else: response = { 'result':'failure', 'errors':form.errors } return HttpResponse(json.dumps(response)) if request.POST['type'] == "experience": # bind form form = AddExperienceForm(request.POST) # validate form if form.is_valid(): try: entity = Entity.objects.get(name=form.cleaned_data['entity']) except MultipleObjectsReturned: entity = Entity.objects.filter(name=form.cleaned_data['entity'])[0] except ObjectDoesNotExist: entity = Entity(name=form.cleaned_data['entity']) entity.save() pos = Position( type="professional", entity=entity, person=request.user, start_date=form.cleaned_data['start_date'], end_date=form.cleaned_data['end_date'], title=form.cleaned_data['title'] ) pos.save() # kick off task to process career matches tasks.match_position(pos) # return json response position_data = { 'title':pos.title, 'pos_id':pos.id, 'entity':pos.entity.name } response = { 'result':'success', 'position':position_data } else: response = { 'result':'failure', 'errors':form.errors } return HttpResponse(json.dumps(response)) if request.POST['type'] == "geography": # bind form form = AddGeographyForm(request.POST) # validate form if form.is_valid(): try: reg = Region.objects.get(name=form.cleaned_data['region']) except MultipleObjectsReturned: reg = Region.objects.filter(name=form.cleaned_data['region'])[0] reg.people.add(request.user) response = { 'result':'success', 'geo':reg.name } else: response = { 'result':'failure', 'errors':form.errors } return HttpResponse(json.dumps(response)) if request.POST['type'] == "goal": # bind form form = AddGoalForm(request.POST) # validate form if form.is_valid(): try: ideal = IdealPosition.objects.get(title=form.cleaned_data['goal']) except MultipleObjectsReturned: ideal = IdealPosition.objects.filter(title=form.cleaned_data['goal'])[0] g = GoalPosition(position=ideal,owner=request.user) g.save() response = { 'result':'success', 'goal':g.position.title } else: response = { 'result':'failure', 'errors':form.errors } return HttpResponse(json.dumps(response))
def add_company(self,id=None,name=None): # get company profile from LinkedIn if name is not None: data = self.get_co_li_profile(name=name) elif id is not None: data = self.get_co_li_profile(co_id=id) # if nothing returned from LI, return None if data is None: # TODO add company return None # add to database co = Entity() co.name = data['name'] co.type = 'organization' co.li_uniq_id = id # coValues = {'li_univ_name':'universalName','li_type':''} if 'universalName' in data: co.li_univ_name = data['universalName'] if 'companyType' in data: co.li_type = data['companyType']['code'] if 'ticker' in data: co.ticker = data['ticker'] if 'websiteUrl' in data: co.web_url = data['websiteUrl'] # co.domain = data['industries'] # co.li_status = data['status'] if 'blog-url' in data: co.blog_url = data['blog-url'] if 'twitterId' in data: co.twitter_handle = data['twitterId'] if 'employeeCountRange' in data: co.size_range = data['employeeCountRange']['name'] if 'description' in data: co.description = data['description'] if 'stockExchange' in data: co.stock_exchange = data['stockExchange']['code'] co.li_last_scanned = datetime.now() co.save() # add industries # TODO add manager that handles this any time domain is added to co if 'industries' in data: for i in data['industries']['values']: # check to see if industry already exists industry = self.get_industry(i['name'],i['code']) if industry: # add industry to domain of company co.domains.add(industry) else: # create new industry industry = Industry() industry.name=i['name'] industry.li_code=i['code'] industry.save() # add to domain of company co.domains.add(industry) # check to see if company has a logo url if 'logoUrl' in data: # get company logo self.save_li_image(co,data['logoUrl']) # check to see if locations in company profile if 'locations' in data: # add offices for l in data['locations']['values']: self.add_office(co,l) return co