flask-pluginkit-accesscount 0.1.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.
- flask_pluginkit_accesscount-0.1.0/LICENSE +29 -0
- flask_pluginkit_accesscount-0.1.0/PKG-INFO +34 -0
- flask_pluginkit_accesscount-0.1.0/README.md +26 -0
- flask_pluginkit_accesscount-0.1.0/flask_pluginkit_accesscount/__init__.py +65 -0
- flask_pluginkit_accesscount-0.1.0/flask_pluginkit_accesscount.egg-info/PKG-INFO +34 -0
- flask_pluginkit_accesscount-0.1.0/flask_pluginkit_accesscount.egg-info/SOURCES.txt +10 -0
- flask_pluginkit_accesscount-0.1.0/flask_pluginkit_accesscount.egg-info/dependency_links.txt +1 -0
- flask_pluginkit_accesscount-0.1.0/flask_pluginkit_accesscount.egg-info/not-zip-safe +1 -0
- flask_pluginkit_accesscount-0.1.0/flask_pluginkit_accesscount.egg-info/requires.txt +1 -0
- flask_pluginkit_accesscount-0.1.0/flask_pluginkit_accesscount.egg-info/top_level.txt +1 -0
- flask_pluginkit_accesscount-0.1.0/setup.cfg +4 -0
- flask_pluginkit_accesscount-0.1.0/setup.py +64 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019, Flask-PluginKit
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
10
|
+
list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
|
14
|
+
and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
17
|
+
contributors may be used to endorse or promote products derived from
|
|
18
|
+
this software without specific prior written permission.
|
|
19
|
+
|
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
24
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
25
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
26
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
27
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
28
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: flask-pluginkit-accesscount
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: IP、PV、Endpoint Statistics
|
|
5
|
+
Home-page: https://github.com/saintic/flask-pluginkit-accesscount
|
|
6
|
+
Download-URL: https://github.com/saintic/flask-pluginkit-accesscount
|
|
7
|
+
Author: Hiroshi.tao
|
|
8
|
+
Author-email: me@tcw.im
|
|
9
|
+
Keywords: flask-pluginkit
|
|
10
|
+
Classifier: Environment :: Web Environment
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
21
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
22
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: Flask-PluginKit>=3.8.0
|
|
26
|
+
Dynamic: author
|
|
27
|
+
Dynamic: author-email
|
|
28
|
+
Dynamic: classifier
|
|
29
|
+
Dynamic: download-url
|
|
30
|
+
Dynamic: home-page
|
|
31
|
+
Dynamic: keywords
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
Dynamic: requires-dist
|
|
34
|
+
Dynamic: summary
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# AccessCount
|
|
2
|
+
|
|
3
|
+
IP、PV、Endpoint统计插件
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
### Development
|
|
8
|
+
|
|
9
|
+
`pip install git+https://github.com/saintic/flask-pluginkit-accesscount@master`
|
|
10
|
+
|
|
11
|
+
### PypI Release
|
|
12
|
+
|
|
13
|
+
`pip install flask-pluginkit-accesscount`
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from flask_pluginkit import PluginManager
|
|
19
|
+
|
|
20
|
+
PluginManager(
|
|
21
|
+
plugin_packages=["flask_pluginkit_accesscount"],
|
|
22
|
+
# If Flask-PluginKit version >= 3.10.0, otherwise pip install it.
|
|
23
|
+
install_packages=dict(pkgs=["flask-pluginkit-accesscount"]),
|
|
24
|
+
)
|
|
25
|
+
```
|
|
26
|
+
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
AccessCount
|
|
4
|
+
-----------
|
|
5
|
+
|
|
6
|
+
PV and IP plugins for statistical access.
|
|
7
|
+
|
|
8
|
+
:copyright: (c) 2025 by Hiroshi.tao.
|
|
9
|
+
:license: BSD 3-Clause License, see LICENSE for more details.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from datetime import datetime
|
|
13
|
+
from flask import current_app, request, g
|
|
14
|
+
from flask_pluginkit import RedisStorage
|
|
15
|
+
|
|
16
|
+
__plugin_name__ = "AccessCount"
|
|
17
|
+
__description__ = "IP、PV、Endpoint Statistics"
|
|
18
|
+
__author__ = "Hiroshi.tao <me@tcw.im>"
|
|
19
|
+
__version__ = "0.1.0"
|
|
20
|
+
__license__ = "BSD 3-Clause"
|
|
21
|
+
#__license_file__ = "LICENSE"
|
|
22
|
+
__readme_file__ = "README.md"
|
|
23
|
+
__url__ = "https://github.com/saintic/flask-pluginkit-accesscount"
|
|
24
|
+
__state__ = "enabled"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def get_time(fm="%Y-%m-%d %H:%M:%S"):
|
|
28
|
+
"""获取今天日期"""
|
|
29
|
+
return datetime.now().strftime(fm)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def record_ip_pv(response):
|
|
33
|
+
"""记录ip、ip"""
|
|
34
|
+
today = get_time("%Y%m%d")
|
|
35
|
+
prefix = current_app.config.get("PLUGINKIT_ACCESSCOUNT_KEY_PREFIX") or "pluginkit"
|
|
36
|
+
pvKey = (
|
|
37
|
+
current_app.config.get("PLUGINKIT_ACCESSCOUNT_PVKEY")
|
|
38
|
+
or f"{prefix}:AccessCount:pv:hash"
|
|
39
|
+
)
|
|
40
|
+
epKey = (
|
|
41
|
+
current_app.config.get("PLUGINKIT_ACCESSCOUNT_EPKEY")
|
|
42
|
+
or f"{prefix}:AccessCount:endpoint:hash"
|
|
43
|
+
)
|
|
44
|
+
conn_name = current_app.config.get("PLUGINKIT_ACCESSCOUNT_REDIS_CONN_NAME") or "redis"
|
|
45
|
+
redis_url = current_app.config.get("PLUGINKIT_ACCESSCOUNT_REDIS_URL")
|
|
46
|
+
redis_conn = getattr(g, conn_name, None)
|
|
47
|
+
if not redis_url and not redis_conn:
|
|
48
|
+
current_app.logger.error(
|
|
49
|
+
"AccessCount plugin not found valid redis url or connection."
|
|
50
|
+
)
|
|
51
|
+
return
|
|
52
|
+
storage = RedisStorage(redis_url=redis_url, redis_connection=redis_conn)
|
|
53
|
+
pipe = storage._db.pipeline()
|
|
54
|
+
pipe.hincrby(pvKey, today, 1)
|
|
55
|
+
if request.endpoint:
|
|
56
|
+
pipe.hincrby(epKey, "%s:%s" % (today, request.endpoint), 1)
|
|
57
|
+
try:
|
|
58
|
+
pipe.execute()
|
|
59
|
+
except Exception as e:
|
|
60
|
+
current_app.logger.error("AccessCount plugin write data failed", e)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def register():
|
|
64
|
+
return dict(hep=dict(after_request=record_ip_pv))
|
|
65
|
+
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: flask-pluginkit-accesscount
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: IP、PV、Endpoint Statistics
|
|
5
|
+
Home-page: https://github.com/saintic/flask-pluginkit-accesscount
|
|
6
|
+
Download-URL: https://github.com/saintic/flask-pluginkit-accesscount
|
|
7
|
+
Author: Hiroshi.tao
|
|
8
|
+
Author-email: me@tcw.im
|
|
9
|
+
Keywords: flask-pluginkit
|
|
10
|
+
Classifier: Environment :: Web Environment
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
21
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
22
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: Flask-PluginKit>=3.8.0
|
|
26
|
+
Dynamic: author
|
|
27
|
+
Dynamic: author-email
|
|
28
|
+
Dynamic: classifier
|
|
29
|
+
Dynamic: download-url
|
|
30
|
+
Dynamic: home-page
|
|
31
|
+
Dynamic: keywords
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
Dynamic: requires-dist
|
|
34
|
+
Dynamic: summary
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
setup.py
|
|
4
|
+
flask_pluginkit_accesscount/__init__.py
|
|
5
|
+
flask_pluginkit_accesscount.egg-info/PKG-INFO
|
|
6
|
+
flask_pluginkit_accesscount.egg-info/SOURCES.txt
|
|
7
|
+
flask_pluginkit_accesscount.egg-info/dependency_links.txt
|
|
8
|
+
flask_pluginkit_accesscount.egg-info/not-zip-safe
|
|
9
|
+
flask_pluginkit_accesscount.egg-info/requires.txt
|
|
10
|
+
flask_pluginkit_accesscount.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Flask-PluginKit>=3.8.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
flask_pluginkit_accesscount
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
import ast
|
|
5
|
+
from setuptools import setup
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _get_meta(meta):
|
|
9
|
+
"""Metadata can be obtained by this function
|
|
10
|
+
when the plugin cannot be imported directly.
|
|
11
|
+
|
|
12
|
+
version = _get_meta("version")
|
|
13
|
+
license = _get_meta("license")
|
|
14
|
+
description = _get_meta("description")
|
|
15
|
+
"""
|
|
16
|
+
pat = re.compile(r"__%s__\s+=\s+(.*)" % meta)
|
|
17
|
+
with open("flask_pluginkit_accesscount/__init__.py", "rb") as fh:
|
|
18
|
+
meta_str = ast.literal_eval(pat.search(fh.read().decode("utf-8")).group(1))
|
|
19
|
+
return str(meta_str)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _get_author():
|
|
23
|
+
mail_re = re.compile(r"(.*)\s<(.*)>")
|
|
24
|
+
author_email = _get_meta("author")
|
|
25
|
+
return (
|
|
26
|
+
mail_re.search(author_email).group(1),
|
|
27
|
+
mail_re.search(author_email).group(2),
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
(author, email) = _get_author()
|
|
32
|
+
setup(
|
|
33
|
+
name="flask-pluginkit-accesscount",
|
|
34
|
+
version=_get_meta("version"),
|
|
35
|
+
license_files=["LICENSE"],
|
|
36
|
+
author=author,
|
|
37
|
+
author_email=email,
|
|
38
|
+
url="https://github.com/saintic/flask-pluginkit-accesscount",
|
|
39
|
+
download_url="https://github.com/saintic/flask-pluginkit-accesscount",
|
|
40
|
+
keywords="flask-pluginkit",
|
|
41
|
+
description=_get_meta("description"),
|
|
42
|
+
packages=[
|
|
43
|
+
"flask_pluginkit_accesscount",
|
|
44
|
+
],
|
|
45
|
+
zip_safe=False,
|
|
46
|
+
include_package_data=True,
|
|
47
|
+
install_requires=["Flask-PluginKit>=3.8.0"],
|
|
48
|
+
classifiers=[
|
|
49
|
+
"Environment :: Web Environment",
|
|
50
|
+
"Intended Audience :: Developers",
|
|
51
|
+
"License :: OSI Approved :: BSD License",
|
|
52
|
+
"Operating System :: OS Independent",
|
|
53
|
+
"Programming Language :: Python :: 3",
|
|
54
|
+
"Programming Language :: Python :: 3.8",
|
|
55
|
+
"Programming Language :: Python :: 3.9",
|
|
56
|
+
"Programming Language :: Python :: 3.10",
|
|
57
|
+
"Programming Language :: Python :: 3.11",
|
|
58
|
+
"Programming Language :: Python :: 3.12",
|
|
59
|
+
"Programming Language :: Python :: Implementation :: CPython",
|
|
60
|
+
"Programming Language :: Python :: Implementation :: PyPy",
|
|
61
|
+
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
|
|
62
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
63
|
+
],
|
|
64
|
+
)
|