Files
streamlit-cicd/app/app.py
2024-07-25 11:39:44 +09:00

58 lines
1.6 KiB
Python

import streamlit as st
import pandas as pd
import requests
import os
import git
import json
token = os.environ['GIT_TOKEN']
user = os.environ['GIT_USER']
url = os.environ['GIT_URL']
repo_url = f'https://{user}:{token}@{url}'
local_path = 'repo'
# JSON 데이터 가져오기
if os.path.exists(local_path):
repo = git.Repo(local_path)
repo.remote().pull()
else:
repo = git.Repo.clone_from(repo_url, local_path)
json_file_path = os.path.join(local_path, 'test_json.json')
with open(json_file_path, 'r', encoding='utf-8') as file:
data = json.load(file)
df = pd.DataFrame(data)
st.title('버전 관리')
cols = st.columns([5,5])
edited_df = cols[0].data_editor(df,
key="version_table",
hide_index=True,
column_config={
'name': st.column_config.TextColumn(label='이름', disabled=True),
'version': st.column_config.TextColumn(label='버전', disabled=False),
}
)
cols[1].write(st.session_state["version_table"]["edited_rows"])
button_cols = st.columns([1, 1])
with button_cols[0]:
if st.button('새로고침'):
repo = git.Repo(local_path)
repo.remote().pull()
st.success("새로고침 완료")
with button_cols[1]:
if st.button('업데이트'):
edited_df.to_json(json_file_path, orient='records', indent=4)
repo.index.add(["/app/"+json_file_path])
repo.index.commit("버전 업데이트")
repo.remote().push()
st.success("업데이트 완료")