diff --git a/.github/action-build/Dockerfile b/.github/action-build/Dockerfile new file mode 100644 index 0000000..b1fd227 --- /dev/null +++ b/.github/action-build/Dockerfile @@ -0,0 +1,5 @@ +FROM python + + +COPY entrypoint /usr/local/bin/entrypoint +ENTRYPOINT ["/usr/local/bin/entrypoint"] \ No newline at end of file diff --git a/.github/action-build/action.yml b/.github/action-build/action.yml new file mode 100644 index 0000000..49eb252 --- /dev/null +++ b/.github/action-build/action.yml @@ -0,0 +1,6 @@ +name: Action Build +description: build holidays.json + +runs: + using: docker + image: Dockerfile diff --git a/.github/action-build/entrypoint b/.github/action-build/entrypoint new file mode 100644 index 0000000..5edff67 --- /dev/null +++ b/.github/action-build/entrypoint @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +python build.py \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..4a6a02a --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,18 @@ +name: Workflow build + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v1 + - name: build + uses: ./.github/action-build/ + - name: commit changes + uses: EndBug/add-and-commit@v4 + with: + message: "[Workflow] build" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 091429a..e18bf37 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -1,7 +1,7 @@ # This workflow will install Python dependencies, run tests and lint with a single version of Python # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python -name: build +name: Test on: push: @@ -34,6 +34,6 @@ jobs: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - name: Test with pytest + - name: build holidays.json run: | python test.py diff --git a/README.md b/README.md index 0dc44ba..80acc75 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,19 @@ -[![status workflow](https://github.com/guangrei/APIHariLibur_V2/actions/workflows/python-app.yml/badge.svg)](https://github.com/guangrei/APIHariLibur_V2/actions) +[![status workflow](https://github.com/guangrei/APIHariLibur_V2/actions/workflows/build.yml/badge.svg)](https://github.com/guangrei/APIHariLibur_V2/actions) APIHariLibur_V2 adalah peningkatan dari api [Json Indonesia holiday](https://github.com/guangrei/Json-Indonesia-holidays). data masih bersumber dari google calendar dan otomatis diperbarui. +## Hari Libur + Perayaan + calendar.json: https://raw.githubusercontent.com/guangrei/APIHariLibur_V2/main/calendar.json calendar.min.json: https://raw.githubusercontent.com/guangrei/APIHariLibur_V2/main/calendar.min.json +## Hari Libur only + +holidays.json: https://raw.githubusercontent.com/guangrei/APIHariLibur_V2/main/holidays.json + ### Showcase - [pytanggalmerah](https://github.com/guangrei/pytanggalmerah) (lib python) diff --git a/build.py b/build.py new file mode 100644 index 0000000..b8f226e --- /dev/null +++ b/build.py @@ -0,0 +1,52 @@ +#-*-coding:utf8;-*- +import json +from datetime import datetime + +# Informasi kredit tentang kode +credit = { + "updated": datetime.now().strftime("%Y%m%d %H:%I:%S"), + "author": "guangrei", + "link": "https://github.com/guangrei"} + +# Membaca konten dari file "calendar.json" dan menguraikannya menjadi bentuk dictionary Python +with open("calendar.json", "r") as f: + js = json.loads(f.read()) + +# Menghapus kunci "info" dari dictionary "js" +del js["info"] +out = {} + + +def get_holiday(des, sum): + """ + Fungsi untuk mendapatkan hari libur dari deskripsi dan ringkasan yang diberikan. + + Parameters: + des (list): Daftar deskripsi yang berisi kata "libur" atau tidak. + sum (list): Daftar ringkasan hari yang sesuai dengan deskripsi. + + Returns: + str: Ringkasan hari libur jika ditemukan, jika tidak kembali None. + """ + i = 0 + for cek in des: + if "libur" in cek.lower(): + return sum[i] + else: + i = i + 1 + + +# Iterasi melalui setiap kunci dan nilai dalam dictionary "js" +for k, v in js.items(): + if v["holiday"]: + out[k] = {} + # Mendapatkan ringkasan hari libur menggunakan fungsi get_holiday + out[k]["summary"] = get_holiday(v["description"], v["summary"]) + +# Menambahkan informasi kredit ke dictionary "out" +out["info"] = credit + +# Mengkonversi dictionary "out" menjadi format JSON dan menyimpannya di file "holidays.json" +s = json.dumps(out, sort_keys=True) +with open("holidays.json", "w") as f: + f.write(s)