Pipenv Installation

What is Pipenv??

pipenv is a better package.

It contain pipfile.lock which contain all require package & dependencies

pipfile is automatically installed.

pipenv can work with requirement.txt file too. If there is one automatically detect it & convert into a pipfile.

Install Pipenv

Before installation get to know python is already installed

$python -V

$pip -V

$pip install pipenv or pipenv install --dev

$pipenv -h (to check the pipenv correctly installed)

$pipenv shell

$exit or deactivate

If showing pipenv not recognized as internal or external command , have to set Path in environment variable.

View More...

Read Write CSV File for Company House using Python

from companyhouse_api import CompaniesHouseAPI ## CompaniesHouseAPI write in post 4088
import pandas as pd
import datetime
key = "XXXXXXXXXXXX" #Fake key - insert your key here
company_numbers_file = "CompanyNumbers.csv"
company_output_file = "CompanyDataOutput.csv"
#Read csv into pandas dataframe
df = pd.read_csv(company_numbers_file)
#Create an instance of the wrapper class
ch_api = CompaniesHouseAPI(key)
#Start timer
tic = datetime.datetime.now()
#Loop through rows of dataframe
for index, row in df.iterrows():
company_number = row["Company Number"]
ch_profile = ch_api.get_company_profile(company_number)
df.at[index, "Company Name"] = ch_profile.get("company_name", None)
#SIC codes are returned as a list of up to 4 numbers
sics = ch_profile.get("sic_codes", [None])
for i in range(0,len(sics)):
df.at[index, f"SIC {i+1}"] = sics[i]
print(f"Num: {row['Company Number']} | "\
f"Name: {df.at[index,'Company Name']}")
#End timer
toc = datetime.datetime.now()
avg_time = ((toc-tic).total_seconds())/(len(df.index)-1)
print(f"Average time between API calls: {avg_time:0.2f} seconds")
#Save the results to a csv file
df.to_csv(company_output_file, index=False)
#"CompanyNumbers.csv" given below
Company Number
03127966
SC380228
08090951
08274073
09120350
05487913
11052744
08608755
05945470
10621964
04857873
FC012676
SC515156
SC636062
11605899
11852632
SC513290
12200440
11213791
09202675
07079128
00952490
08978206
11745804
12377237
08483294
11734142
11504009
10574013

View More...

Company House API Integreation using python

