download-flow-enmu 0.1.0__py3-none-any.whl → 0.1.1__py3-none-any.whl

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.
cli/download_cmd.py CHANGED
@@ -1,6 +1,7 @@
1
1
  import typer
2
- import json
3
2
  import logging
3
+ import sys
4
+ import json
4
5
  from pathlib import Path
5
6
  from pydantic import TypeAdapter
6
7
  from factory import downloader_factory, email_factory, provider_factory
@@ -12,22 +13,21 @@ from cli.root import app
12
13
  def run(provider: str):
13
14
  # 配置日志
14
15
  logging.basicConfig(
15
- level=logging.INFO,
16
- format='%(levelname)s: %(message)s'
16
+ level=logging.ERROR, stream=sys.stderr, format="%(levelname)s: %(message)s"
17
17
  )
18
-
19
18
  config_path = Path.home() / ".flow" / "config.json"
20
-
19
+
21
20
  logging.info(f"开始下载 {provider} 账单...")
22
21
  logging.info(f"配置文件路径: {config_path}")
23
22
 
24
23
  try:
25
24
  # 使用 ConfigLoader 加载配置(支持环境变量替换)
26
- from config.loader import load_config
25
+ from config.loader import load_config
26
+
27
27
  config_json = load_config(config_path)
28
-
28
+
29
29
  logging.info(f"配置加载成功")
30
-
30
+
31
31
  adapter = TypeAdapter(PayConfig)
32
32
  config_obj = adapter.validate_python(config_json[provider])
33
33
  downloader = downloader_factory.creat_downloader(config_obj.download)
@@ -41,9 +41,22 @@ def run(provider: str):
41
41
  provider_obj.bill = config_obj.profile
42
42
 
43
43
  logging.info(f"开始执行下载...")
44
- provider_obj.process_bills()
44
+ is_success = provider_obj.process_bills()
45
+
45
46
  logging.info(f"✅ 下载完成!")
46
47
 
48
+ if is_success:
49
+
50
+ return {
51
+ "status": "success",
52
+ "provider": provider,
53
+ }
54
+ else:
55
+ return {
56
+ "status": "fail",
57
+ "provider": provider,
58
+ }
59
+
47
60
  except FileNotFoundError as e:
48
61
  logging.error(f"配置文件未找到: {config_path}")
49
62
  raise
@@ -61,4 +74,11 @@ def download(
61
74
  str, typer.Option("--provider", "-p", help="config file")
62
75
  ] = "alipay",
63
76
  ):
64
- run(provider)
77
+
78
+ try:
79
+ result = run(provider)
80
+ typer.echo(json.dumps(result, ensure_ascii=False))
81
+ except Exception as e:
82
+ error_result = {"status": "error", "provider": provider, "message": str(e)}
83
+ typer.echo(json.dumps(error_result, ensure_ascii=False))
84
+ raise typer.Exit(code=1)
cli/main.py CHANGED
@@ -1,4 +1,4 @@
1
- from .root import app
1
+ from cli.root import app
2
2
 
3
3
  from cli.download_cmd import download
4
4
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: download-flow-enmu
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: A task flow management tool for syncing todo files with taskwarrior
5
5
  Author-email: Your Name <your.email@example.com>
6
6
  Classifier: Development Status :: 3 - Alpha
@@ -1,6 +1,6 @@
1
1
  cli/__init__.py,sha256=I9Hh5zrDiIh_ocW0Ra3I-pV0VAJrl1dwLEmCbX-NDn4,14
2
- cli/download_cmd.py,sha256=kuobLGli_nbrLeeoU1U4GFe46fYDtyj3K4Nlr-KjMhY,1951
3
- cli/main.py,sha256=zC--P4_g2EtDaiHO0hyBx_4Y458C9YMtl7pDY6Xd84M,125
2
+ cli/download_cmd.py,sha256=HSZnpK5wrrl3laj2K3o3LcYL-Z8T3DiZCR746N0Yl-g,2510
3
+ cli/main.py,sha256=BOnRpFwm5tzlUg0m9UWqqHB7NI_RRE8tkwCUiMBeL5k,128
4
4
  cli/root.py,sha256=TlMsPrPVwiIl64ZuwixmftVpmqRwoPmgFLDwKxrzgPY,513
5
5
  config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  config/loader.py,sha256=sHueTVLT-spMWn-8Eq2RancJIkVKpgD3XHJIqW3h8SI,1793
@@ -11,15 +11,15 @@ factory/provider_factory.py,sha256=oe7oDyCIBeFTjQTGJY0gxkcgrGdhhvOfxS_mZSnooWc,2
11
11
  package/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
12
  package/downfile.py,sha256=7qnDJeh1sGnRZDYOPZ5f5QsHuck2iAdfXOIWD6NG3RE,6501
13
13
  strategy/downloader/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
