def post(self, company_detail): if not company_detail: return None DBSession = sessionmaker(bind=self.engine) session = DBSession() try: company = models.Company( company_detail['symbol'], company_detail['logo'], company_detail['exchange'], company_detail['name'], company_detail['cik'], company_detail['bloomberg'], company_detail['lei'], company_detail['sic'], company_detail['country'], company_detail['industry'], company_detail['sector'], company_detail['marketcap'], company_detail['employees'], company_detail['phone'], company_detail['ceo'], company_detail['url'], company_detail['description'], ) session.add(company) session.commit() except: session.rollback() finally: session.close()
def create_company(self, form): public_key, private_key = util.generrate_key() company = models.Company(companyName=form.companyName.data, privateKey=private_key, publicKey=public_key) company.set_password(form.password.data) self.session.add(company) return company
def add_company(): name = request.json['name'] domain = request.json['domain'] email = request.json['email'] phone = request.json['phone'] new_company = models.Company(name, domain, email, phone) db.session.add(new_company) db.session.commit() return schemas.company_Schema.jsonify(new_company)
def get_company(company_url): try: company = DB_MANAGER.open().query( mo.Company).filter(mo.Company.api_url == company_url).one() return company except: try: company_obj = get_request(company_url) company = mo.Company() company.parse_json(company_obj) company = DB_MANAGER.save(company) return company except: return None
def post_many(self, company_details): if len(company_details) > 100: print('This is too much information to load.') return None if not company_details or len(company_details) == 0: print('There is no information.') return None DBSession = sessionmaker(bind=self.engine) session = DBSession() try: for company_detail in company_details: with session.no_autoflush: try: company = models.Company( symbol=company_detail.get('symbol', None), logo=company_detail.get('logo', None), exchange=company_detail.get('exchange', None), name=company_detail.get('name', None), cik=company_detail.get('cik', None), bloomberg=company_detail.get('bloomberg', None), lei=company_detail.get('lei', None), sic=company_detail.get('sic', None), country=company_detail.get('country', None), industry=company_detail.get('industry', None), sector=company_detail.get('sector', None), marketCap=company_detail.get('marketcap', None), employees=company_detail.get('employees', None), phone=company_detail.get('phone', None), ceo=company_detail.get('ceo', None), url=company_detail.get('url', None), description=company_detail.get('description', None), ) session.add(company) except Exception as e: print("company not added", e) session.commit() except Exception as e: print("Roll Back! ", e) session.rollback() finally: session.close()
def test_get_company_polls(self): date1 = arrow.get('2014-10-23').datetime date2 = arrow.get('2017-11-24').datetime poll1 = models.Poll(id=1, date=date1, url="fe", category="m", title="sometitle", client="someclient") poll2 = models.Poll(id=2, date=date2, url="someurl", category="m", title="someothertitle", client="someclient") company = models.Company(code="COM", name="Company", url="someurl", canonical="company") company.company_polls.append(poll1) company.company_polls.append(poll2) db.session.add(company) db.session.commit() # Check we get a response response = self.app.get('/companies/company/polls/') assert response.status_code == 200 # Check we get two polls for the company decoded = response.get_data().decode('utf-8') response_json = json.loads(decoded) assert len(response_json['polls']) == 2 # Check they are sorted by date response_date = arrow.get( response_json['polls'][0].get('date')).datetime assert response_date == date2 # Check the two polls are the ones we defined assert b"someothertitle" in response.get_data() assert b"sometitle" in response.get_data()
def get(self): user = users.get_current_user() if user: project = None if not project: default_flow = models.FlowTemplate.all().filter( "is_default =", True)[0] project = models.Company(owner=user, flow_template=default_flow) project.put() self.redirect('/dashboard') else: self.redirect(users.create_login_url('/new/'))
def create_company(): datadir = '/home/li/company' files = os.listdir(datadir) for fname in files: with open(os.path.join(datadir, fname), 'r') as f: # read file end f.seek(2) data = f.readline().strip('\n') data = data.strip().split(',') print data[1], data[2] company = db.Company() company.code = str(data[1]).zfill(6) company.name = str(data[2]).decode('utf-8') company.zz1code = str(data[3]).zfill(2) company.zz1name = str(data[4]).decode('utf-8') company.zz2code = str(data[5]).zfill(4) company.zz2name = str(data[6]).decode('utf-8') company.zz3code = str(data[7]).zfill(6) company.zz3name = str(data[8]).decode('utf-8') company.zz4code = str(data[9]).zfill(8) company.zz4name = str(data[10]).decode('utf-8') if not db.get_company(company.code): db.add_data([company])
def parse_companies(collect_ids_pass=False): check_preconditions(collect_ids_pass) f = open(JSON_DUMP_DIR + COMPANIES_FILENAME, "r") companies = json.loads(f.read()) companies_list = [] for company_dict in companies: company_id = company_dict['id'] if collect_ids_pass: _KNOWN_COMPANIES.add(company_id) else: website = company_dict['website'] city = company_dict['city'] if city not in _KNOWN_CITIES: city = None name = company_dict['name'] twitter = company_dict['twitter'] summary = company_dict['summary'] logo_url = company_dict['logo_url'] people = json.dumps(filter_contains(_KNOWN_PEOPLE, company_dict['people'])) financial_orgs = json.dumps(filter_contains(_KNOWN_FINORGS, company_dict['financial_orgs'])) c = models.Company(company_id, name, summary, people, city, financial_orgs, twitter, website, logo_url) companies_list += [c] return companies_list
def process_new_company(self, arguments): #-------------------CONTACT INFO--------------- firstName = arguments['firstName'] lastName = arguments["lastName"] title = arguments['title'] email = arguments['email'] phone = arguments['phone'] contacted = True if 'contacted' in arguments else False contact = models.Person( firstName=firstName, lastName=lastName, title=title, email=email, phone=phone, contacted=contacted, ) #-------------------CEO INFO--------------- ceoFirstName = arguments['ceoFirstName'] ceoLastName = arguments['ceoLastName'] ceo = models.Person(firstName=ceoFirstName, lastName=ceoLastName, title="CEO") #-------------------COMPANY INFO--------------- url = arguments['url'] companyName = arguments['companyName'] prettyName = re.sub(r'([^\s\w])+', '', companyName).replace(" ", "-").title() city = arguments['city'] zipCode = arguments['zipCode'] state = arguments['state'] country = country_keys[arguments['country']] if 'companyType' in arguments: companyType = arguments['otherCompanyType'] if arguments[ 'companyType'] == 'Other' else arguments['companyType'] else: companyType = '' yearFounded = 0 if not arguments['yearFounded'] else arguments[ 'yearFounded'] fte = 0 if not arguments['fte'] else arguments['fte'] if 'revenueSource' in arguments: revenueSource = [] if not arguments[ 'revenueSource'] else arguments['revenueSource'].split(',') if 'Other' in revenueSource: del revenueSource[revenueSource.index('Other')] revenueSource.append(arguments['otherRevenueSource']) else: revenueSource = [] if 'category' in arguments: companyCategory = arguments['otherCategory'] if arguments[ 'category'] == 'Other' else arguments['category'] filters = [companyCategory, state, "survey-company"] else: companyCategory = '' filters = [] description = arguments['description'] descriptionShort = arguments['descriptionShort'] financialInfo = arguments['financialInfo'] datasetWishList = arguments['datasetWishList'] if 'sourceCount' in arguments: sourceCount = arguments['sourceCount'] else: sourceCount = '' company = models.Company(companyName=companyName, prettyName=prettyName, url=url, ceo=ceo, city=city, zipCode=zipCode, state=state, yearFounded=yearFounded, fte=fte, companyType=companyType, revenueSource=revenueSource, companyCategory=companyCategory, description=description, descriptionShort=descriptionShort, financialInfo=financialInfo, datasetWishList=datasetWishList, sourceCount=sourceCount, contact=contact, lastUpdated=datetime.now(), display=False, submittedSurvey=True, vetted=False, vettedByCompany=True, submittedThroughWebsite=True, locked=False, filters=filters, country=country) company.save() return company
def create_new_company(self, arguments): company = models.Company(companyName=arguments['companyName'], state=arguments['state'], country=country_keys[arguments['country']]) company.save() return company