import requests
import json
import datetime
import time
class CompaniesHouseService:
base_url = "https://api.companieshouse.gov.uk"
search_url = base_url+"/search/companies?q={}&items_per_page={}&start_index={}"
company_url = base_url+"/company/{}"
company_charges_url = base_url+"/company/{}/charges"
company_charge_url = base_url+"/company/{}/charges/{}"
company_exemptions_url = base_url+"/company/{}/exemptions"
company_filing_histories_url = base_url+"/company/{}/filing-history"
company_filing_history_url = base_url+"/company/{}/filing-history/{}"
company_insolvency_url = base_url+"/company/{}/insolvency"
person_corporate_entity_url = base_url+"/company/{}/persons-with-significant-control/corporate-entity/{}"
person_control_individual_url = base_url+"/company/{}/persons-with-significant-control/individual/{}"
person_control_legal_person_url = base_url+"/company/{}/persons-with-significant-control/legal-person/{}"
person_control_statement_url = base_url+"/company/{}/persons-with-significant-control-statements/{}"
person_control_super_secure_url = base_url+"/company/{}/persons-with-significant-control/super-secure/{}"
company_registers_url = base_url+"/company/{}/registers"
company_registered_office_address_url = base_url+"/company/{}/registered-office-address"
disqualified_officers_corporate_url = base_url+"/disqualified-officers/corporate/{}"
disqualified_officers_natural_url = base_url+"/disqualified-officers/natural/{}"
company_officers_url = base_url+"/company/{}/officers"
company_officer_url = base_url+"/company/{}/appointments/{}"
company_uk_establishments_url = base_url+"/company/{}/uk-establishments"
company_officer_appointments_url = base_url+"/officers/{}/appointments?items_per_page={}&start_index={}"
person_significate_control_url = base_url+"/company/{}/persons-with-significant-control?items_per_page={}&start_index={}"
person_signicate_control_statements_url = base_url+"/company/{}/persons-with-significant-control-statements?items_per_page={}&start_index={}"
def __init__(self, key, time_between_requests=0.5):
self.key = key
self.time_between_requests = time_between_requests
self.last_request_timestamp = None
def query_companieshouse_api(self, url, query, items_per_page=10, start_index=0):
query = self._remove_problem_characters(query)
self._rate_limiting()
resultQuery = requests.get(url.format(query, items_per_page, start_index),auth=(self.key,''))
print(url.format(query, items_per_page, start_index))
if resultQuery.status_code == 200:
result = json.JSONDecoder().decode(resultQuery.text)
else:
print(f"Failed with error code: {resultQuery.status_code} | "\
f"Reason: {resultQuery.reason}")
result = {}
return result
def _rate_limiting(self):
if self.last_request_timestamp is None:
self.last_request_timestamp = datetime.datetime.now()
else:
current_time = datetime.datetime.now()
time_since_request = (current_time - self.last_request_timestamp).total_seconds()
wait_time = max(self.time_between_requests - time_since_request, 0)
time.sleep(wait_time)
self.last_request_timestamp = datetime.datetime.now()
def _remove_problem_characters(self, string):
string = string.replace(" ","+")
string = string.replace("&","%26")
return string
def get_company_profile(self, company_number):
company_profile = self.query_companieshouse_api(self.company_url, company_number)
return company_profile
def get_company_charges(self, company_number, charge_id):
company_charges = self.query_companieshouse_api(self.company_charge_url, company_number, charge_id)
return company_charges
def list_company_charges(self, company_number):
company_charges_list = self.query_companieshouse_api(self.company_charges_url, company_number)
return company_charges_list
def get_company_exemptions(self, company_number):
company_exemptions = self.query_companieshouse_api(self.company_exemptions_url, company_number)
return company_exemptions
def list_company_filing_history(self, company_number):
company_filing_histories = self.query_companieshouse_api(self.company_filing_histories_url, company_number)
return company_filing_histories
def get_company_filing_history(self, company_number, transaction_id):
company_filing_history = self.query_companieshouse_api(self.company_filing_history_url, company_number, transaction_id)
return company_filing_history
def get_company_insolvency(self, company_number):
company_insolvency = self.query_companieshouse_api(self.company_insolvency_url, company_number)
return company_insolvency
def get_company_persons_with_significant_control_corporate_entity(self, company_number,psc_id):
person_corporate_entity = self.query_companieshouse_api(self.person_corporate_entity_url, company_number)
return person_corporate_entity
def get_company_persons_with_significant_control_individual(self, company_number, psc_id):
person_control_individual = self.query_companieshouse_api(self.person_control_individual_url, company_number)
return person_control_individual
def get_company_persons_with_significant_control_legal_person(self, company_number, psc_id):
person_control_legal_person = self.query_companieshouse_api(self.person_control_legal_person_url, company_number)
return person_control_legal_person
def get_company_persons_with_significant_control_statements(self, company_number, statement_id):
person_control_statement = self.query_companieshouse_api(self.person_control_statement_url, company_number)
return person_control_statement
def get_company_persons_with_significant_control_super_secure(self, company_number, super_secure_id):
person_control_super_secure = self.query_companieshouse_api(self.person_control_super_secure_url, company_number)
return person_control_super_secure
def get_company_registered_office_address(self, company_number):
company_registered_office_address = self.query_companieshouse_api(self.company_registered_office_address_url, company_number)
return company_registered_office_address
def get_company_registers(self, company_number):
company_registers = self.query_companieshouse_api(self.company_registers_url, company_number)
return company_registers
def get_disqualified_officers_corporate(self, officer_id):
disqualified_officers_corporate = self.query_companieshouse_api(self.disqualified_officers_corporate_url, company_number)
return disqualified_officers_corporate
def get_disqualified_officers_natural(self, officer_id):
disqualified_officers_natural = self.query_companieshouse_api(self.disqualified_officers_natural_url, company_number)
return disqualified_officers_natural
def list_company_officers(self, company_number):
company_officers = self.query_companieshouse_api(self.company_officers_url, company_number)
return company_officers
def get_company_officers(self, company_number, appointment_id):
company_officer = self.query_companieshouse_api(self.company_officer_url, company_number)
return company_officer
def list_company_uk_establishments(self, company_number):
company_uk_establishments = self.query_companieshouse_api(self.company_uk_establishments_url, company_number)
return company_uk_establishments
def list_company_persons_with_significant_control(self, company_number, items_per_page=10, start_index=0):
person_significate_control = self.query_companieshouse_api(self.person_significate_control_url, company_number, items_per_page, start_index)
return person_significate_control
def list_company_persons_with_significant_control_statements(self, company_number, items_per_page=10, start_index=0):
person_signicate_control_statements = self.query_companieshouse_api(self.person_signicate_control_statements_url, company_number)
return person_signicate_control_statements
def list_officers_appointments(self, officer_id, items_per_page=10, start_index=0):
company_officer_appointments = self.query_companieshouse_api(self.company_officer_appointments_url, company_number, items_per_page, start_index)
return company_officer_appointments
def search_companies(self, company_name, items_per_page=10, start_index=0):
search_result = self.query_companieshouse_api(self.search_url, company_name, items_per_page, start_index)
return search_result
if __name__ == "__main__":
key = "XXXXXXXXXXXXXXXXXXXXX" #Generate key https://developer.company-information.service.gov.uk/
ch_api = CompaniesHouseService(key)
search_query = "google"
company_number = "00445790"
charge_id = "5QU1lSudRI2jTIfUv_AOVxfLxVE"
transaction_id = "MzMyODc4MjQ4MmFkaXF6a2N4"
company_profile = ch_api.get_company_profile(company_number)
companies = ch_api.search_companies(search_query, 100, 0)
company_charges_list = ch_api.list_company_charges(company_number)
company_charges = ch_api.get_company_charges(company_number, charge_id)
company_exemptions = ch_api.get_company_exemptions(company_number)
company_filing_histories = ch_api.list_company_filing_history(company_number)
company_filing_history = ch_api.get_company_filing_history(company_number, transaction_id)
company_insolvency = ch_api.get_company_insolvency(company_number)

View More...

Error while cloning--- 'git' is not recognized as an internal or external command, operable program

Already installed in Linux--> No Need to do any process

Windows-->

1- Install Git -- https://git-scm.com/download/win

2-Set Path

Go to Start

Start typing 'This PC'

Right-click This PC, choose Properties

On the left side of the window that pops up, click on Advanced System Settings

Click on the Advanced tab

Click on the Environmental Variables button at the bottom

Down in the System Variables section, double-click Path

Click the New button in the top right corner

Add this path: C:\Program Files\Git\bin\ then click the enter key

Add another path: C:\Program Files\Git\cmd

Close & re-open the console if it's already open.

View More...

First Previous 1 2 3 4 5 Next Last