- strategy/downloader/attchment.py,sha256=v6CQwnyKLLoaTk_4q3K99SUuCoSHo4JSHPr4i05a1JM,1545
14
+ strategy/downloader/attchment.py,sha256=wegb6hM1QvoOskFi5uVGCsspvzgFy_Zj0H6X6jf8Ir8,1519
15
15
  strategy/downloader/provider.py,sha256=YasGNxaYvvUgHQxPck8GkD5FW7pCyR9DS9JrbyUTYT4,225
16
16
  strategy/email/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
17
  strategy/email/email_provider.py,sha256=aoGFk_D2nifwGQZFi8LH6Xu-2_CHqCWMJSYaIPjKIu0,151
18
18
  strategy/email/gmail.py,sha256=-DJiv6f8VbY0ZCdz7rbikfv1PWgkQ5qr3hwkgH06xAI,458
19
- strategy/provider/ali_provider.py,sha256=WvEeeDsWUVxBMsSQNHSQe36ANyFk1ulevi_J1NGvgpA,797
19
+ strategy/provider/ali_provider.py,sha256=43rb5QqIjZ3TQAKOJUJar43RRD60wPZO5-HCJeW8Euw,804
20
20
  strategy/provider/provider.py,sha256=DHBGAr2dfw0W0XULwLd8DwzZY_VH4qEV5tarx8hUU_o,122
21
- download_flow_enmu-0.1.0.dist-info/METADATA,sha256=VGpCyPLOgmHZcqZsbchSUUlGzj3oXlBYz_iehdnyUnE,1969
22
- download_flow_enmu-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
23
- download_flow_enmu-0.1.0.dist-info/entry_points.txt,sha256=8SQ6Y1ma7AZSTzdbb0fRbAzeCKnxtNYchJjhi4ciosw,40
24
- download_flow_enmu-0.1.0.dist-info/top_level.txt,sha256=lAF0lGukoa1q1EfG1UxNkro603Rnr3H0HaXMu9hDAno,41
25
- download_flow_enmu-0.1.0.dist-info/RECORD,,
21
+ download_flow_enmu-0.1.1.dist-info/METADATA,sha256=hD21rwWDJQBJlZ6PWSZX8c1Wq_lHDxnfoVVlWDHanhw,1969
22
+ download_flow_enmu-0.1.1.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
23
+ download_flow_enmu-0.1.1.dist-info/entry_points.txt,sha256=8SQ6Y1ma7AZSTzdbb0fRbAzeCKnxtNYchJjhi4ciosw,40
24
+ download_flow_enmu-0.1.1.dist-info/top_level.txt,sha256=lAF0lGukoa1q1EfG1UxNkro603Rnr3H0HaXMu9hDAno,41
25
+ download_flow_enmu-0.1.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.9.0)
2
+ Generator: setuptools (80.10.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -17,25 +17,29 @@ class AttchmentDownloader(Downloader):
17
17
  date=datetime.date.today(),
18
18
  )
19
19
 
20
+ downloaded_count = 0
21
+
20
22
  for msg in mail.fetch(criteria=criteria):
21
23
  logging.info(f"找到邮件: {msg.subject}") # 添加这一行
22
24
 
23
25
  if bill.search_subject not in msg.subject:
24
26
  continue
25
27
  for att in msg.attachments:
26
- if att.filename.lower().endswith(bill.file_suffix):
27
- bill.save_subdir.mkdir(parents=True, exist_ok=True)
28
- filepath = (
29
- bill.save_subdir / f"{datetime.date.today()}.{bill.file_suffix}"
30
- ) # 改这里:加扩展名
31
-
32
- try:
33
- if bill.file_suffix in ["zip", "7z", "rar"]:
34
- filepath.write_bytes(att.payload)
35
- else:
36
- content_str = att.payload.decode(bill.encoding)
37
- filepath.write_text(content_str, encoding="utf-8")
38
- except UnicodeDecodeError:
39
- logging.error(" ✗ 转码失败")
40
- else:
41
- logging.info(f"✗ 附件类型不匹配 (期望后缀: {bill.file_suffix})")
28
+ if not att.filename.lower().endswith(bill.file_suffix):
29
+ continue
30
+ bill.save_subdir.mkdir(parents=True, exist_ok=True)
31
+ filepath = (
32
+ bill.save_subdir / f"{datetime.date.today()}.{bill.file_suffix}"
33
+ )
34
+
35
+ try:
36
+ if bill.file_suffix in ["zip", "7z", "rar"]:
37
+ filepath.write_bytes(att.payload)
38
+ else:
39
+ content_str = att.payload.decode(bill.encoding)
40
+ filepath.write_text(content_str, encoding="utf-8")
41
+ downloaded_count += 1
42
+ except UnicodeDecodeError:
43
+ logging.error(" 转码失败")
44
+ continue
45
+ return downloaded_count > 0
@@ -28,4 +28,4 @@ class AliProvider(Provider):
28
28
  mailbox = self.email.connect()
29
29
 
30
30
  with mailbox.login(self.email.username, self.email.password, "INBOX") as mb:
31
- self.downloader.download(mb, bill=self.bill)
31
+ return self.downloader.download(mb, bill=self.bill)