From 9f00d43729c91fe61e0a6207ca2d351084edbe3f Mon Sep 17 00:00:00 2001 From: Pokpong Limpaphan <235639172+pokpong-dev@users.noreply.github.com> Date: Mon, 6 Oct 2025 23:55:13 +0700 Subject: [PATCH 1/8] update branch (#5) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Create CODEOWNERS * Create pull_request_template.md (#1) * Create CONTRIBUTING.md * Update CONTRIBUTING.md * Create __init__.py * Create file_handler.py * Create account.py * Create auth.py * Create main_program.py * Create smoke_check.yml * Update main_program.py * Update README.md * Update smoke_check.yml * Update smoke_check.yml * Rename smoke_check.yml to พี่ไม่ได้อยากเป็นเสือ.yml * Update พี่ไม่ได้อยากเป็นเสือ.yml * Update พี่ไม่ได้อยากเป็นเสือ.yml * Update README.md * Update main_program.py * Create icutmyhairyoudontcaremyheart * Rename icutmyhairyoudontcaremyheart to icutmyhairyoudontcaremyheart.yml * Update icutmyhairyoudontcaremyheart.yml --- .github/CODEOWNERS | 1 + .github/CONTRIBUTING.md | 81 ++++++++ .github/pull_request_template.md | 37 ++++ .../icutmyhairyoudontcaremyheart.yml | 66 +++++++ ...0\340\270\252\340\270\267\340\270\255.yml" | 173 ++++++++++++++++++ README.md | 3 + main_program.py | 8 + modules/__init__.py | 1 + modules/account.py | 2 + modules/auth.py | 2 + modules/file_handler.py | 2 + 11 files changed, 376 insertions(+) create mode 100644 .github/CODEOWNERS create mode 100644 .github/CONTRIBUTING.md create mode 100644 .github/pull_request_template.md create mode 100644 .github/workflows/icutmyhairyoudontcaremyheart.yml create mode 100644 ".github/workflows/\340\270\236\340\270\265\340\271\210\340\271\204\340\270\241\340\271\210\340\271\204\340\270\224\340\271\211\340\270\255\340\270\242\340\270\262\340\270\201\340\271\200\340\270\233\340\271\207\340\270\231\340\271\200\340\270\252\340\270\267\340\270\255.yml" create mode 100644 main_program.py create mode 100644 modules/__init__.py create mode 100644 modules/account.py create mode 100644 modules/auth.py create mode 100644 modules/file_handler.py diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..83fd8b3 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @pokpong-dev diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 0000000..c892498 --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,81 @@ +# คู่มือ +สำหรับโปรเจกต์: **ATM Simulation Program (CLI)** +กลุ่ท **Baan Dollar** G01 + +--- + +บทบาทแต่ละคน + +| บทบาท | หน้าที่หลัก | +|--------|--------------| +| @pokpong-dev | Admin / Reviewer / Merge PR | +| สมาชิกทีม | พัฒนาโมดูลตามที่ได้รับมอบหมาย | +... + +**แอดมิน (pokpong-dev)** เราจะเป็นคนตรวจสอบโค้ดให้พวกนายเอง +- Merge Pull Request เข้าสาขา `main` + + +--- + + + +### ขั้นตอนการใช้งาน github เบื้องต้น ### +```bash +git clone https://github.com/pokpong-dev/ATM_Simulation_Project.git +cd ATM_Simulation_Project +git pull origin main +``` + +จากนั้นเปลี่ยนเป็น branch ของตัวเอง + +### ตัวอย่าง ### +- feature/auth +- feature/account +- feature/main_program +- feature/file_handler + +### ห้ามแก้ไข main ให้ทำใน branch ตัวเองแล้วเปิด pr เดี๋ยวเราจะ review ให้) + +### วิธีเปิด Pull Request (PR) ### +ไปที่หน้า GitHub +จะเห็นปุ่ม Compare & pull request → กด +ตรวจว่า base = main, compare = feature/... +GitHub จะเติม template ให้อัตโนมัติ +เขียนรายละเอียดการเปลี่ยนแปลง +กด Create Pull Request +รอการตรวจโค้ดจากปกป้อง + + +ถ้ามีการแก้ไข → แก้ใน branch เดิมแล้ว push ใหม่ + + +### วิธีอัปเดตโค้ดจาก main ### + +หลัง merge เสร็จ ให้ทุกคนอัปเดต branch ตัวเองด้วย + +git checkout main +git pull +git checkout feature/<ชื่อ branch ตัวเอง> +git merge main + +กฎที่ต้องปฏิบัติ +push ตรงเข้า main main ถูกป้องกันไว้ +ลบ branch โดยไม่ merge งานหาย / เทสไม่ครบ +เปิด PR โดยไม่มีคำอธิบาย Reviewer ตรวจยาก + +การทดสอบอัตโนมัติ (GitHub Actions) +ทุก PR จะรัน test workflow อัตโนมัติจาก +ถ้าเทสไม่ผ่าน → PR จะขึ้น “❌ Checks failed” → Merge ไม่ได้ +ถ้าเทสผ่านทั้งหมด → “✅ All checks passed” → Reviewer สามารถ merge ได้ + + +อย่าลืม +ทำ commit ย่อย ๆ ดีกว่า commit ใหญ่ก้อนเดียว +อ่านคอมเมนต์ใน PR ทุกครั้งก่อน merge +ใช้ PR Template ที่เราให้เพื่ออธิบายงานชัดเจน +ถ้าไม่แน่ใจให้ tag เราได้เลย @pokpong-dev ไว้ในคอมเมนต์ + +ถ้าเจอข้อความ +“You can’t commit to main because it is a protected branch” +แปลว่า main ถูกป้องกันไม่ให้ commit ตรง เราตั้งใจเซ็ตไว้ เพราะว่าให้ทุกคนไปทำ feature/... แยกเป็นของตัวเอง diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..33c3773 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,37 @@ +## รายละเอียดการเปลี่ยนแปลง +> สรุปสิ่งที่แก้ไข เพิ่มเติม หรือลบออกใน Pull Request นี้ +> (สมมุติว่า ตัวอย่างเฉยๆนะเพื่อน เพิ่มระบบregister, ปรับปรุงการดักจับ error, แก้บั๊กถอนเงินไม่ถูกต้อง) + +เช็คลิสต์ตัวอย่างเอาไปปรับแก้ตามฟังชันที่ตัวเองทำนะเพื่อนน นายเก่งอยู่แล้วระดับนี้ +- [ ] เพิ่ม/แก้ไขฟังก์ชัน ... stuff like that +- [ ] แก้ไขไฟล์ ... something like that +- [ ] อัปเดต comment ในโค้ด + +--- + +## การทดสอบ +> อธิบายขั้นตอนการเทสในเครื่องของนายอะว่าฟังชันนายรันได้จริงป่าว ใส่ input ไรเข้าไปแล้วออกมายังไงไรงี้ +> เช่นแบบ รัน main_program.py แล้วเลือกเมนู Deposit, กรอก input เป็น string ให้มันผิด เพื่อดูว่าจับ error ได้จริงป่าว +> แล้วก็แบบโชว์ด้วยว่า output ออกมายังไง ตรงไหม + +> input +//นายใส่ตรงนี้เลยว่าใส่ไรเข้าไป + +> output +// นายใส่ตรงนี้ว่าอะไรมันออกมาแบบไหน แล้วตรงไหมหรือไม่ตรง + + +--- + +## เช็กลิสต์ก่อนขอรีวิว +- [ ] โค้ดผ่านการรันโดยไม่มี error +- [ ] ผ่าน test case ที่เกี่ยวข้อง +- [ ] ไม่มีการแก้ไฟล์ที่ไม่เกียวข้อง +- [ ] commit message ชัดเจน +- [ ] ตรวจสอบแล้วว่าไม่ conflict กับ main + +--- + +## cReviewer +@pokpong-dev +> เราจะเป็นตรวจโค้ดให้นายนะ ไม่ต้องร้อง เราเข้าใจ diff --git a/.github/workflows/icutmyhairyoudontcaremyheart.yml b/.github/workflows/icutmyhairyoudontcaremyheart.yml new file mode 100644 index 0000000..ab32cf4 --- /dev/null +++ b/.github/workflows/icutmyhairyoudontcaremyheart.yml @@ -0,0 +1,66 @@ +name: ประกาศสายตามเสียง + +on: + push: + branches: [ main ] + pull_request: + types: [opened, synchronize, closed] + +jobs: + ping_discord: + runs-on: ubuntu-latest + steps: + - name: เตรียมข้อความไปด่… เอ๊ย ไปแจ้ง + id: prep + run: | + set -e # ให้สคริปต์หยุดทันทีถ้ามี error + + if [[ "${{ github.event_name }}" == "push" ]]; then + # กรณี push + COMMIT_MSG=$(echo "${{ github.event.head_commit.message }}" | tr '\n' ' ') + MSG="มีการ push ใส่ branch **${{ github.ref_name }}** โดย **${{ github.actor }}** + **ข้อความ:** ${COMMIT_MSG:-"(ไม่มีข้อความคอมมิต)"} + **ดูการเปลี่ยนแปลง:** ${{ github.event.compare }}" + + else + # กรณี pull request + PR_ACTION="${{ github.event.action }}" + PR_MERGED="${{ github.event.pull_request.merged }}" + PR_NUM="${{ github.event.pull_request.number }}" + PR_TITLE=$(echo "${{ github.event.pull_request.title }}" | tr '\n' ' ') + + STATE="PR #${PR_NUM} (${PR_ACTION})" + if [[ "$PR_ACTION" == "closed" && "$PR_MERGED" == "true" ]]; then + STATE="✅ PR #${PR_NUM} ถูกรวม (merged) แล้ว" + elif [[ "$PR_ACTION" == "closed" ]]; then + STATE="❌ PR #${PR_NUM} ถูกปิด (closed) โดยไม่รวม" + fi + + MSG="${STATE} + **หัวข้อ:** ${PR_TITLE} + **ลิงก์:** ${{ github.event.pull_request.html_url }} + **คนก่อเรื่อง:** **${{ github.actor }}**" + fi + + # ส่งตัวแปร MSG เข้า GITHUB_ENV เพื่อให้ python เรียกใช้ได้ + echo "DISCORD_MESSAGE<> $GITHUB_ENV + echo "$MSG" >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV + + - name: สร้าง JSON Payload + id: json_payload + run: | + python -c ' + import json, os + msg = os.environ.get("DISCORD_MESSAGE", "") + payload = json.dumps({"content": msg}, ensure_ascii=False) + print(f"body={payload}") + ' >> "$GITHUB_OUTPUT" + + - name: ส่งเข้า Discord + env: + DISCORD_WEBHOOK_URL: ${{ secrets.pok }} + run: | + curl -sS -X POST "$DISCORD_WEBHOOK_URL" \ + -H "Content-Type: application/json" \ + -d '${{ steps.json_payload.outputs.body }}' diff --git "a/.github/workflows/\340\270\236\340\270\265\340\271\210\340\271\204\340\270\241\340\271\210\340\271\204\340\270\224\340\271\211\340\270\255\340\270\242\340\270\262\340\270\201\340\271\200\340\270\233\340\271\207\340\270\231\340\271\200\340\270\252\340\270\267\340\270\255.yml" "b/.github/workflows/\340\270\236\340\270\265\340\271\210\340\271\204\340\270\241\340\271\210\340\271\204\340\270\224\340\271\211\340\270\255\340\270\242\340\270\262\340\270\201\340\271\200\340\270\233\340\271\207\340\270\231\340\271\200\340\270\252\340\270\267\340\270\255.yml" new file mode 100644 index 0000000..4c97529 --- /dev/null +++ "b/.github/workflows/\340\270\236\340\270\265\340\271\210\340\271\204\340\270\241\340\271\210\340\271\204\340\270\224\340\271\211\340\270\255\340\270\242\340\270\262\340\270\201\340\271\200\340\270\233\340\271\207\340\270\231\340\271\200\340\270\252\340\270\267\340\270\255.yml" @@ -0,0 +1,173 @@ +name: ปกป้องร่างแยกให้ + +on: + push: + branches: [ main ] + pull_request: + +permissions: + contents: read + pull-requests: write + +jobs: + smoke: + name: ปกป้องร่างแยกกำลังอ่านโค้ดของคุณ + runs-on: ubuntu-latest + + steps: + - name: ตรวจ repo แปปนึงดิวะ + uses: actions/checkout@v4 + + - name: ลง python อยู่ใจเย็นดิ๊ + uses: actions/setup-python@v5 + with: + python-version: '3.13' + + - name: เช็ค python syntax รอก่อนนะแว่น + id: syntax + shell: bash + run: | + set +e + echo "ปกป้องร่างแยกกำลังตรวจ syntax ของพวกแก รอสักครู่ เดี๋ยวแว่นยังอ่านอยู่" + FILES="$(git ls-files '*.py')" + if [ -z "$FILES" ]; then + echo "ไม่มีไฟล์ .py เลย เอายังไงดีวะเนี่ย" | tee syntax_stdout.txt + : > syntax_stderr.txt + echo "status=passed" >> "$GITHUB_OUTPUT" + else + python -m py_compile $FILES 1>syntax_stdout.txt 2>syntax_stderr.txt + rc=$? + if [ $rc -eq 0 ]; then + echo "status=passed" >> "$GITHUB_OUTPUT" + else + echo "status=failed" >> "$GITHUB_OUTPUT" + fi + fi + + - name: ตรวจว่า import ครบไหมวะเนี่ย + id: importcheck + shell: bash + run: | + set +e + echo "แว่นกำลังดูว่าพวกแก import ถูกไหม เดี๋ยวดูหน่อยสิ..." + if [ ! -f main_program.py ]; then + echo "main_program.py หายอีกละ เอาไปซ่อนไหน" | tee import_result.txt + echo "status=failed" >> "$GITHUB_OUTPUT" + else + if grep -q "^from modules import file_handler, auth, account" main_program.py; then + echo "โอเคนะ เห็น import ครบอยู่ แว่นไม่บ่น" | tee import_result.txt + echo "status=passed" >> "$GITHUB_OUTPUT" + else + echo "ไหนวะ import modules... file_handler, auth, account มันอยู่ไหน หาไม่เจอเลย" | tee import_result.txt + echo "status=failed" >> "$GITHUB_OUTPUT" + fi + fi + + - name: ส่งให้สรัลเทส main_program.py + id: runprog + shell: bash + run: | + set +e + echo "สรัลกำลังรัน main_program.py... ขอให้รอด" + if [ -f main_program.py ]; then + python main_program.py 1>program_stdout.txt 2>program_stderr.txt + rc=$? + else + echo "หา main_program.py ไม่เจอเลยพวก เอาไปไว้ไหนเนี่ย" | tee program_stderr.txt + : > program_stdout.txt + rc=127 + fi + + if [ ${rc} -eq 0 ]; then + echo "status=passed" >> "$GITHUB_OUTPUT" + echo "exit_code=0" >> "$GITHUB_OUTPUT" + else + echo "status=failed" >> "$GITHUB_OUTPUT" + echo "exit_code=${rc}" >> "$GITHUB_OUTPUT" + fi + + - name: สรุปผลเป็น Markdown + id: report + shell: bash + run: | + SYNTAX_STATUS="${{ steps.syntax.outputs.status }}" + IMPORT_STATUS="${{ steps.importcheck.outputs.status }}" + RUN_STATUS="${{ steps.runprog.outputs.status }}" + EXIT_CODE="${{ steps.runprog.outputs.exit_code }}" + + OVERALL="passed" + if [ "$SYNTAX_STATUS" != "passed" ] || [ "$IMPORT_STATUS" != "passed" ] || [ "$RUN_STATUS" != "passed" ]; then + OVERALL="failed" + fi + + { + echo "# รายงานจากปกป้องร่างแยก (แว่นฉุนโหมด)" + echo + echo "- Syntax Check: ${SYNTAX_STATUS}" + echo "- Import Check: ${IMPORT_STATUS}" + echo "- Run main_program.py: ${RUN_STATUS} (exit code: ${EXIT_CODE:-N/A})" + echo "- Overall: ${OVERALL}" + echo + echo "## ผลการตรวจ import" + echo '```' + cat import_result.txt || true + echo '```' + echo + echo "## Syntax stdout" + echo '```' + cat syntax_stdout.txt || true + echo '```' + echo + echo "## Syntax stderr" + echo '```' + cat syntax_stderr.txt || true + echo '```' + echo + echo "## Program stdout (main_program.py)" + echo '```' + cat program_stdout.txt || true + echo '```' + echo + echo "## Program stderr (main_program.py)" + echo '```' + cat program_stderr.txt || true + echo '```' + } > report.md + + cat report.md >> "$GITHUB_STEP_SUMMARY" + echo "overall=${OVERALL}" >> "$GITHUB_OUTPUT" + + - name: คอมเมนต์ผลใน PR + if: ${{ github.event_name == 'pull_request' }} + uses: marocchino/sticky-pull-request-comment@v2 + with: + header: "ผลตรวจจากปกป้องร่างแยก" + message: | + $(if [ "${{ steps.report.outputs.overall }}" = "passed" ]; then + echo "ผ่านว่ะ โครตเจ๋ง รอบนี้แว่นไม่บ่น ขอรหัส 4 ตัวท้ายด้วยจะหักคะแนนความดีแทน" + else + echo "ยังไม่รอด แว่นอ่านแล้วปวดหัว ไปดู import modules ด้วย error ยุ ไปนู่นไปรำคาญ" + fi) + + ------------------------------------------------------------ + รายงานฉบับเต็ม (อย่าขี้เกียจอ่าน) + ------------------------------------------------------------ + $(cat report.md) + + - name: เก็บไฟล์ output + uses: actions/upload-artifact@v4 + with: + name: smoke-outputs + path: | + syntax_stdout.txt + syntax_stderr.txt + program_stdout.txt + program_stderr.txt + import_result.txt + report.md + + - name: ตัดสินใจผ่านไม่ผ่าน + if: ${{ steps.report.outputs.overall == 'failed' }} + run: | + echo "แว่นบอกไม่ผ่าน ยังไม่รอด อย่าลืม import ให้ครบด้วยนะ รำคาญ" + exit 1 diff --git a/README.md b/README.md index 73f8918..e5c3082 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +## Project Current Status ## +[![ปกป้องร่างแยกให้](https://github.com/pokpong-dev/ATM_Simulation_Project/actions/workflows/%E0%B8%9E%E0%B8%B5%E0%B9%88%E0%B9%84%E0%B8%A1%E0%B9%88%E0%B9%84%E0%B8%94%E0%B9%89%E0%B8%AD%E0%B8%A2%E0%B8%B2%E0%B8%81%E0%B9%80%E0%B8%9B%E0%B9%87%E0%B8%99%E0%B9%80%E0%B8%AA%E0%B8%B7%E0%B8%AD.yml/badge.svg)](https://github.com/pokpong-dev/ATM_Simulation_Project/actions/workflows/%E0%B8%9E%E0%B8%B5%E0%B9%88%E0%B9%84%E0%B8%A1%E0%B9%88%E0%B9%84%E0%B8%94%E0%B9%89%E0%B8%AD%E0%B8%A2%E0%B8%B2%E0%B8%81%E0%B9%80%E0%B8%9B%E0%B9%87%E0%B8%99%E0%B9%80%E0%B8%AA%E0%B8%B7%E0%B8%AD.yml) + # ATM Simulation Program (Command Line Interface) โครงงานรายวิชา SC361002 การเขียนโปรแกรมเชิงโครงสร้างสำหรับเทคโนโลยีสารสนเทศ diff --git a/main_program.py b/main_program.py new file mode 100644 index 0000000..919fed1 --- /dev/null +++ b/main_program.py @@ -0,0 +1,8 @@ +from modules import file_handler, auth, account + +def main(): + print("SARAN O.K") + print("yim") + +if __name__ == "__main__": + main() diff --git a/modules/__init__.py b/modules/__init__.py new file mode 100644 index 0000000..f307358 --- /dev/null +++ b/modules/__init__.py @@ -0,0 +1 @@ +# modules/__init__.py diff --git a/modules/account.py b/modules/account.py new file mode 100644 index 0000000..e9732ee --- /dev/null +++ b/modules/account.py @@ -0,0 +1,2 @@ +# modules/account.py +# พวกระบบบัญชี (ยังไม่ทำจริง แค่โครง) diff --git a/modules/auth.py b/modules/auth.py new file mode 100644 index 0000000..87afaed --- /dev/null +++ b/modules/auth.py @@ -0,0 +1,2 @@ +# modules/auth.py +# พวกระบบล็อคอิน/เปิดบัญชี (ยังไม่ทำจริง แค่โครง) diff --git a/modules/file_handler.py b/modules/file_handler.py new file mode 100644 index 0000000..656dc6a --- /dev/null +++ b/modules/file_handler.py @@ -0,0 +1,2 @@ +# modules/file_handler.py +# ตัวจัดการไฟล์ (ยังไม่ทำจริง แค่โครง) From f42fb4cd44babfd15b39011ca08889f4f1a909b1 Mon Sep 17 00:00:00 2001 From: chitsanupongkiw Date: Tue, 7 Oct 2025 11:09:31 +0700 Subject: [PATCH 2/8] Update1 main_program.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit แก้ไปแล้ว printอะเห็นป่าว --- main_program.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main_program.py b/main_program.py index 919fed1..01f466a 100644 --- a/main_program.py +++ b/main_program.py @@ -1,7 +1,8 @@ from modules import file_handler, auth, account def main(): - print("SARAN O.K") + print("pok") + print("s"a) print("yim") if __name__ == "__main__": From ee741848ca10c1d52159ab92614aade480e9b22d Mon Sep 17 00:00:00 2001 From: perawitsimla Date: Tue, 7 Oct 2025 11:10:58 +0700 Subject: [PATCH 3/8] Update 1+2 main_program.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit print บรรทัด 7 --- main_program.py | 1 + 1 file changed, 1 insertion(+) diff --git a/main_program.py b/main_program.py index 01f466a..5b80d63 100644 --- a/main_program.py +++ b/main_program.py @@ -4,6 +4,7 @@ def main(): print("pok") print("s"a) print("yim") + print("tod sob") if __name__ == "__main__": main() From 990c3f52df8115695508ee56dcb6b29e0e7244ac Mon Sep 17 00:00:00 2001 From: perawitsimla Date: Tue, 7 Oct 2025 11:13:56 +0700 Subject: [PATCH 4/8] Update 222 main_program.py WOW --- main_program.py | 1 + 1 file changed, 1 insertion(+) diff --git a/main_program.py b/main_program.py index 5b80d63..8a74c2d 100644 --- a/main_program.py +++ b/main_program.py @@ -5,6 +5,7 @@ def main(): print("s"a) print("yim") print("tod sob") + print("tod sob22222") if __name__ == "__main__": main() From ff464b2a7e67f4d11f0ad029fbc3a4f82f7c5e9d Mon Sep 17 00:00:00 2001 From: perawitsimla Date: Tue, 7 Oct 2025 11:17:58 +0700 Subject: [PATCH 5/8] Update Hello wrold main_program.py Hello world --- main_program.py | 1 + 1 file changed, 1 insertion(+) diff --git a/main_program.py b/main_program.py index 8a74c2d..8f8919c 100644 --- a/main_program.py +++ b/main_program.py @@ -6,6 +6,7 @@ def main(): print("yim") print("tod sob") print("tod sob22222") + print("Hello World") if __name__ == "__main__": main() From c021a218dbcf3379b9614aab4b2d60f74675cff6 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Tue, 7 Oct 2025 14:13:14 +0700 Subject: [PATCH 6/8] testtt --- main_program.py | 1 + 1 file changed, 1 insertion(+) diff --git a/main_program.py b/main_program.py index 8d707af..5673136 100644 --- a/main_program.py +++ b/main_program.py @@ -4,6 +4,7 @@ def main(): print("SARAN O.K") print("yim") print("title lover ขุนแพน") + #testkub if __name__ == "__main__": main() From 00c9ce3531219f48c7eab87fe294e5e5953c82d1 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Fri, 10 Oct 2025 21:26:04 +0700 Subject: [PATCH 7/8] =?UTF-8?q?main=20program=20=E0=B8=97=E0=B8=B1?= =?UTF-8?q?=E0=B9=89=E0=B8=87=E0=B8=AB=E0=B8=A1=E0=B8=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main_program.py | 108 +++++++++++++++++++++++++++++++++++++++++++- modules/__init__.py | 2 +- modules/account.py | 24 +++++----- modules/auth.py | 22 +++++---- 4 files changed, 132 insertions(+), 24 deletions(-) diff --git a/main_program.py b/main_program.py index cfe6271..cc91ad5 100644 --- a/main_program.py +++ b/main_program.py @@ -1,2 +1,108 @@ -#from modules import atm_file_handler, auth, account +from modules import atm_file_handler, auth, account +import datetime +def main(): + while True: + print("""==== ATM Simulation ==== + [1] Login + [2] Register + [3] Exit""") + menu = input("Enter menu number:").strip() + if menu == "1": + account_number = input("Enter account number: ").strip() + pin = input("Enter PIN number: ").strip() + login_result = auth.login(account_number, pin) + print(login_result["msg"]) + if login_result["status"] == "success": + main_menu(account_number) + elif menu == "2": + check_title = True + title = input("Enter title (MR/MS): ").strip() + if title != "MR" and title != "MS": + print("Select title MR or MS") + check_title = False + if check_title: + first_name = input("Enter first name: ").strip() + last_name = input("Enter last name: ").strip() + pin = input("Enter 6-digit PIN: ").strip() + register_result = auth.register(title, first_name, last_name, pin) + print(type(register_result["msg"])) + elif menu == "3": + print("Goodbye") + break + else: + print("Invalid menu number, please try again.") + +#ใบเสร็จ Receipt +def receipt(account_number,menu_type ,amount , account_numberv2=None): + #อ่านธุรกรรม + try: + transactions = atm_file_handler.read_transaction_file(account_number) + if not transactions: + print("ไม่พบบัญชีหรือไม่มีธุรกรรม") + return + lol_transaction = transactions[-1].strip().split(",") + transaction_id = lol_transaction[0] + timestamp = lol_transaction[1] + balance = lol_transaction[2] + account_numberv2_acc = account_numberv2 if account_numberv2 else "None" + print(f"""==== {menu_type} ==== +Time: {timestamp} +Account: {account_number} +Amount: {amount} +Target: {account_numberv2_acc} +Transaction ID: {transaction_id} +Balance: {balance} + ================""") + except FileNotFoundError: + print("ไม่พบไฟล์ธุรกรรมของบัญชีนี้") + + +#หน้า Main Menu +def main_menu(account_number): + while True: + print(f"""==== Main Menu (Account: {account_number}) ==== +[1] Check Balance +[2] Deposit +[3] Withdraw +[4] Transfer +[5] Transactions history +[6] Logout""") + choice = input("Enter menu number:").strip() + if choice == "1": + balance = account.check_balance(account_number) + #if balance is None: + print(balance) + elif choice == "2": + print(type(account_number)) + print(account_number) + amount = float(input("Enter deposit amount (100, 500, 1000 banknote only): ")) + print(amount) + result = account.add_transaction_firstdeposit(account_number, amount) + result = account.add_transaction_deposit(account_number, amount) + receipt(account_number, "Deposit", amount) + print(result["msg"]) + elif choice == "3": + amount = float(input("Enter withdraw amount: ")) + result = account.add_transaction_withdrawal(account_number, amount) + receipt(account_number, "Withdrawal", amount) + print(result["msg"]) + elif choice == "4": + account_numberv2 = input("Enter recipient account number: ").strip() + amount = float(input("Enter transfer amount: ")) + result = account.add_transaction_transfer(account_number,account_numberv2,amount) + receipt(account_number, "Transfer", amount, account_numberv2) + print(result["msg"]) + elif choice == "5": + transactions = atm_file_handler.read_transaction_file(account_number) + print("==== Transactions history ====") + for t in transactions: + print(t.strip()) + elif choice == "6": + print("Logging out...") + break + else: + print("Invalid menu number, please try again.") + +main() +#main_menu("123456789") \ No newline at end of file diff --git a/modules/__init__.py b/modules/__init__.py index 97830d3..869c41a 100644 --- a/modules/__init__.py +++ b/modules/__init__.py @@ -1,5 +1,5 @@ # modules/__init__.py -_all_ = [ +__all__ = [ 'atm_file_handler', 'auth', 'account', diff --git a/modules/account.py b/modules/account.py index 55aba60..ee02b2c 100644 --- a/modules/account.py +++ b/modules/account.py @@ -27,11 +27,11 @@ def add_transaction_deposit(account_number,amount): if i == lol - 1: decimal1 = float(cut1) plus_num += decimal1 - timestamps = datetime.datetime.now().isoformat() + timestamps = str(datetime.datetime.now()) atm_file_handler.append_transaction_log_file( account_number=account_number, transaction_id=gen_transaction_id, - timestamp=timestamps[0:19], + timestamp=timestamps, type_i="deposit", amount=amount, balance= amount+plus_num, @@ -58,11 +58,11 @@ def add_transaction_firstdeposit(account_number,amount): except: checkfile = True if check == True and checkfile == True: - timestamps = datetime.datetime.now().isoformat() + timestamps = str(datetime.datetime.now()) atm_file_handler.append_transaction_log_file( account_number=account_number, transaction_id=gen_transaction_id, - timestamp=timestamps[0:19], + timestamp=timestamps, type_i="deposit", amount=amount, balance=amount, @@ -85,13 +85,13 @@ def add_transaction_withdrawal(account_number,amount): if i == lol - 1: decimal1 = float(cut1) plus_num += decimal1 - timestamps = datetime.datetime.now().isoformat() + timestamps = str(datetime.datetime.now()) if amount > plus_num: return {"status":"error","msg":"ยอดเงินไม่เพียง่พอ"} atm_file_handler.append_transaction_log_file( account_number=account_number, transaction_id=gen_transaction_id, - timestamp=timestamps[0:19], + timestamp=timestamps, type_i="withdrawal", amount=-abs(amount), balance= plus_num-amount, @@ -111,7 +111,7 @@ def check_balance(account_number): if i == lol - 1: return {"status":"success","msg":acc_num} except FileNotFoundError: - return {"status":"error","msg":"ไม่พบบัญชี"} + return {"status":"error","msg":"ไม่พบบัญชีหรือธุรกรรม"} #โอนเงิน def add_transaction_transfer(account_number,account_numberv2,amount): @@ -127,13 +127,13 @@ def add_transaction_transfer(account_number,account_numberv2,amount): if i == lol - 1: decimal1 = float(cut1) plus_num += decimal1 - timestamps = datetime.datetime.now().isoformat() + timestamps = str(datetime.datetime.now()) if amount > plus_num: return {"status":"error","msg":"ยอดเงินไม่เพียงพอ"} atm_file_handler.append_transaction_log_file( account_number=account_number, transaction_id=gen_transaction_id, - timestamp=timestamps[0:19], + timestamp=timestamps, type_i="transfer", amount=-abs(amount), balance= plus_num-amount, @@ -156,9 +156,9 @@ def check_transaction_history(account_number): #kplus = check_transaction_history("123-4-56789-0") #print(kplus) -#x = add_transaction_firstdeposit(account_number="123-4-56789-0",amount=20000.0) -#y = add_transaction_deposit("123-4-56789-0",3000.00) -#m = add_transaction_withdrawal("123-4-56789-0",500.00) +# x = add_transaction_firstdeposit(account_number="870-9-74830-6",amount=20000.0) +# y = add_transaction_deposit("870-9-74830-6",3000.00) +# m = add_transaction_withdrawal("870-9-74830-6",500.00) #print(m) #print(x) # atm_file_handler.append_account_file( diff --git a/modules/auth.py b/modules/auth.py index 575aab4..47bb639 100644 --- a/modules/auth.py +++ b/modules/auth.py @@ -1,9 +1,16 @@ from modules import atm_file_handler import random -from datetime import datetime +import datetime -def register(title, first_name, last_name, account_number, pin): +def register(title, first_name, last_name, pin): #title ถ้าไม่ได้รับ MR หรือ ms + # สุ่มเลขบัญชี + acc_nums1 = random.randint(0, 999) + acc_nums2 = random.randint(0, 9) + acc_nums3 = random.randint(0, 99999) + acc_nums4 = random.randint(0, 9) + account_number = f"{acc_nums1:03}-{acc_nums2}-{acc_nums3:05}-{acc_nums4}" + lol=["MR", "MS"] if title != "MR" and title != "MS": return {"status": "error", "msg": "Select title MR or MS"} @@ -39,16 +46,11 @@ def register(title, first_name, last_name, account_number, pin): if not pin.isdigit(): return {"status": "error", "msg": "กรอกเป็นตัวเลขเท่านั้น"} - #สุ่มเลขบัญชี - acc_nums1 = random.randint(0, 999) - acc_nums2 = random.randint(0, 9) - acc_nums3 = random.randint(0, 99999) - acc_nums4 = random.randint(0, 9) - account_number = f"{acc_nums1:03}-{acc_nums2}-{acc_nums3:05}-{acc_nums4}" + #เวลา - timestamps = datetime.datetime.now().isoformat() - created_at = timestamps[0:19] + #timestamps = datetime.datetime.now() + created_at = str(datetime.datetime.now()) #เพิ่มข้อมูลเข้าไฟ atm_file_handler.append_account_file(title, first_name, last_name, account_number, pin, created_at) From ddb9fc78a122b62eebd7b129daa3931ce6c639ec Mon Sep 17 00:00:00 2001 From: BuildTools Date: Fri, 10 Oct 2025 21:46:47 +0700 Subject: [PATCH 8/8] =?UTF-8?q?Withdraw,=20Deposit=20=E0=B8=A3=E0=B8=B1?= =?UTF-8?q?=E0=B8=9A=E0=B9=80=E0=B8=89=E0=B8=9E=E0=B8=B2=E0=B8=B0=20100,?= =?UTF-8?q?=20500,=201000?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main_program.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/main_program.py b/main_program.py index cc91ad5..15be402 100644 --- a/main_program.py +++ b/main_program.py @@ -74,19 +74,29 @@ def main_menu(account_number): #if balance is None: print(balance) elif choice == "2": - print(type(account_number)) - print(account_number) + check_amount = True amount = float(input("Enter deposit amount (100, 500, 1000 banknote only): ")) - print(amount) - result = account.add_transaction_firstdeposit(account_number, amount) - result = account.add_transaction_deposit(account_number, amount) - receipt(account_number, "Deposit", amount) - print(result["msg"]) + if amount % 100 != 0: + print("100, 500, 1000 banknote only") + check_amount = False + if check_amount: + balance = account.check_balance(account_number) + print(balance) + print(amount) + result = account.add_transaction_firstdeposit(account_number, amount) + result = account.add_transaction_deposit(account_number, amount) + receipt(account_number, "Deposit", amount) + print(result["msg"]) elif choice == "3": + check_amount = True amount = float(input("Enter withdraw amount: ")) - result = account.add_transaction_withdrawal(account_number, amount) - receipt(account_number, "Withdrawal", amount) - print(result["msg"]) + if amount % 100 != 0: + print("100, 500, 1000 banknote only") + check_amount = False + if check_amount: + result = account.add_transaction_withdrawal(account_number, amount) + receipt(account_number, "Withdrawal", amount) + print(result["msg"]) elif choice == "4": account_numberv2 = input("Enter recipient account number: ").strip() amount = float(input("Enter transfer amount: "))