jpcorpreg 1.7.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,3 @@
1
+ include LICENSE
2
+ include README.md
3
+ recursive-include jpcorpreg/config *.json
@@ -0,0 +1,60 @@
1
+ Metadata-Version: 2.4
2
+ Name: jpcorpreg
3
+ Version: 1.7.0
4
+ Summary: jpcorpreg is a Python library that downloads corporate registry which is published in the Corporate Number Publication Site as a data frame.
5
+ Author: new-village
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/new-village/jpcorpreg
8
+ Project-URL: Repository, https://github.com/new-village/jpcorpreg
9
+ Requires-Python: >=3.8
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: requests
13
+ Requires-Dist: bs4
14
+ Requires-Dist: pandas
15
+ Dynamic: license-file
16
+
17
+ # jpcorpreg
18
+ [![Test](https://github.com/new-village/jpcorpreg/actions/workflows/test.yaml/badge.svg)](https://github.com/new-village/jpcorpreg/actions/workflows/test.yaml)
19
+ ![PyPI - Version](https://img.shields.io/pypi/v/jpcorpreg)
20
+
21
+ **jpcorpreg** is a Python library that downloads corporate registry which is published in the [Corporate Number Publication Site](https://www.houjin-bangou.nta.go.jp/en/) as a data frame.
22
+
23
+
24
+ ## Installation
25
+ ----------------------
26
+ jpcorpreg is available on pip installation.
27
+ ```sh
28
+ $ python -m pip install jpcorpreg
29
+ ```
30
+
31
+ ### GitHub Install
32
+ Installing the latest version from GitHub:
33
+ ```sh
34
+ $ git clone https://github.com/new-village/jpcorpreg
35
+ $ cd jpcorpreg
36
+ $ pip install -e .
37
+ ```
38
+
39
+ ## Usage
40
+ This section demonstrates how to use this library to load and process data from the National Tax Agency's [Corporate Number Publication Site](https://www.houjin-bangou.nta.go.jp/).
41
+
42
+ ### Direct Data Loading
43
+ To download data for a specific prefecture, use the `load` function. By passing the prefecture name as an argument, you can obtain a DataFrame containing data for that prefecture.
44
+ ```python
45
+ >>> import jpcorpreg
46
+ >>> df = jpcorpreg.load("Shimane")
47
+ ```
48
+
49
+ To execute the `load` function without argument, data for all prefectures across Japan will be downloaded.
50
+ ```python
51
+ >>> import jpcorpreg
52
+ >>> df = jpcorpreg.load()
53
+ ```
54
+
55
+ ### CSV Data Loading
56
+ If you already have a downloaded CSV file, use the `read_csv` function. By passing the file path as an argument, you can obtain a DataFrame with headers from the CSV data.
57
+ ```python
58
+ >>> import jpcorpreg
59
+ >>> df = jpcorpreg.read_csv("path/to/data.csv")
60
+ ```
@@ -0,0 +1,44 @@
1
+ # jpcorpreg
2
+ [![Test](https://github.com/new-village/jpcorpreg/actions/workflows/test.yaml/badge.svg)](https://github.com/new-village/jpcorpreg/actions/workflows/test.yaml)
3
+ ![PyPI - Version](https://img.shields.io/pypi/v/jpcorpreg)
4
+
5
+ **jpcorpreg** is a Python library that downloads corporate registry which is published in the [Corporate Number Publication Site](https://www.houjin-bangou.nta.go.jp/en/) as a data frame.
6
+
7
+
8
+ ## Installation
9
+ ----------------------
10
+ jpcorpreg is available on pip installation.
11
+ ```sh
12
+ $ python -m pip install jpcorpreg
13
+ ```
14
+
15
+ ### GitHub Install
16
+ Installing the latest version from GitHub:
17
+ ```sh
18
+ $ git clone https://github.com/new-village/jpcorpreg
19
+ $ cd jpcorpreg
20
+ $ pip install -e .
21
+ ```
22
+
23
+ ## Usage
24
+ This section demonstrates how to use this library to load and process data from the National Tax Agency's [Corporate Number Publication Site](https://www.houjin-bangou.nta.go.jp/).
25
+
26
+ ### Direct Data Loading
27
+ To download data for a specific prefecture, use the `load` function. By passing the prefecture name as an argument, you can obtain a DataFrame containing data for that prefecture.
28
+ ```python
29
+ >>> import jpcorpreg
30
+ >>> df = jpcorpreg.load("Shimane")
31
+ ```
32
+
33
+ To execute the `load` function without argument, data for all prefectures across Japan will be downloaded.
34
+ ```python
35
+ >>> import jpcorpreg
36
+ >>> df = jpcorpreg.load()
37
+ ```
38
+
39
+ ### CSV Data Loading
40
+ If you already have a downloaded CSV file, use the `read_csv` function. By passing the file path as an argument, you can obtain a DataFrame with headers from the CSV data.
41
+ ```python
42
+ >>> import jpcorpreg
43
+ >>> df = jpcorpreg.read_csv("path/to/data.csv")
44
+ ```
@@ -0,0 +1,6 @@
1
+ """
2
+ Corporate Number Parser Library
3
+ ~~~~~~~~~~~~~~~~~~~~~
4
+ jpcorpreg is a simple scraping library for Corporate Number Publication Site
5
+ """
6
+ from jpcorpreg.load import load, read_csv
@@ -0,0 +1,32 @@
1
+ [
2
+ "sequence_number",
3
+ "corporate_number",
4
+ "process",
5
+ "correct",
6
+ "update_date",
7
+ "change_date",
8
+ "name",
9
+ "name_image_id",
10
+ "kind",
11
+ "prefecture_name",
12
+ "city_name",
13
+ "street_number",
14
+ "address_image_id",
15
+ "prefecture_code",
16
+ "city_code",
17
+ "post_code",
18
+ "address_outside",
19
+ "address_outside_image_id",
20
+ "close_date",
21
+ "close_cause",
22
+ "successor_corporate_number",
23
+ "change_cause",
24
+ "assignment_date",
25
+ "latest",
26
+ "en_name",
27
+ "en_prefecture_name",
28
+ "en_city_name",
29
+ "en_address_outside",
30
+ "furigana",
31
+ "hihyoji"
32
+ ]
@@ -0,0 +1,216 @@
1
+ '''load.py
2
+ '''
3
+ import io
4
+ import re
5
+ import zipfile
6
+
7
+ import requests
8
+ import pandas as pd
9
+ from io import StringIO
10
+ from bs4 import BeautifulSoup
11
+
12
+ from jpcorpreg.utility import load_config
13
+
14
+ # Dictionary mapping Japanese prefecture names to English
15
+ PREF_MAP = {
16
+ "全国": "All",
17
+ "北海道": "Hokkaido",
18
+ "青森県": "Aomori",
19
+ "岩手県": "Iwate",
20
+ "宮城県": "Miyagi",
21
+ "秋田県": "Akita",
22
+ "山形県": "Yamagata",
23
+ "福島県": "Fukushima",
24
+ "茨城県": "Ibaraki",
25
+ "栃木県": "Tochigi",
26
+ "群馬県": "Gunma",
27
+ "埼玉県": "Saitama",
28
+ "千葉県": "Chiba",
29
+ "東京都": "Tokyo",
30
+ "神奈川県": "Kanagawa",
31
+ "新潟県": "Niigata",
32
+ "富山県": "Toyama",
33
+ "石川県": "Ishikawa",
34
+ "福井県": "Fukui",
35
+ "山梨県": "Yamanashi",
36
+ "長野県": "Nagano",
37
+ "岐阜県": "Gifu",
38
+ "静岡県": "Shizuoka",
39
+ "愛知県": "Aichi",
40
+ "三重県": "Mie",
41
+ "滋賀県": "Shiga",
42
+ "京都府": "Kyoto",
43
+ "大阪府": "Osaka",
44
+ "兵庫県": "Hyogo",
45
+ "奈良県": "Nara",
46
+ "和歌山県": "Wakayama",
47
+ "鳥取県": "Tottori",
48
+ "島根県": "Shimane",
49
+ "岡山県": "Okayama",
50
+ "広島県": "Hiroshima",
51
+ "山口県": "Yamaguchi",
52
+ "徳島県": "Tokushima",
53
+ "香川県": "Kagawa",
54
+ "愛媛県": "Ehime",
55
+ "高知県": "Kochi",
56
+ "福岡県": "Fukuoka",
57
+ "佐賀県": "Saga",
58
+ "長崎県": "Nagasaki",
59
+ "熊本県": "Kumamoto",
60
+ "大分県": "Oita",
61
+ "宮崎県": "Miyazaki",
62
+ "鹿児島県": "Kagoshima",
63
+ "沖縄県": "Okinawa",
64
+ "国外": "Other"
65
+ }
66
+
67
+ def load(prefecture="All") -> pd.DataFrame:
68
+ """Loads data for a specified prefecture.
69
+
70
+ Args:
71
+ prefecture (str): The name of the prefecture to load data for. Defaults to "All".
72
+
73
+ Returns:
74
+ DataFrame: A DataFrame containing the loaded data.
75
+ """
76
+ loader = ZipLoader()
77
+ return loader.zip_load(prefecture)
78
+
79
+ def read_csv(file_path: str) -> pd.DataFrame:
80
+ """Reads a CSV file from a specified path.
81
+
82
+ Args:
83
+ file_path (str): The path to the CSV file.
84
+
85
+ Returns:
86
+ DataFrame: A DataFrame containing the CSV data.
87
+ """
88
+ header = load_config("header")
89
+ return pd.read_csv(file_path, encoding='utf-8', header=None, names=header, dtype='object')
90
+
91
+ class ZipLoader():
92
+ """Handles the loading and processing of zip files from a specified URL."""
93
+ def __init__(self):
94
+ self.url = "https://www.houjin-bangou.nta.go.jp/download/zenken/"
95
+
96
+ try:
97
+ response = requests.get(self.url, timeout=(3.0, 60.0))
98
+ soup = BeautifulSoup(response.text, "html.parser")
99
+ except requests.exceptions.RequestException as exp:
100
+ raise SystemExit(f"Request to {self.url} has been failure") from exp
101
+
102
+ key = "jp.go.nta.houjin_bangou.framework.web.common.CNSFWTokenProcessor.request.token"
103
+ self.payload = {key: self._load_token(soup, key), "event": "download"}
104
+ self.pref_list = self._fetch_file_ids(soup)
105
+
106
+ def zip_load(self, prefecture) -> pd.DataFrame:
107
+ """Loads and processes a zip file from the server using a file ID.
108
+
109
+ Args:
110
+ file_id (str): The file ID to request the zip file.
111
+
112
+ Returns:
113
+ DataFrame: A DataFrame containing the data from the zip file.
114
+ """
115
+ try:
116
+ file_id = self.pref_list[prefecture.capitalize()]
117
+ except KeyError as exp:
118
+ raise SystemExit(f"Unexpected Key Value: {prefecture}") from exp
119
+
120
+ contents = self._download_zip(file_id)
121
+ csv_string = self._uncompress_file(contents)
122
+ return self._convert_csv_2_df(csv_string)
123
+
124
+ def _load_token(self, soup, key) -> str:
125
+ """Loads a security token from the server for requests.
126
+
127
+ Args:
128
+ url (str): The URL to load the token from.
129
+ key (str): The key name of the token to retrieve.
130
+
131
+ Returns:
132
+ str: The token as a string.
133
+
134
+ Raises:
135
+ SystemExit: If the request fails.
136
+ """
137
+ return soup.find("input", {"name": key, "type": "hidden"})["value"]
138
+
139
+ def _download_zip(self, file_id) -> bytes:
140
+ """Downloads a zip file from the server using the specified file ID.
141
+
142
+ Args:
143
+ file_id (str): The file ID to use for the download.
144
+
145
+ Returns:
146
+ bytes: The content of the zip file as bytes.
147
+
148
+ Raises:
149
+ SystemExit: If the request fails or the server responds with an error.
150
+ """
151
+ try:
152
+ self.payload["selDlFileNo"] = file_id
153
+ res = requests.post(self.url, params=self.payload, timeout=(3.0, 120.0))
154
+ except requests.exceptions.RequestException as exp:
155
+ print('Request is failure: Name, server or service not known')
156
+ raise SystemExit("RequestsExceptions") from exp
157
+
158
+ if res.status_code not in [200]:
159
+ raise SystemExit('Request to ' + self.url + ' has been failed: ' + str(res.status_code))
160
+ return res.content
161
+
162
+ def _uncompress_file(self, content) -> StringIO:
163
+ """Uncompresses the zip file content and extracts the CSV file.
164
+
165
+ Args:
166
+ content (bytes): The content of the zip file as bytes.
167
+
168
+ Returns:
169
+ StringIO: The CSV file content as a StringIO object.
170
+
171
+ Raises:
172
+ zipfile.BadZipFile: If the content is not a valid zip file.
173
+ """
174
+ try:
175
+ zip_object = zipfile.ZipFile(io.BytesIO(content))
176
+ except zipfile.BadZipFile:
177
+ print("Failed to unzip content. The content may not be a valid zip file.")
178
+ raise
179
+
180
+ for file_name in zip_object.namelist():
181
+ if not re.search(r'.*\.asc', file_name):
182
+ txt = zip_object.open(file_name).read()
183
+ return StringIO(txt.decode('utf-8'))
184
+
185
+ def _convert_csv_2_df(self, csv_string) -> pd.DataFrame:
186
+ """Converts a CSV string to a DataFrame using predefined headers.
187
+
188
+ Args:
189
+ csv_string (str): The CSV file content as a string.
190
+
191
+ Returns:
192
+ DataFrame: A DataFrame created from the CSV string.
193
+ """
194
+ header = load_config("header")
195
+ return pd.read_csv(csv_string, encoding='utf-8', header=None, names=header, dtype='object')
196
+
197
+ def _fetch_file_ids(self, soup) -> dict:
198
+ """
199
+ Extracts file IDs from the parsed HTML of a webpage.
200
+
201
+ Args:
202
+ soup (BeautifulSoup): The BeautifulSoup object containing the parsed HTML.
203
+
204
+ Returns:
205
+ dict: A dictionary mapping region names to their corresponding file IDs.
206
+ """
207
+
208
+ unicode_table = soup.find('div', class_='inBox21').find_all('div', class_='tbl02')[1]
209
+ rows = unicode_table.find_all('dl')
210
+ region_file_ids = {}
211
+ for row in rows:
212
+ region_name_jp = row.find('dt', class_='mb05').text.strip()
213
+ region_name = PREF_MAP.get(region_name_jp, region_name_jp) # Convert Japanese to English if possible
214
+ file_id = re.search(r'\d{5}', row.find('a').get('onclick')).group() # Extract file ID using regex
215
+ region_file_ids[region_name] = file_id
216
+ return region_file_ids
@@ -0,0 +1,21 @@
1
+ """ Utility
2
+ It is utility functions class.
3
+ """
4
+ import json
5
+ import os
6
+
7
+ import jpcorpreg
8
+
9
+
10
+ def load_config(data_type:str) -> str:
11
+ """ The function loads configuration file from config directory
12
+ :param data_type: Category is identifier of data types such as ENTRY, ODDS, RACE and RESULT.
13
+ """
14
+ try:
15
+ dir_location = os.path.dirname(jpcorpreg.__file__) + '/config/'
16
+ with open(dir_location + data_type + '.json', 'r', encoding='UTF-8') as file:
17
+ return json.load(file)
18
+ except json.JSONDecodeError as exc:
19
+ raise SystemExit(f'Config file decode error: {exc}') from exc
20
+ except FileNotFoundError as exc:
21
+ raise SystemExit(f'Config file not found: {exc}') from exc
@@ -0,0 +1,60 @@
1
+ Metadata-Version: 2.4
2
+ Name: jpcorpreg
3
+ Version: 1.7.0
4
+ Summary: jpcorpreg is a Python library that downloads corporate registry which is published in the Corporate Number Publication Site as a data frame.
5
+ Author: new-village
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/new-village/jpcorpreg
8
+ Project-URL: Repository, https://github.com/new-village/jpcorpreg
9
+ Requires-Python: >=3.8
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: requests
13
+ Requires-Dist: bs4
14
+ Requires-Dist: pandas
15
+ Dynamic: license-file
16
+
17
+ # jpcorpreg
18
+ [![Test](https://github.com/new-village/jpcorpreg/actions/workflows/test.yaml/badge.svg)](https://github.com/new-village/jpcorpreg/actions/workflows/test.yaml)
19
+ ![PyPI - Version](https://img.shields.io/pypi/v/jpcorpreg)
20
+
21
+ **jpcorpreg** is a Python library that downloads corporate registry which is published in the [Corporate Number Publication Site](https://www.houjin-bangou.nta.go.jp/en/) as a data frame.
22
+
23
+
24
+ ## Installation
25
+ ----------------------
26
+ jpcorpreg is available on pip installation.
27
+ ```sh
28
+ $ python -m pip install jpcorpreg
29
+ ```
30
+
31
+ ### GitHub Install
32
+ Installing the latest version from GitHub:
33
+ ```sh
34
+ $ git clone https://github.com/new-village/jpcorpreg
35
+ $ cd jpcorpreg
36
+ $ pip install -e .
37
+ ```
38
+
39
+ ## Usage
40
+ This section demonstrates how to use this library to load and process data from the National Tax Agency's [Corporate Number Publication Site](https://www.houjin-bangou.nta.go.jp/).
41
+
42
+ ### Direct Data Loading
43
+ To download data for a specific prefecture, use the `load` function. By passing the prefecture name as an argument, you can obtain a DataFrame containing data for that prefecture.
44
+ ```python
45
+ >>> import jpcorpreg
46
+ >>> df = jpcorpreg.load("Shimane")
47
+ ```
48
+
49
+ To execute the `load` function without argument, data for all prefectures across Japan will be downloaded.
50
+ ```python
51
+ >>> import jpcorpreg
52
+ >>> df = jpcorpreg.load()
53
+ ```
54
+
55
+ ### CSV Data Loading
56
+ If you already have a downloaded CSV file, use the `read_csv` function. By passing the file path as an argument, you can obtain a DataFrame with headers from the CSV data.
57
+ ```python
58
+ >>> import jpcorpreg
59
+ >>> df = jpcorpreg.read_csv("path/to/data.csv")
60
+ ```
@@ -0,0 +1,14 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ pyproject.toml
5
+ jpcorpreg/__init__.py
6
+ jpcorpreg/load.py
7
+ jpcorpreg/utility.py
8
+ jpcorpreg.egg-info/PKG-INFO
9
+ jpcorpreg.egg-info/SOURCES.txt
10
+ jpcorpreg.egg-info/dependency_links.txt
11
+ jpcorpreg.egg-info/requires.txt
12
+ jpcorpreg.egg-info/top_level.txt
13
+ jpcorpreg/config/header.json
14
+ test/test_load.py
@@ -0,0 +1,3 @@
1
+ requests
2
+ bs4
3
+ pandas
@@ -0,0 +1 @@
1
+ jpcorpreg
@@ -0,0 +1,31 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "jpcorpreg"
7
+ version = "1.7.0"
8
+ description = "jpcorpreg is a Python library that downloads corporate registry which is published in the Corporate Number Publication Site as a data frame."
9
+ readme = "README.md"
10
+ authors = [{ name = "new-village" }]
11
+ license = { text = "Apache-2.0" }
12
+ requires-python = ">=3.8"
13
+ dependencies = [
14
+ "requests",
15
+ "bs4",
16
+ "pandas",
17
+ ]
18
+
19
+ [project.urls]
20
+ Homepage = "https://github.com/new-village/jpcorpreg"
21
+ Repository = "https://github.com/new-village/jpcorpreg"
22
+
23
+ [tool.setuptools]
24
+ include-package-data = true
25
+
26
+ [tool.setuptools.packages.find]
27
+ include = ["jpcorpreg"]
28
+ where = ["."]
29
+
30
+ [tool.setuptools.package-data]
31
+ jpcorpreg = ["config/*.json"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,35 @@
1
+ """ test_load.py
2
+ """
3
+ import unittest
4
+ import json
5
+ import pandas as pd
6
+ import jpcorpreg
7
+
8
+ class TestLoadFunctions(unittest.TestCase):
9
+ def setUp(self):
10
+ """Load expected columns from configuration file before each test."""
11
+ with open('jpcorpreg/config/header.json', 'r') as file:
12
+ self.expected_columns = json.load(file)
13
+
14
+ def test_load(self):
15
+ """Test the load function with 'Shimane' prefecture."""
16
+ result = jpcorpreg.load(prefecture='Shimane')
17
+
18
+ # Validate results
19
+ self.assertIsInstance(result, pd.DataFrame)
20
+ self.assertEqual(list(result.columns), self.expected_columns)
21
+ self.assertGreater(len(result), 20000)
22
+
23
+ def test_read_csv(self):
24
+ """Test the read_csv function with a specific CSV file."""
25
+ result = jpcorpreg.read_csv('./test/data/31_tottori_test_20240329.csv')
26
+
27
+ # Validate results
28
+ self.assertIsInstance(result, pd.DataFrame)
29
+ self.assertEqual(list(result.columns), self.expected_columns)
30
+ self.assertEqual(len(result), 5)
31
+ self.assertEqual(result.iloc[0]['corporate_number'], '1000013050238')
32
+ self.assertEqual(result.iloc[1]['name'], '島田商事株式会社')
33
+
34
+ if __name__ == '__main__':
35
+ unittest.main()