def load_companies(): Company.query.delete() comp_list = json.load(open('seed_data/companies.json')) for c in comp_list: comp_id = c['company_id'] is_exist = db.session.query( Company.query.filter( Company.company_id == comp_id).exists()).scalar() if is_exist: continue elif c['address'] != "None": company = Company(company_id=c['company_id'], company_name=c['company_name'], location=c['location'], address=c['address'], lat=c['lat'], lng=c['lng'], rating=c['rating']) db.session.add(company) else: company = Company(company_id=c['company_id'], company_name=c['company_name'], location=c['location']) db.session.add(company) db.session.commit() print("Companies loaded.")
def load_company(): with open("data.csv") as file: data = csv.reader(file, delimiter=",") next(file) # skip first line for row in data: company_name, industry_name, hq_address = row[2].strip(), \ row[8].strip(), \ row[3].strip()+", "+ row[4].strip() +", "+ row[5].strip() if Company.query.filter_by(name=company_name).first() == None: if industry_name: company = Company(company_name, hq_address) company.industry = Industry.query.filter_by( name=industry_name).first() db.session.add(company) print("company loading") else: company = Company(company_name, hq_address) db.session.add(company) print("company loading") db.session.commit() print("company loading completed")
def simulate_sample_company(n_steps, **kwargs): """ Runs a model for n_steps and returns a pandas.DataFrame containing the data collected at each step. kwargs are forwarded to init of company. """ model = Company(**kwargs) for i in range(n_steps): model.step() df = model.data_collector.get_model_vars_dataframe().copy() df['i'] = df.index df['competency_mechanism'] = model.competency_mechanism df['promotion_strategy'] = model.promotion_strategy df['year'] = df['i'] * model.timestep_years return df
def load_companies(): """Load companies from company-example into database.""" print("Loading companies...") # Delete all rows in table to make sure there are no duplicates Company.query.delete() # Read user file and insert data for row in open("data/company-example.txt"): row = row.rstrip() name, street, city, state, zipcode, website = row.split("|") company = Company(name=name, street=street, city=city, state=state, zipcode=zipcode, website=website) # Add to the session or it won't ever be stored db.session.add(company) # Once we're done, we should commit our work db.session.commit()
def load_companies(): """Load companies into Companies table.""" data = pd.read_csv("Diversitech-Table.csv") print "Companies" Company.query.delete() for index, row in data.iterrows(): name = row[0] if type(name) == str: name_lower = name.lower() # number_of_employees = row[28] report_date = row[2] female_overall = row[3] male_overall = row[4] company = Company( name=name_lower, # number_of_employees=number_of_employees, report_date=report_date, female_overall=female_overall, male_overall=male_overall) db.session.add(company) db.session.commit()
def update_last_ticks(companies): engine = start_engine() start = datetime.strptime('2008-07-01', '%Y-%m-%d').date() CSV = 'https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY'\ '&interval=1min'\ '&outputsize=full'\ '&datatype=csv'\ '&apikey=B2S8XKGQNA9PKVS0'\ '&symbol=' if not engine: engine = start_engine() if companies == 'all': companies = Company().query().all() else: company_list = [] for code in companies: company_list.append(get_company(code)) companies = company_list for company in companies: stock = company.code # print('Updating', stock) df = pd.read_csv(CSV + stock + '.AX', parse_dates=['timestamp']) df['timestamp'] = df['timestamp'].dt.tz_localize('Australia/Sydney') df['timestamp'] = df['timestamp'].dt.tz_convert(None) df['timestamp'] = df['timestamp'] + pd.Timedelta(days=1) df = df.loc[df['timestamp'].idxmax()] company.last_dt = df['timestamp'].to_pydatetime() company.last_tick = df['close'] company.save() time.sleep(15)
def add_company(symbol, name=None): old_company = get_company(symbol) if old_company is None: company = Company(symbol, name) db.add(company) return db else: return None
def getCompanyData(link, field, location, companies): company = Company() company.Field = field company.Location = location driver.get(link) #getName try: name = driver.find_element_by_class_name('blockNameCompany').text company.Name = name except NoSuchElementException: pass #getDescription try: description = driver.find_element_by_xpath( '/html/body/main/div/div/div/div[3]/div[1]/div[1]/div/div/div' ).text company.Description = description except: pass companies.append(company) try: driver.find_element_by_class_name('contactButton').click() time.sleep(2) tel = driver.find_element_by_class_name( 'freePhoneNumber-hiconnect').text company.Tel = tel except NoSuchElementException: pass
def insert_company(session, name, revenue, domain, origin): company = Company( name=name, #revenue=parse_revenue_using_currency_and_rate(revenue), revenue_raw=revenue, domain=domain, origin=origin, ) session.add(company)
def add(): if request.method == 'POST': company = Company(request.form['name'], request.form['address'], request.form['phone']) db.session.add(company) db.session.commit() # flash('Adicionado com sucesso!') return redirect(url_for('init')) else: return render_template('add.html')
def add_company(self): id_ = View.get_data('id') codName = View.get_data('codName') fullName = View.get_data('fullName') shortName = View.get_data('shortName') address = View.get_data('address') user_id = View.get_data('user_id') bankDetals = View.get_data('bankDetals') specializatio = View.get_data('specializatio') company = Company.add_company(id_, codName, fullName, shortName, address, bankDetals, specializatio, user_id)
def post(delf): """Add a private job.""" if not current_user.is_active: return 'Please login first.' key1 = request.form.get('key1') key2 = request.form.get('key2') key3 = request.form.get('key3') key4 = request.form.get('key4') company_id = None job_id = None if Company.query.filter(Company.company_name == key2).first(): company = Company.query.filter( Company.company_name == key2).first() company_id = company.company_id else: new_company = Company(key2, is_private='t') db.session.add(new_company) db.session.commit() company = Company.query.filter(Company.company_name == key2).one() company_id = company.company_id if Job.query.filter((Job.title == key1) & (Job.description == key3) & (Job.company_id == company_id) & (Job.is_private == 't')).first(): the_job = Job.query.filter((Job.title == key1) & (Job.description == key3) & (Job.company_id == company_id) & (Job.is_private == 't')).first() job_id = the_job.job_id else: new_job = Job(key1, company_id, key3, key4, is_private='t') db.session.add(new_job) db.session.commit() the_job = Job.query.filter((Job.title == key1) & (Job.description == key3) & (Job.company_id == company_id) & (Job.is_private == 't')).first() job_id = the_job.job_id user_id = current_user.get_id() status = 'Applied' new_user_job = UserJob(user_id, job_id, status) db.session.add(new_user_job) db.session.commit() return 'User Job Added.'
def clearbase(bot, update): uid = update.message.from_user.id if uid not in ADMINS: return try: Company.drop_table() Company.create_table() Service.drop_table() Service.create_table() Good.drop_table() Good.create_table() Aliases.drop_table() Aliases.create_table() except: bot.send_message( uid, 'Что-то пошло не так. Не все таблицы очищены', ) return bot.send_message(uid, 'Таблицу очистил')
def load_companies(): """Load companies from companies.txt into database.""" print "Companies" Company.query.delete() for row in open("seed_data/companies.txt"): name = row.rstrip() company = Company(name=name) db.session.add(company) db.session.commit()
def new_application(): # company attributes company_name = request.form.get('company_name') website = request.form.get('website') # job attributes title = request.form.get('title') link = request.form.get('link') source = request.form.get('source') # application status attributes status = request.form.get('status') application = Application() db.session.add(application) company = db.session.query(Company) \ .filter((Company.company_name==company_name) & (Company.website==website)) \ .first() if not company: company = Company(company_name=company_name, website=website) db.session.add(company) db.session.commit() job = db.session \ .query(Job) \ .filter(Job.title==title, Job.link==link, Job.source==source, Job.company==company) \ .first() if not job: job = Job(title=title, link=link, source=source) db.session.add(job) company.jobs.append(job) db.session.commit() application_status = ApplicationStatus(status=status) db.session.add(application_status) current_user.applications.append(application) job.applications.append(application) application.application_statuses.append(application_status) db.session.commit() # TODO: point entry for new application return jsonify({ 'application_id': application.application_id, 'title': job.title, 'company_name': company.company_name, 'status': application_status.status, })
def populate_company_table(): # Function that populates company table from company list # Clear out all previous tables Company.query.delete() db.session.commit() for comp in companies: name_of_company = comp['name'] industry = comp['industry'] address = comp['address'] website = comp['website'] #Add Company ifo to the database company = Company(name=name_of_company, industry=industry, address=address, website=website) db.session.add(company) db.session.commit()
def seed1(): datetime_applied, datetime_created = datetime.now(), datetime.now() user = User(email='*****@*****.**', password='******', first_name='First', last_name='Last', datetime_created=datetime_created) db.session.add(user) company = Company(company_name='My Company', website='www.mycompany.com', datetime_created=datetime_created) db.session.add(company) db.session.commit() job = Job(company_id=company.company_id, title='Software Engineer', link='www.linkedin.com/mycompany/software-engineer', source='LinkedIn', datetime_created=datetime_created ) db.session.add(job) db.session.commit() application = Application(user_id=user.user_id, job_id=job.job_id, datetime_applied=datetime_applied, referred_by="Anjelica", datetime_created=datetime_created) db.session.add(application) db.session.commit() application_status = ApplicationStatus(application_id=application.application_id, status='Applied', experience_rating='positive', datetime_created=datetime_created) db.session.add(application_status) journal_entry = JournalEntry(application_id=application.application_id, entry='This is a journal entry.', datetime_created=datetime_created) db.session.add(journal_entry) db.session.commit()
def seed2(): datetime_applied, datetime_created = datetime.now(), datetime.now() user = User.query.first() company = db.session.query(Company).filter(Company.company_name.like('%Another Company%')).first() if not company: company = Company(company_name='Another Company', website='www.anothercompany.com', datetime_created=datetime_created) db.session.add(company) db.session.commit() job = db.session.query(Job).filter(Job.company_id==company.company_id, Job.title.like('%Software Engineer%')).first() if not job: job = Job(company_id=company.company_id, title='Software Engineer', link='www.linkedin.com/anothercompany/software-engineer', source='Glassdoor', datetime_created=datetime_created) db.session.add(job) db.session.commit() application = Application(user_id=user.user_id, job_id=job.job_id, datetime_applied=datetime_applied, referred_by="Anjelica", datetime_created=datetime_created) db.session.add(application) db.session.commit() application_status = ApplicationStatus(application_id=application.application_id, status='Applied', experience_rating='positive', datetime_created=datetime_created) db.session.add(application_status) journal_entry = JournalEntry(application_id=application.application_id, entry='Another journal entry.', datetime_created=datetime_created) db.session.add(journal_entry) db.session.commit()
def load_companies(): """ Load companies from companies.txt to database""" for row in open("seed_data/companies.txt"): row = row.strip() id, name, domain, location, time_zone, industry, support_tier, is_pilot = row.split( "|") company = Company(id=id.strip(), name=name.strip(), domain=domain.strip(), location=location.strip(), time_zone=time_zone.strip(), industry=industry.strip(), support_tier=support_tier.strip(), is_pilot=is_pilot.strip()) db.session.add(company) print "Got to here" db.session.commit()
def load_companies(): """Load companies from data_spreadsheet.csv into database.""" print "companies" # Delete all rows in table, so if we need to run this a second time, # we won't be trying to add duplicates. Company.query.delete() # Read data file and insert data. for row in open("data/data_spreadsheet.csv"): row = row.rstrip() key, company, team, num_female_eng, num_eng, percent_female_eng, last_updated, submit, site = row.split( ",") print "*" * 80 key = key.strip('"') company = company.strip('"') team = team.strip('"') num_female_eng = num_female_eng.strip('"') num_eng = num_eng.strip('"') percent_female_eng = percent_female_eng.strip('"') last_updated = last_updated.strip('"') if key != 'key': print row company = Company(key=key, company=company, team=team, num_female_eng=int(num_female_eng), num_eng=int(num_eng), percent_female_eng=float(percent_female_eng), last_updated=last_updated) print company # We need to add to the session or it won't ever be stored. db.session.add(company) # Once we're done, we should commit our work. db.session.commit()
def edit_a_contact(): """Allows user to edit info about a contact""" # redirect if user is not logged in if not session: return redirect('/') else: # get contact object to update contact_id = request.form['contact_id'] contact = Contact.query.filter( Contact.contact_id == contact_id).options( db.joinedload('companies')).first() contact.notes = request.form['notes'] contact.email = request.form['email'] phone = "".join((request.form['phone']).split('-')) contact.phone = phone # look for company_id and find existing company OR # get new company_name and create company object, add, commit if request.form['company_id']: company_id = int(request.form['company_id']) company = Company.query.filter( Company.company_id == company_id).first() elif request.form['company_name']: company_name = request.form['company_name'] company = Company(name=company_name) db.session.add(company) db.session.commit() contact.company_id = company.company_id db.session.commit() # send results back to webpage results = { 'email': contact.email, 'phone': contact.phone, 'company': contact.companies.name, 'notes': contact.notes, } return jsonify(results)
def add_companies(): """Load companies from jobs.json into database.""" job_dict = json.load(open('seed_data/jobs.json')) for j in job_dict: comp = job_dict[j]['company'] is_exist = db.session.query( Company.query.filter( Company.company_name == comp).exists()).scalar() if is_exist: continue else: company = Company(company_name=comp, location=job_dict[j]['location']) db.session.add(company) db.session.commit() print("Companies added.")
def load_companies(): """Load companies from organizations.csv into database.""" with open('data/organizations.csv') as f: reader = csv.reader(f) for row in reader: (crunchbase_uuid, cb_type, primary_role, name, crunchbase_url, homepage_domain, homepage_url, profile_image_url, facebook_url, twitter_url, linkedin_url, stock_symbol, location_city, location_region, location_country_code, short_description) = row if (location_country_code == 'USA' and location_city != '' and primary_role == 'company'): company = Company(name=name, crunchbase_url=crunchbase_url, homepage_url=homepage_url, profile_image_url=profile_image_url, stock_symbol=stock_symbol, city=location_city, state=location_region, short_description=short_description) try: db.session.add(company) db.session.flush() except exc.DataError: db.session.rollback() print 'Data Error' except exc.IntegrityError: db.session.rollback() print 'Integrity Error' else: db.session.commit()
def process_create_company(): """Process a newly created company""" # Get form variables company_name = request.form["companyname"] company_email = request.form["companyemail"] contact_person = request.form["contactperson"] company_phone = request.form["companyphone"] company_address = request.form["companyaddress"] company_city = request.form["companycity"] company_state = request.form["companystate"] company_zip = request.form["companyzip"] password = request.form["password"] password_bytes = password.encode('utf-8') # Hashing password hashed = bcrypt.hashpw(password_bytes, bcrypt.gensalt()) new_company = Company(company_name=company_name, company_email=company_email, contact_person=contact_person, company_phone=company_phone, company_address=company_address, company_city=company_city, company_state=company_state, company_zip=company_zip, password=hashed) # Adding the new company to the database db.session.add(new_company) db.session.commit() # Saving the session session["company_id"] = new_company.company_id flash("%s added." % company_name, "success") return redirect("/company_profile/%s" % new_company.company_id)
def load_company(): db.create_all() name_dict = { # "DIS": "Walt Disney", # "NKE": "Nike", # "M": "Nike" } for ticker, name in name_dict.items(): company = Company(ticker=ticker, name=name) db.session.add(company) data_by_ticker = get_ticker_data(ticker) for date, value in data_by_ticker.items(): if date >= "2018-08-30": date = date open_p = value["1. open"] high_p = value["2. high"] low_p = value["3. low"] close_p = value["4. close"] volume_p = value["5. volume"] daily_price = DailyPrice(date=date, open_p=open_p, low_p=low_p, high_p=high_p, close_p=close_p, volume_p=volume_p) company.daily_prices.append(daily_price) db.session.commit()
def load_companies(): """Load companies information from seed file into the database. working code. """ print("Company") # opening seed file with the csv library and csv reader. with open('seed_production/WorkingDataSet_2-19-2020.csv') as csv_file: # below line will load 'test' seed file # with open('seed_test/programs_test_csv.csv') as csv_file: csv_reader = csv.reader(csv_file, delimiter=',') line_count = 0 utility_list = [] contractor_list = [] pv_manuf_list = [] invert_manuf_list = [] for row in csv_reader: if line_count == 0: # print(f'Column names are {", ".join(row)}') line_count += 1 else: utility_abreviation = row[1] contractor_company = row[44] pv_manuf_company = row[49] invert_manuf_company = row[76] # print functions for debugging: # print(f' LINE COUNT: {line_count}') # print(f'{utility_abreviation}') # print(f'{contractor_company}') # print(f'{pv_manuf_company}') # print(f'{invert_manuf}') #append companies to the appropriate lists: if utility_abreviation not in utility_list: utility_list.append(utility_abreviation) if contractor_company not in contractor_list: contractor_list.append(contractor_company) if pv_manuf_company not in pv_manuf_list: pv_manuf_list.append(pv_manuf_company) if invert_manuf_company not in invert_manuf_list: invert_manuf_list.append(invert_manuf_company) # increase the line count by 1 line_count += 1 # print funtions for debugging: # print(f'utility list: {utility_list}') # print(f'contractor_list: {contractor_list}') # print(f'pv_manuf_list: {pv_manuf_list}') # print(f'invert_manuf_list:{invert_manuf_list}') # print(f'Processed {line_count} lines.') for utility in utility_list: # convert company abbreviations into company names name = get_utility_name(utility) # create instances of the company class to add to the database company = Company(name=name, company_type='Utility and Energy Producer') # print(company) # Add to the session to the database - NEED TO ADD db.session.add(company) for contractor in contractor_list: # create instances of the company class to add to the database company = Company(name=contractor, company_type='Solar Contractor') # print(company) # Add to the session to the database - NEED TO ADD db.session.add(company) for pv_manuf in pv_manuf_list: # create instances of the company class to add to the database company = Company(name=pv_manuf, company_type='photovoltaic manufacture') # Add to the session to the database - NEED TO ADD db.session.add(company) for invert_manuf in invert_manuf_list: # create instances of the company class to add to the database company = Company(name=invert_manuf, company_type='inverter manufacturer') # print(company) # Add to the session to the database - NEED TO ADD db.session.add(company) # Commit our work so it saves to the database db.session.commit() print(f'Company line_count: {line_count}')
def update_company(self): id_ = View.get_data('id') changePar = View.get_data('changer Parameter') changeOn = View.get_data('Change On') company = Company.update_company(id_, changeOn, changePar)
def delite_company(self): id_ = View.get_data('id') Company.delite_company(id_)
def show_company(self): company = Company.get_company() return View.show_item(company)
from model import Company def read_company_data(): fantasy_name = input('Entre com o nome fantasia da empresa: ') social_reason = input('Entre com a razão social da empresa: ') company_dict = { "fantasy_name": fantasy_name, "social_reason": social_reason } return company_dict if __name__ == "__main__": company_dict = read_company_data() new_company = Company(company_dict) print('Nome fantasia da empresa: ', new_company.fantasy_name) print('Razão social da empresa: ', new_company.social_reason)