跳转到内容
项目模板·Pro

Python CSV 报表

把销售 CSV 变成终端摘要和带柱状图的 HTML 页面的脚本:按月、类别和产品汇总。只用标准库,附带示例数据和测试。需要 Linux 环境中的 Python。

安装它需要 PocketCode Pro。

如果你的 Android 设备上装了 PocketCode,这会在应用里打开此页面。

预览

文件

README.md
data/sales.csv
report.py
tests/__init__.py
tests/test_report.py

README.md

# Sales report from a CSV, in Python A script that reads a CSV of sales and gives you two things: a summary in the terminal (revenue, units, median sale, totals per month and per category) and `report.html`, a page with bar charts that works offline. It only uses Python's standard library (csv, decimal, statistics, html): nothing to install with pip. Sample data is included. ## Run it in PocketCode You need the app's Linux environment with Python 3.10 or newer: install it in Settings › Compilers and runtimes, or with the Developer pack in Terminal › Linux. When you tap Run, the first line of the Run panel should say Python 3 (Linux). 1. Open `report.py` and tap Run. The Run panel prints the summary and writes `report.html`. 2. Open `report.html` and tap the globe icon (DevBrowser) at the top of the editor to see the charts. With your own data, from the terminal (Open Terminal Here, in the editor menu): ```sh python3 report.py my-sales.csv -o my-report.html ``` The CSV needs these columns: `date` (YYYY-MM-DD), `product`, `category`, `units`, `unit_price`. A wrong line stops the script and says which line it is. ## Run the tests ```sh python3 -m unittest -v ``` ## Where things are | Path | What it does | |---|---| | `report.py` | Reading the CSV, the totals, the terminal summary and the HTML | | `data/sales.csv` | Sample data: 32 sales over three months | | `tests/test_report.py` | Tests with unittest |

此预览已截短。安装后可获得完整内容。

1.0.0 的变更

首个版本。

相关

Python + SQLite 命令行工具Pro项目模板终端里的记账工具:添加和列出支出、按月按类别汇总、导出 CSV。只用标准库(argparse、sqlite3),无需用 pip 安装任何东西,并附带 unittest 测试。需要 Linux 环境中的 Python。Flask + SQLite 网页应用Pro项目模板用 Flask 写的阅读清单:服务端渲染页面和普通表单,数据存入 SQLite,另有一个小型 JSON API。测试使用 Flask 的测试客户端。需要 Linux 环境中的 Python 和 pip,会安装 7 个固定版本的包。FastAPI 短链接服务Pro项目模板用 Python、FastAPI 和 SQLite 写的短链接服务。生成短代码、跳转并统计点击,附带单页表单和 pytest 测试。需要 Linux 环境中的 Python 3.10 或更新版本及 pip;会安装 14 个固定版本的包。Next.js + Tailwind + i18nPro项目模板Next.js 15 项目,带 next-intl 和 Tailwind CSS,在 /en 和 /es 提供一个英语和西班牙语页面。深色模式跟随系统。需要带 Node.js 的 Linux 环境;首次 npm install 约下载 400 MB。静态落地页Pro项目模板纯 HTML 和 CSS 编写的单页网站:带折叠菜单的页头、首屏、功能网格、常见问题和页脚。颜色跟随系统的浅色或深色模式。无需构建,也不需要 Linux:打开 index.html,点地球图标即可。Rust 命令行:行数统计Pro项目模板用 Rust 写的命令行工具,按语言统计文件夹里的代码行、注释行和空行。这是一个没有依赖的 Cargo 项目,带单元测试。需要 Linux 环境中的 Rust 和 Cargo(约 370 MB)。