donlad-stats 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.
- donlad_stats-0.1.0/PKG-INFO +11 -0
- donlad_stats-0.1.0/README.md +0 -0
- donlad_stats-0.1.0/donlad_stats/__init__.py +5 -0
- donlad_stats-0.1.0/donlad_stats/cli.py +29 -0
- donlad_stats-0.1.0/donlad_stats/core.py +74 -0
- donlad_stats-0.1.0/donlad_stats.egg-info/PKG-INFO +11 -0
- donlad_stats-0.1.0/donlad_stats.egg-info/SOURCES.txt +11 -0
- donlad_stats-0.1.0/donlad_stats.egg-info/dependency_links.txt +1 -0
- donlad_stats-0.1.0/donlad_stats.egg-info/entry_points.txt +2 -0
- donlad_stats-0.1.0/donlad_stats.egg-info/requires.txt +1 -0
- donlad_stats-0.1.0/donlad_stats.egg-info/top_level.txt +1 -0
- donlad_stats-0.1.0/setup.cfg +4 -0
- donlad_stats-0.1.0/setup.py +17 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: donlad_stats
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: donlad 下载量统计工具(SQLite + JSON + TXT)
|
|
5
|
+
Author: shiroko
|
|
6
|
+
Requires-Python: >=3.6
|
|
7
|
+
Requires-Dist: donlad
|
|
8
|
+
Dynamic: author
|
|
9
|
+
Dynamic: requires-dist
|
|
10
|
+
Dynamic: requires-python
|
|
11
|
+
Dynamic: summary
|
|
File without changes
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
import argparse
|
|
3
|
+
from donlad.cli import load_config
|
|
4
|
+
from .core import Stats
|
|
5
|
+
|
|
6
|
+
def main():
|
|
7
|
+
parser = argparse.ArgumentParser(description="donlad 统计工具")
|
|
8
|
+
parser.add_argument("--save", action="store_true", help="查询所有已添加模块并保存")
|
|
9
|
+
parser.add_argument("--packages", nargs="+", help="临时指定模块列表")
|
|
10
|
+
args = parser.parse_args()
|
|
11
|
+
|
|
12
|
+
if args.save:
|
|
13
|
+
config = load_config()
|
|
14
|
+
pkgs = config.get("packages", [])
|
|
15
|
+
if not pkgs:
|
|
16
|
+
print("暂无模块,请先用 donlad add 添加")
|
|
17
|
+
return
|
|
18
|
+
stats = Stats(pkgs)
|
|
19
|
+
stats.run_all()
|
|
20
|
+
stats.close()
|
|
21
|
+
elif args.packages:
|
|
22
|
+
stats = Stats(args.packages)
|
|
23
|
+
stats.run_all()
|
|
24
|
+
stats.close()
|
|
25
|
+
else:
|
|
26
|
+
parser.print_help()
|
|
27
|
+
|
|
28
|
+
if __name__ == "__main__":
|
|
29
|
+
main()
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import time
|
|
2
|
+
import secrets
|
|
3
|
+
import sqlite3
|
|
4
|
+
import os
|
|
5
|
+
import json
|
|
6
|
+
from datetime import datetime
|
|
7
|
+
from donlad import get_downloads_robust as get_downloads
|
|
8
|
+
|
|
9
|
+
DEFAULT_CONFIG_DIR = os.path.expanduser("~/.donlad_stats")
|
|
10
|
+
DB_PATH = os.path.join(DEFAULT_CONFIG_DIR, "downloads.db")
|
|
11
|
+
JSON_PATH = os.path.join(DEFAULT_CONFIG_DIR, "downloads.json")
|
|
12
|
+
TXT_PATH = os.path.join(DEFAULT_CONFIG_DIR, "downloads.txt")
|
|
13
|
+
|
|
14
|
+
os.makedirs(DEFAULT_CONFIG_DIR, exist_ok=True)
|
|
15
|
+
|
|
16
|
+
def randint(a, b):
|
|
17
|
+
return a + secrets.randbelow(b - a + 1)
|
|
18
|
+
|
|
19
|
+
class Stats:
|
|
20
|
+
def __init__(self, packages=None):
|
|
21
|
+
self.packages = packages or []
|
|
22
|
+
self.conn = sqlite3.connect(DB_PATH)
|
|
23
|
+
self._init_db()
|
|
24
|
+
self.now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
25
|
+
|
|
26
|
+
def _init_db(self):
|
|
27
|
+
c = self.conn.cursor()
|
|
28
|
+
c.execute("""
|
|
29
|
+
CREATE TABLE IF NOT EXISTS stats (
|
|
30
|
+
name TEXT PRIMARY KEY,
|
|
31
|
+
downloads INTEGER,
|
|
32
|
+
time TEXT
|
|
33
|
+
)
|
|
34
|
+
""")
|
|
35
|
+
self.conn.commit()
|
|
36
|
+
|
|
37
|
+
def _update_now(self):
|
|
38
|
+
self.now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
39
|
+
|
|
40
|
+
def fetch(self, pkg):
|
|
41
|
+
self._update_now()
|
|
42
|
+
downloads = get_downloads(pkg)
|
|
43
|
+
c = self.conn.cursor()
|
|
44
|
+
c.execute("INSERT OR REPLACE INTO stats VALUES (?, ?, ?)", (pkg, downloads, self.now))
|
|
45
|
+
self.conn.commit()
|
|
46
|
+
return downloads
|
|
47
|
+
|
|
48
|
+
def save_json(self):
|
|
49
|
+
data = {}
|
|
50
|
+
c = self.conn.cursor()
|
|
51
|
+
c.execute("SELECT name, downloads, time FROM stats")
|
|
52
|
+
for name, downloads, t in c.fetchall():
|
|
53
|
+
data[name] = {"downloads": downloads, "time": t}
|
|
54
|
+
with open(JSON_PATH, "w", encoding="utf-8") as f:
|
|
55
|
+
json.dump(data, f, ensure_ascii=False, indent=2)
|
|
56
|
+
|
|
57
|
+
def save_txt(self):
|
|
58
|
+
c = self.conn.cursor()
|
|
59
|
+
c.execute("SELECT name, downloads, time FROM stats")
|
|
60
|
+
rows = c.fetchall()
|
|
61
|
+
with open(TXT_PATH, "w", encoding="utf-8") as f:
|
|
62
|
+
for name, downloads, t in rows:
|
|
63
|
+
f.write(f"name:{name}\ndownloads:{downloads}\ntime:{t}\n\n")
|
|
64
|
+
|
|
65
|
+
def run_all(self, delay_range=(1, 3)):
|
|
66
|
+
for pkg in self.packages:
|
|
67
|
+
time.sleep(randint(*delay_range))
|
|
68
|
+
downloads = self.fetch(pkg)
|
|
69
|
+
print(f"['name:{pkg}']\n['{pkg} download:{downloads}']\n")
|
|
70
|
+
self.save_json()
|
|
71
|
+
self.save_txt()
|
|
72
|
+
|
|
73
|
+
def close(self):
|
|
74
|
+
self.conn.close()
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: donlad_stats
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: donlad 下载量统计工具(SQLite + JSON + TXT)
|
|
5
|
+
Author: shiroko
|
|
6
|
+
Requires-Python: >=3.6
|
|
7
|
+
Requires-Dist: donlad
|
|
8
|
+
Dynamic: author
|
|
9
|
+
Dynamic: requires-dist
|
|
10
|
+
Dynamic: requires-python
|
|
11
|
+
Dynamic: summary
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
setup.py
|
|
3
|
+
donlad_stats/__init__.py
|
|
4
|
+
donlad_stats/cli.py
|
|
5
|
+
donlad_stats/core.py
|
|
6
|
+
donlad_stats.egg-info/PKG-INFO
|
|
7
|
+
donlad_stats.egg-info/SOURCES.txt
|
|
8
|
+
donlad_stats.egg-info/dependency_links.txt
|
|
9
|
+
donlad_stats.egg-info/entry_points.txt
|
|
10
|
+
donlad_stats.egg-info/requires.txt
|
|
11
|
+
donlad_stats.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
donlad
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
donlad_stats
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name="donlad_stats",
|
|
5
|
+
version="0.1.0",
|
|
6
|
+
author="shiroko",
|
|
7
|
+
description="donlad 下载量统计工具(SQLite + JSON + TXT)",
|
|
8
|
+
packages=find_packages(),
|
|
9
|
+
install_requires=["donlad"],
|
|
10
|
+
entry_points={
|
|
11
|
+
"console_scripts": [
|
|
12
|
+
"donlad-stats = donlad_stats.cli:main",
|
|
13
|
+
]
|
|
14
|
+
},
|
|
15
|
+
python_requires=">=3.6",
|
|
16
|
+
)
|
|
17
|
+
|