def post(self): if(Company.exists(request.form['name'])): return jsonify(message='Company exists') else: company = Company() company.name = request.form['name'] company.tin = request.form['tin'] company.address = request.form['address'] db.session.add(company) db.session.commit() return jsonify(company.serialize)
def post(self): company = Company() try: name = self.request.get('name') company.name = name except: pass try: address = self.request.get('address') company.address = address except: pass try: city = self.request.get('city') company.city = city except: pass try: country = self.request.get('country') company.country = country except: pass try: email = self.request.get('email') company.email = email except: pass try: phone_number = int(self.request.get('phone_number')) company.phone_number = phone_number except: pass company.put() company_id = company.key().id() self.redirect("company/" + str(company_id))
def getCompanyInfo(dom): '''获取一个公司的信息''' info_items = dom('.companyInfoItems') info_trs = info_items('.companyInfoTab tr') company_info = {} for tr in info_trs: tr = pq(tr) k = tr('td:eq(0)').text().split(u':')[0] v = tr('td:eq(1)').text() company_info[k] = v scale = company_info.get(u'公司规模') if scale: sh = re.search(r'(\d+)-(\d+)', scale) scale = sh.groups() if sh else (None, None) else: scale = (None, None) #### jcs = dom('.jobContact>div>div').find('div') # Job Contact for jc in jcs: jc = pq(jc) jctext = jc.text().split(u':') if len(jctext) == 2: k, v = jctext company_info[k] = v com = Company() com.name = info_items('.companyTitle').text() com.industry = company_info.get(u'公司行业') com.type = company_info.get(u'公司类型') com.address = company_info.get(u'公司地址') com.website = company_info.get(u'公司主页') com.scale_low, com.scale_high = scale com.email = None com.phone_num = None com.description = dom('.black12 tr:eq(2)').find('td').html() com.etag = '' return com
def read_job_from_html(skill, html_file): """ read job info from downloaded html file :param html_file: contains job info, but sometime the contents are empty. """ html = read_all(html_file) soup = make_soup(html) detail = soup.find('dl', 'job_detail') # in some rare cases, e.g. the job is closed already, then the job info is missing. if not detail: return None job = Job() job.job_id = int(soup.find('input', {'id': 'jobid'})['value']) job.skill_tag = skill log('*** JOB ***') title = detail.find('h1') log(title['title']) log(title.div.text) job.title = title['title'] job.dept = title.div.text log('') request = detail.find('dd', 'job_request') main_features = [] for s in request.stripped_strings: f = s.strip().lstrip(u'职位诱惑 : ').lstrip(u'发布时间:').rstrip(u'发布') log(f) main_features.append(f) assert len(main_features) == 7 job.salary = main_features[0] job.city = main_features[1] job.experience = main_features[2] job.education = main_features[3] job.full_time = main_features[4] == u'全职' job.benefits = main_features[5] job.published_date = get_published_date(main_features[6], created_on(html_file)) log('') desc_html = [] desc = detail.find('dd', 'job_bt').find_all('p') for bt in desc: desc_html.append(unicode(bt)) job.desc = ''.join(desc_html) log(job.desc) log('\n*** COMPANY ***\n') company = Company() comp = soup.find('dl', 'job_company') url = comp.dt.a['href'] pat = re.compile(r'(?P<comp_id>\d+)') m = re.search(pat, url) log(url) company.comp_id = int(m.group('comp_id')) job.comp_id = company.comp_id log(comp.dt.a.img['src']) log(comp.dt.a.div.h2.text.split()[0]) company.logo = comp.dt.a.img['src'] company.name = comp.dt.a.div.h2.text.split()[0] log('') comp_features = comp.dd features = [] for li in comp_features.ul.find_all('li'): for ls in li.stripped_strings: features.append(ls) log(''.join(features)) if len(features) == 6: company.domain = features[1] company.size = features[3] company.url = features[5] else: print(u'features ex: ' + html_file) log('') stage_h = comp_features.h4 stage_tags = stage_h.find_next_sibling('ul').find_all('li') stage = [] for li in stage_tags: for ls in li.stripped_strings: stage.append(ls) log('\t'.join(stage)) if len(stage) % 2 == 0: for i in xrange(0, len(stage), 2): if stage[i] == u'目前阶段': company.cur_stage = stage[i + 1] elif stage[i] == u'投资机构': company.investor = stage[i + 1] else: print(u'stages ex: ' + html_file) log('') # address if comp_features.div: log(comp_features.div.text) company.address = comp_features.div.text return job, company