-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathretrieve_companies_hki.py
More file actions
44 lines (35 loc) · 1.47 KB
/
retrieve_companies_hki.py
File metadata and controls
44 lines (35 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import requests
import datetime
# Function to query the PRH API for companies in a given city within the last month
def query_companies(city_name):
print(f"Querying for companies in {city_name} within the last month")
# Define the base URL for the PRH API
base_url = "https://avoindata.prh.fi/bis/v1"
# Calculate the date one month ago from today
one_month_ago = datetime.datetime.now() - datetime.timedelta(days=30)
formatted_date = one_month_ago.strftime('%Y-%m-%d')
# Define your specific parameters
params = {
'totalResults': 'true',
'maxResults': '1000',
'resultsFrom': '0',
'registeredOffice': city_name,
'companyForm': 'OY',
'companyRegistrationFrom': formatted_date
}
# Make the API request
response = requests.get(base_url, params=params)
# Check if the request was successful
if response.status_code == 200:
data = response.json()
total_results = data['totalResults']
print(f"Total companies in {city_name}: {total_results}")
# Extract email addresses if available
for company in data['results']:
# Assuming email is a field in the company data
email = company.get('email', 'No email available')
print(f"Company: {company['name']}, Email: {email}")
else:
print(f"Failed to retrieve data. Status Code: {response.status_code}, Response: {response.text}")
# Example usage
query_companies('Helsinki')