Skip to content

Commit 4495769

Browse files
committed
Create file for sending post requests
1 parent acea198 commit 4495769

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

test_server.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import requests
2+
from datetime import datetime
3+
from pprint import pprint
4+
import json
5+
6+
start_time = datetime.now()
7+
8+
def send():
9+
10+
# url = "http://127.0.0.1:7851/api/tts-generate/"
11+
12+
url = "http://127.0.0.1:8000/api/synthesize/"
13+
14+
txt1 = "1번. 또 파이썬은 순수한 프로그램 언어로서의 기능 외에도 다른 언어로 쓰인 모듈들을 연결하는 접착제 언어로써 자주 이용된다. 실제 파이썬은 많은 상용 응용 프로그램에서 스크립트 언어로 채용되고 있다. 도움말 문서도 정리가 잘 되어 있으며, 유니코드 문자열을 지원해서 다양한 언어의 문자 처리에도 능하다."
15+
txt2 = "2번. 파이썬에서는 들여쓰기를 사용해서 블록을 구분하는 독특한 문법을 채용하고 있다. 이 문법은 파이썬에 익숙한 사용자나 기존 프로그래밍 언어에서 들여쓰기의 중요성을 높이 평가하는 사용자에게는 잘 받아들여지고 있지만, 다른 언어의 사용자에게서는 프로그래머의 코딩 스타일을 제한한다는 비판도 많다."
16+
txt3 = "3번. 파이썬은 1980년대 말 고안되어 네덜란드 CWI의 귀도 반 로섬이 1989년 12월 구현하기 시작하였다. 이는 역시 SETL에서 영감을 받은 ABC 언어의 후계로서 예외 처리가 가능하고, 아메바 OS와 연동이 가능하였다. 반 로섬은 파이썬의 주 저자로 계속 중심적 역할을 맡아 파이썬의 방향을 결정하여, 파이썬 공동체로부터 '자선 종신 이사'의 칭호를 부여받았다. 이 같은 예로는 리눅스의 리누스 토발즈 등이 있다."
17+
18+
txt_arr = [txt1, txt2, txt3]
19+
20+
21+
current_datetime = datetime.now()
22+
date_format = current_datetime.strftime("%Y%m%d%H%M%S")
23+
date_format = date_format + str(current_datetime.microsecond)
24+
25+
# data = {
26+
# "voice": {
27+
# "languageCode": "ko-KR",
28+
# "name": "ko-KR-Standard-B"
29+
# },
30+
# "input": {
31+
# "ssml":txt1
32+
# },
33+
# "audioConfig":{"audioEncoding":"mp3",
34+
# "effectsProfileId":"telephony-class-application"
35+
# }
36+
# }
37+
38+
data = {
39+
"languageCode": "ko-KR",
40+
"name": "ko-KR-Standard-B",
41+
"text": str(txt1)
42+
}
43+
44+
#convert data to json
45+
46+
47+
try:
48+
response = requests.post(url, data=json.dumps(data), verify=False)
49+
response.raise_for_status()
50+
# print(response)
51+
# rsp = response.text
52+
# pprint(rsp)
53+
54+
with open('somefile.txt', 'a') as the_file:
55+
the_file.write(response.text)
56+
57+
except requests.exceptions.RequestException as e:
58+
print(f"Request error: {e}")
59+
except ValueError as e:
60+
print(f"JSON parsing error: {e}")
61+
except Exception as e:
62+
print(f"An error occurred: {e}")
63+
64+
if __name__ == "__main__":
65+
send()
66+
print(f"Elapsed time: {datetime.now() - start_time}")
67+
68+
69+
70+
71+
72+

0 commit comments

Comments
 (0)