Exemple #1
0
	def setUp(self):
		newco = Company()
		
		#start by creating the required fields
		
		#name
		newco.name = "SuperStartup"
		#permalink
		newco.permalink = "superstartup"
		#category_code
		newco.category_code ="software"
		#number of employees
		newco.number_of_employees = 3
		#founded year
		newco.founded_year = 2001
		#founded_month
		newco.founded_month = None
		#deadpooled_year
		newco.deadpooled_year = None
		#deadpooled_month
		newco.deadpooled_month = None
		#deadpooled_url
		#newco.deadpooled_url = ''
		
		#description
		newco.description = "newco makes widgets that automate productivity of efficient social features in the health, retail, industry, banking, telecommunications, construction and small business accounting industries"
		#overview
		newco.overview = "We are revolution to market"
		#total_money_raised
		newco.total_money_raised = "\u20ac183M"
		
		#save to database before adding manytomanyfields
		newco.save()
		
		#adding ManyToManyField values
		#ipo
		ipo1 = ipo()
		ipo1.save()
		newco.ipo.add(ipo1)
		
		#tag_list
		tag1 = tag(tag = "venture-capital-company")
		tag1.save()
		tag2 = tag(tag = "disruptive-technology-start-ups")
		tag2.save()
		
		newco.tag_list.add(tag1)
		newco.tag_list.add(tag2)

		#funding rounds
		#financial organization
		financial1 = financial_org()
		financial1.name = "Open Ocean"
		financial1.permalink = "openocean"
		financial1.save()
		#investment
		investment1 = investments()
		investment1.save()
		investment1.financial_org.add(financial1)
		
		#round
		round1 = funding_rounds()
		round1.round_code = "a"
		round1.raised_amount = 21640000 
		round1.raised_currency_code = "EUR"
		round1.funded_year = 2008 
		round1.funded_month = 10 
		round1.funded_day = 30 
		round1.save()
		print("Saved the easy funding round...")
		round1.investments.add(investment1)
		
		#Add the funding round
		newco.funding_rounds.add(round1)
Exemple #2
0
def createCompany(dicta):
    newco = Company()
    #start by creating the required fields
    
    #name
    newco.name = dicta["name"]
    #permalink
    try:
        newco.permalink = dicta["permalink"]
    except KeyError:
        newco.permalink
    #category_code
    newco.category_code = dicta["category_code"]
    #number of employees
    newco.number_of_employees = dicta["number_of_employees"]
    #founded year
    newco.founded_year = dicta["founded_year"]
    #founded_month
    newco.founded_month = dicta["founded_month"]
    #deadpooled_year
    newco.deadpooled_year = dicta["deadpooled_year"]
    #deadpooled_month
    newco.deadpooled_month = dicta["deadpooled_month"]
    #deadpooled_url
    newco.deadpooled_url = dicta["deadpooled_url"]
    #description
    newco.description = dicta["description"]
    #overview
    newco.overview = dicta["overview"]
    #total_money_raised
    newco.total_money_raised = dicta["total_money_raised"]
    
    #save to database before adding manytomanyfields
    newco.save()
    
    #Creating ManyToManyField values
    #ipo
    if dicta["ipo"] is not None:
        ipo1 = ipo()
        ipo1.valuation_amount = dicta["ipo"]["valuation_amount"]
        ipo1.valuation_currency_code = dicta["ipo"]["valuation_currency_code"]
        ipo1.pub_year = dicta["ipo"]["pub_year"]
        ipo1.pub_month = dicta["ipo"]["pub_month"]
        ipo1.pub_day = dicta["ipo"]["pub_day"]
        ipo1.stock_symbol = dicta["ipo"]["stock_symbol"]
        ipo1.save()
        newco.ipo.add(ipo1)
    else:
        print("ipo is null")
    
    #Creating funding rounds
    #Funding rounds require investments
    #Investments require either a company, financial_org or person
    # We iterate over the funding rounds, and inside the funding rounds iterate over investments. 
    if dicta["funding_rounds"] is not None:
        #Loop over funding rounds, create the funding round
        for f in dicta['funding_rounds']:
            fr = funding_rounds()
            fr.round_code = f['round_code']
            fr.raised_amount = f['raised_amount']
            fr.raised_currency_code = f['raised_currency_code']
            fr.funded_year = f['funded_year']
            fr.funded_month = f['funded_month']
            fr.funded_day = f['funded_day']
            fr.save()
            #In the current funding round, loop over the investments
            if f["investments"] is not None:
                inv = investments()
                inv.save()
                for i in f['investments']:
                    
                    # For company, financial_org and person, get or create the instance and add it to this investment
                    if i['company'] is not None:
                        try:
                            co = Company.objects.get(name=i['company']['name'])
                            inv.company.add(co)
                        #if the company doesn't already exist, create it.
                        except Company.DoesNotExist:
                            #Try to find the company's real crunchbase page
                            try:
                                permalink = i['company']['permalink']
                                save_by_permalink(permalink)
                                co = Company.objects.get(name=i['company']['name'])
                                inv.company.add(co)
                            except:
                                nCo, created = Company.objects.get_or_create(name=i['company']['name'])
                                inv.company.add(nCo)
                    if i['financial_org'] is not None:
                        try:
                            co = financial_org.objects.get(name=i['financial_org']['name'])
                            inv.financial_org.add(co)
                        #if the company doesn't already exist, create it.
                        except financial_org.DoesNotExist:
                            nCo, created = financial_org.objects.get_or_create(name=i['financial_org']['name'], permalink=i['financial_org']['permalink'])
                            inv.financial_org.add(nCo)
                    if i['person'] is not None:
                        try:
                            co = person.objects.get(permalink=i['person']['permalink'])
                            inv.person.add(co)
                        #if the company doesn't already exist, create it.
                        except person.DoesNotExist:
                            nCo, created = person.objects.get_or_create(first_name=i['person']['first_name'], last_name = i['person']['last_name'], permalink=i['person']['permalink'])
                            inv.person.add(nCo)
                #Add this investment thing in this funding round
                fr.investments.add(inv)
            #Add this funding round to the company
            newco.funding_rounds.add(fr)
    
    #tag_list
    
    if dicta['tag_list'] is not None or "":
    
        #turn the csv list into a list and then loop throught it
        #csv_to_list creates a list of the csv with tags
        taglist = csv_to_list(dicta['tag_list'])
        
        #loop through the list and add them as tags
        
        for i in taglist:
            try:
                tagi = tag.objects.get(tag = i)
                newco.tag_list.add(tagi)
            except tag.DoesNotExist:
                tagi = tag()
                tagi.tag = i
                tagi.save()
                newco.tag_list.add(tagi)