Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Am K committed Jul 25, 2023
1 parent 3c7eb35 commit c00c949
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .github/action-build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM python


COPY entrypoint /usr/local/bin/entrypoint
ENTRYPOINT ["/usr/local/bin/entrypoint"]
6 changes: 6 additions & 0 deletions .github/action-build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: Action Build
description: build holidays.json

runs:
using: docker
image: Dockerfile
3 changes: 3 additions & 0 deletions .github/action-build/entrypoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env sh

python build.py
18 changes: 18 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -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 }}
4 changes: 2 additions & 2 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
52 changes: 52 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit c00c949

Please sign in to comment.