\n"
+ event_fraction = str(event).split("\t")
+ for i in event_fraction:
+ if i != "" and i != "\n" and i != "---":
+ if "|" in i and not i.endswith("|"):
+ # CHANGE
+ spl_text = i.split("|")
+ html_string += "\t\t
"+spl_text[0]+"
\n"
+ html_string += "\t\t
"+spl_text[1].replace("\n","")+"
\n"
+ elif ">>>" in i:
+ # INSERT
+ spl_text = i.split(">>>")
+ html_string += "\t\t
"+spl_text[0]+"
\n"
+ html_string += "\t\t
"+spl_text[1].replace("\n","")+"
\n"
+ elif i.endswith("|"):
+ html_string += "\t\t
"+i[:-1]+"
\n"
+ else:
+ # print("Default = ", i)
+ # Either version, status or others
+
+ html_string += "\t\t
"+i.replace("\n","")+"
\n"
+ html_string += "\t
\n"
+
+ outlogHtml.write(html_string)
+
+
+
# Merge dictionary - called by `merge`, using when the value is `dict` type
# original - main file to merge/append value into
@@ -271,7 +242,7 @@ def merge_dicts(original:dict, updated:dict, path=""):
lc = last_change if last_change != "" else pre_timestamp
try:
if debug == "debug":
- print("Encounter path --> "+path, " | master: ",original[key]," dev: ", value)
+ print("Encounter path --> "+current_path, " | master: ",original[key]," dev: ", value)
except:
pass
if "Recipe01" in current_path and not "recipes" in current_path:
@@ -348,23 +319,13 @@ def merge_lists(original, updated, path=""):
pdadd += 1
original.append(item)
-
-
def main():
command_line = sys.argv[1]
- if command_line == "name":
- UnifyGen.GetFileSheet("menu-name", ".menu-name.tsv")
- ImportFileAndUpdateMenuName( 529, ".menu-name.tsv", CoffeeRecipeDirectory + "/coffeethai02_530.json")
+ print(sys.argv)
if command_line == "merge":
- dev_version = sys.argv[2]
merge(sys.argv[2:])
+
if __name__ == "__main__":
- main()
-
-
-
-
-#./import_price.py ~/cofffeemachineConfig/profile_MYR/profile_MYR_1.json ~/Downloads/MYS\ Taobin\ Menu\ with\ price.xlsx\ -\ 28_Mar_2023.tsv F ~/cofffeemachineConfig/profile_MYR/profile_MYR_1_3.json
-
+ main()
\ No newline at end of file
diff --git a/server/server.go b/server/server.go
index d0232f6..3ddf6a5 100644
--- a/server/server.go
+++ b/server/server.go
@@ -9,6 +9,7 @@ import (
"net/url"
"os"
"os/exec"
+ "path/filepath"
"recipe-manager/config"
"recipe-manager/data"
"recipe-manager/routers"
@@ -77,9 +78,8 @@ func (s *Server) createHandler() {
AllowedOrigins: strings.Split(s.cfg.AllowedOrigins, ","),
AllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"},
AllowCredentials: true,
- AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
- MaxAge: 300, // Maximum value not ignored by any of major browsers
- // Debug: true,
+ ExposedHeaders: []string{"Content-Type"},
+ AllowedMethods: []string{"GET", "POST", "PUT", "DELETE"},
}))
database := data.NewData()
@@ -92,6 +92,7 @@ func (s *Server) createHandler() {
// Protect Group
r.Group(func(r chi.Router) {
+
r.Use(func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -121,11 +122,8 @@ func (s *Server) createHandler() {
})
})
- // Recipe Router
- rr := routers.NewRecipeRouter(database)
- rr.Route(r)
-
r.Post("/merge", func(w http.ResponseWriter, r *http.Request) {
+
var targetMap map[string]interface{}
err := json.NewDecoder(r.Body).Decode(&targetMap)
if err != nil {
@@ -133,38 +131,72 @@ func (s *Server) createHandler() {
log.Fatalln("Merge request failed: ", err)
return
}
- log.Println(targetMap)
+ repo_path := "cofffeemachineConfig/coffeethai02_"
+
master_version := targetMap["master"].(string)
dev_version := targetMap["dev"].(string)
+ output_path := targetMap["output"].(string)
+ changelog_path := targetMap["changelog"].(string)
// find target file in the cofffeemachineConfig
- if _, err := os.Stat("coffeemachineConfig/coffeethai02_" + master_version + ".json"); err != nil {
+ if _, err := os.Stat(repo_path + master_version + ".json"); err != nil {
w.WriteHeader(http.StatusBadRequest)
log.Fatalln("Merge request failed. Master file not found: ", err)
return
}
- if _, err := os.Stat("coffeemachineConfig/coffeethai02_" + dev_version + ".json"); err != nil {
+ if _, err := os.Stat(repo_path + dev_version + ".json"); err != nil {
w.WriteHeader(http.StatusBadRequest)
log.Fatalln("Merge request failed. Dev file not found: ", err)
return
}
- repo_path := "coffeemachineConfig/coffeethai02_"
master_path := repo_path + master_version + ".json"
dev_path := repo_path + dev_version + ".json"
- // output path
- output_path := ""
+ // // output path
+ // output_path := ""
- // changelog path
- changelog_path := ""
+ // // changelog path
+ // changelog_path := ""
// TODO: Call merge api if found
- err = exec.Command("python", "merge", master_path, dev_path, output_path, changelog_path).Run()
+
+ // lookup for python exec
+ py_exec, err := exec.LookPath("python")
+ if err != nil {
+ log.Fatalln("Python error: ", err)
+ } else {
+ py_exec, err = filepath.Abs(py_exec)
+ }
+
+ log.Println("Found python exec: ", py_exec)
+ // target api file
+ merge_api, api_err := os.Open("./python_api/merge_recipe.py")
+ if api_err != nil {
+ log.Fatalln("Merge request failed. Python api error: ", api_err)
+ }
+ log.Println("Locate python api", merge_api.Name())
+ cmd := exec.Command(py_exec, merge_api.Name(), "merge", master_path, dev_path, output_path, changelog_path, "debug")
+
+ log.Println("Run merge command", cmd)
+ err = cmd.Run()
if err != nil {
log.Fatalln("Merge request failed. Python merge failed: ", err)
}
+
+ w.Header().Add("Content-Type", "application/json")
+ w.WriteHeader(http.StatusOK)
+ json.NewEncoder(w).Encode(map[string]string{"message": "Merge success"})
+
})
+
+ r.Get("/dllog", func(w http.ResponseWriter, r *http.Request) {
+
+ })
+ // Recipe Router
+ rr := routers.NewRecipeRouter(database)
+ rr.Route(r)
+
})
r.NotFound(func(w http.ResponseWriter, r *http.Request) {