Skip to content

Commit

Permalink
Bugfix menu에 \n\n 2개 이상 나오는 문제 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
HoyoenKim committed Feb 2, 2023
1 parent df52355 commit 447bc48
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 29 deletions.
74 changes: 46 additions & 28 deletions parsing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
import os
import requests
import json
import pandas as pd
Expand Down Expand Up @@ -34,38 +35,55 @@ def parsing(excel_path: str, bldgType: int, langType: int) -> list:
parsing_result.append(meal.__dict__)

return parsing_result
if __name__ == "__main__":
excel_path = "./2학생회관.xlsx"

def parsingTest():
excel_dir_path = "./excel"
parsing_result = []

print("-------------------------------------------------")
print("parsing xlsx to json...")
parsing_result.extend(parsing(excel_path, BLDG2_1ST, KOR)) #2학 1층, 한글
parsing_result.extend(parsing(excel_path, BLDG2_1ST, ENG)) #2학 1층, 영어
for excel_filename in os.listdir(excel_dir_path):
excel_path = os.path.join(excel_dir_path, excel_filename)
parsing_result.extend(parsing(excel_path, BLDG2_1ST, KOR)) #2학 1층, 한글
parsing_result.extend(parsing(excel_path, BLDG2_1ST, ENG)) #2학 1층, 영어
print("-------------------------------------------------")
print("saving json...")
jsonFile = open("./2nd1floor_meal.json", "w", encoding="utf-8")
json.dump(parsing_result, jsonFile, indent=4,
ensure_ascii=False, cls=ComplexEncoder)
print("-------------------------------------------------")

if len(sys.argv) == 1:
# no url, save to local as json
print("-------------------------------------------------")
print("saving json...")
jsonFile = open("./2nd1floor_meal.json", "w", encoding="utf-8")
json.dump(parsing_result, jsonFile, indent=4,
ensure_ascii=False, cls=ComplexEncoder)
print("-------------------------------------------------")
elif len(sys.argv) == 2:
# post to server
url = sys.argv[1]
if __name__ == "__main__":
Mode = 0
if Mode == 0:
excel_path = "./2학생회관.xlsx"
parsing_result = []
print("-------------------------------------------------")
print("send to server...")
if url[0:4] != "http":
url = "http://localhost:8080/meals/test"
requests.post(url, data={"testStr": "Hello World!"})
else:
for meal_result in parsing_result:
print(meal_result)
response = requests.post(url, json=meal_result)
print(response)
print()
print("parsing xlsx to json...")
parsing_result.extend(parsing(excel_path, BLDG2_1ST, KOR)) #2학 1층, 한글
parsing_result.extend(parsing(excel_path, BLDG2_1ST, ENG)) #2학 1층, 영어
print("-------------------------------------------------")
None
if len(sys.argv) == 1:
# no url, save to local as json
print("-------------------------------------------------")
print("saving json...")
jsonFile = open("./2nd1floor_meal.json", "w", encoding="utf-8")
json.dump(parsing_result, jsonFile, indent=4,
ensure_ascii=False, cls=ComplexEncoder)
print("-------------------------------------------------")
elif len(sys.argv) == 2:
# post to server
url = sys.argv[1]
print("-------------------------------------------------")
print("send to server...")
if url[0:4] != "http":
url = "http://localhost:8080/meals/test"
requests.post(url, data={"testStr": "Hello World!"})
else:
for meal_result in parsing_result:
print(meal_result)
response = requests.post(url, json=meal_result)
print(response)
print()
print("-------------------------------------------------")
elif Mode == 1:
parsingTest()
3 changes: 2 additions & 1 deletion util.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def parsing_menu(row_range: list, data_sheet: list, langType: int):
for i in range(row_range[0], row_range[1]):
algy = add_allergy(data_sheet[i], langType)
menu_oneline = sanitize_menu(data_sheet[i])
menu += menu_oneline + algy + "\n"
menu += menu_oneline + algy
menu += "\n" if len(menu_oneline) > 0 else "";
return menu

def parsing_breakfast(endpoint: list, data_sheet: list, langType: int, dateType: int):
Expand Down

0 comments on commit 447bc48

Please sign in to comment.