# Simple API Call Counter
## Environment
1. Python 3.11.x
It is recommended to set with pyenv.
<br>If you can configure the Python execution environment in another way, you can skip the pyenv guide below.
### pyenv
~~~shell
$ pyenv install 3.11.2
$ pyenv virtualenv 3.11.2 url_counter
$ pyenv local url_counter
~~~
### Install
~~~shell
$ pip install api-counter
~~~
### Run
~~~shell
$ counter [FILE] # Quick start with a single file.
~~~
~~~shell
$ counter --help # Show me the help.
$ counter -d . -r -f # Counts urls from all (json and log) files under the current folder and
# creates a result file (however, json files starting with result_ are not included!)
~~~
#### Example of Using Options (Refer to the Help)
~~~shell
$ counter 000.json # Display the count result from 000.json on the screen
$ counter 000.json -f # Display the count result from 000.json on the screen and create a result_{date_time}.json file
$ counter 000.json 111.json 222.json ... # Count multiple json files and display the results on the screen
$ counter 000.json 111.json 222.json ... -f # Count multiple json files, display the results on the screen, and create a result file
$ counter -d ./0000 # Count all json files in the 0000 folder and display the result (subfolders are not processed)
$ counter -d ./0000 -f # Count all json files in the 0000 folder, display the result, and create files (subfolders are not included)
$ counter -d -r -f ./0000 # Count all json files in the 0000 folder, display the result, and create files (including subfolders)
~~~
### Test (unittest with pytest)
~~~shell
$ pytest -svx -rsa tests
~~~
## Result File Format
Format: result_{date_time(%Y%m%d_%H%M%S)}.json
~~~jsonc
{
"targets": [
list of counted files
],
"result": [
"Counted URL: 1st place in frequency",
"Counted URL: Sorted in descending order of frequency"
]
}
~~~
Sample: result_20231209_201928.json
~~~jsonc
{
"targets": [
"tests/samples/nginx.log"
],
"result": [
"GET /api/docs: 18",
"GET /api: 17",
"POST /api/v1/social/signup: 4",
"DELETE /api/v1/users/95: 2",
"PUT /api/v1/users/me: 1",
"POST /api/v1/social/profile/format: 1",
"POST /api/v1/social/profile: 1"
]
}
~~~
## One More Thing (About the ignore option)
If you want to specify lines to exclude from the counter. (e.g. request from a specific IP address, etc.)
<br>You can set export ignores=1.1.1.1 or export ignores=1.1.1.1,2.2.2.2 (no space allowed).
~~~shell
$ export ignores=1.1.1.1
or for multiple ignores.
$ export ignores=1.1.1.1,2.2.2.2
~~~
And surprisingly, this option can work with any string. (e.g. '/api/token')
~~~shell
$ export ignores='/api/token'
or for multiple ignores.
$ export ignores='/api/token',2.2.2.2
~~~
Raw data
{
"_id": null,
"home_page": "https://github.com/windies21/api-counter",
"name": "Api-Counter",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.11.0",
"maintainer_email": "",
"keywords": "",
"author": "winDy",
"author_email": "winDy@windystudio.com",
"download_url": "https://files.pythonhosted.org/packages/18/22/909b09650be171cba75989790fc2e8b06d11a28f7312928d022515bd0c4b/Api-Counter-2.2.3.tar.gz",
"platform": null,
"description": "# Simple API Call Counter\n\n## Environment\n1. Python 3.11.x\n\nIt is recommended to set with pyenv.\n<br>If you can configure the Python execution environment in another way, you can skip the pyenv guide below.\n\n### pyenv\n\n~~~shell\n$ pyenv install 3.11.2\n$ pyenv virtualenv 3.11.2 url_counter\n$ pyenv local url_counter\n~~~\n\n### Install\n\n~~~shell\n$ pip install api-counter\n~~~\n\n### Run\n\n~~~shell\n$ counter [FILE] # Quick start with a single file.\n~~~\n\n~~~shell\n$ counter --help # Show me the help.\n\n$ counter -d . -r -f # Counts urls from all (json and log) files under the current folder and \n # creates a result file (however, json files starting with result_ are not included!)\n~~~\n\n#### Example of Using Options (Refer to the Help)\n~~~shell\n$ counter 000.json # Display the count result from 000.json on the screen\n\n$ counter 000.json -f # Display the count result from 000.json on the screen and create a result_{date_time}.json file\n\n$ counter 000.json 111.json 222.json ... # Count multiple json files and display the results on the screen\n\n$ counter 000.json 111.json 222.json ... -f # Count multiple json files, display the results on the screen, and create a result file\n\n$ counter -d ./0000 # Count all json files in the 0000 folder and display the result (subfolders are not processed)\n\n$ counter -d ./0000 -f # Count all json files in the 0000 folder, display the result, and create files (subfolders are not included)\n\n$ counter -d -r -f ./0000 # Count all json files in the 0000 folder, display the result, and create files (including subfolders)\n~~~\n\n### Test (unittest with pytest)\n\n~~~shell\n$ pytest -svx -rsa tests\n~~~\n\n## Result File Format\n\nFormat: result_{date_time(%Y%m%d_%H%M%S)}.json\n~~~jsonc\n{\n \"targets\": [ \n list of counted files \n ],\n \"result\": [\n \"Counted URL: 1st place in frequency\",\n \"Counted URL: Sorted in descending order of frequency\"\n ]\n}\n~~~\nSample: result_20231209_201928.json\n~~~jsonc\n{\n \"targets\": [\n \"tests/samples/nginx.log\"\n ],\n \"result\": [\n \"GET /api/docs: 18\",\n \"GET /api: 17\",\n \"POST /api/v1/social/signup: 4\",\n \"DELETE /api/v1/users/95: 2\",\n \"PUT /api/v1/users/me: 1\",\n \"POST /api/v1/social/profile/format: 1\",\n \"POST /api/v1/social/profile: 1\"\n ]\n}\n~~~\n\n## One More Thing (About the ignore option)\nIf you want to specify lines to exclude from the counter. (e.g. request from a specific IP address, etc.)\n<br>You can set export ignores=1.1.1.1 or export ignores=1.1.1.1,2.2.2.2 (no space allowed).\n\n~~~shell\n$ export ignores=1.1.1.1\n\nor for multiple ignores.\n$ export ignores=1.1.1.1,2.2.2.2\n~~~\n\nAnd surprisingly, this option can work with any string. (e.g. '/api/token')\n~~~shell\n$ export ignores='/api/token'\n\nor for multiple ignores.\n$ export ignores='/api/token',2.2.2.2\n~~~\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Simple API Counter from log files or folder.",
"version": "2.2.3",
"project_urls": {
"Homepage": "https://github.com/windies21/api-counter"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "dbc28dafd4a60029ccdcf05b39757e9d113f4d017c63d81e81ca8e4c1ccec1d2",
"md5": "b4f7fe9e5c45552930ec48aa2570428a",
"sha256": "2c777bd5432272196ea0a5bc25273ee47b660ee26088c8dec96f72fc7488c8da"
},
"downloads": -1,
"filename": "Api_Counter-2.2.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b4f7fe9e5c45552930ec48aa2570428a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.11.0",
"size": 4055,
"upload_time": "2023-12-09T12:18:58",
"upload_time_iso_8601": "2023-12-09T12:18:58.065798Z",
"url": "https://files.pythonhosted.org/packages/db/c2/8dafd4a60029ccdcf05b39757e9d113f4d017c63d81e81ca8e4c1ccec1d2/Api_Counter-2.2.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1822909b09650be171cba75989790fc2e8b06d11a28f7312928d022515bd0c4b",
"md5": "e0efc0e03dec3eb9902cd6e7e12c3422",
"sha256": "83e6d0f5b34c5b3b027b2f196b16675187c608637f7273a33d5b48b44b278925"
},
"downloads": -1,
"filename": "Api-Counter-2.2.3.tar.gz",
"has_sig": false,
"md5_digest": "e0efc0e03dec3eb9902cd6e7e12c3422",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11.0",
"size": 4301,
"upload_time": "2023-12-09T12:18:59",
"upload_time_iso_8601": "2023-12-09T12:18:59.735621Z",
"url": "https://files.pythonhosted.org/packages/18/22/909b09650be171cba75989790fc2e8b06d11a28f7312928d022515bd0c4b/Api-Counter-2.2.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-09 12:18:59",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "windies21",
"github_project": "api-counter",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "Yirgachefe",
"specs": []
},
{
"name": "click",
"specs": []
},
{
"name": "rich",
"specs": []
},
{
"name": "pytest",
"specs": []
}
],
"lcname": "api-counter"
}