Skip to content

Commit 4839570

Browse files
committed
Merge remote-tracking branch 'origin/develop' into develop
# Conflicts: # crawling/koreatech_article/table.py
2 parents 4feddff + 5ce3c39 commit 4839570

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

crawling/koreatech_article/article.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
from bs4 import BeautifulSoup, Comment
99
import urllib3
1010
import pymysql
11+
import uuid
1112

1213
from delete_article import delete_article
13-
from table import replace_table
14+
from table import replace_table, upload_txt
1415
from login_v2 import login
1516
from login import get_jwt_token
1617
from slack_notice import filter_nas, notice_to_slack
@@ -285,6 +286,11 @@ def crawling_article(board: Board, host: str, url: str) -> Article:
285286
# 표 처리
286287
# content = replace_table(content, board, num)
287288

289+
# content s3 업로드 및 url 삽입
290+
random_uuid = str(uuid.uuid4().hex)
291+
file_name = f'articles/content/board_{board.id}/{random_uuid}.txt'
292+
content = upload_txt(file_name=file_name, text_content=content)
293+
288294
# ===== 첨부 파일 =====
289295
attachment = list(map(
290296
lambda tag: Attachment(

crawling/koreatech_article/table.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,27 @@ def upload_image(s3, file_name: str, image: bytes) -> str:
105105
print(e)
106106

107107
return f'{S3_CONFIG["upload_domain"]}/{file_name}'
108+
109+
110+
def upload_txt(file_name: str, text_content: str) -> str:
111+
s3 = boto3.client(
112+
service_name='s3',
113+
aws_access_key_id=S3_CONFIG['aws_access_key_id'],
114+
aws_secret_access_key=S3_CONFIG['aws_secret_access_key'],
115+
)
116+
encoded_text = text_content.encode('utf-8')
117+
118+
try:
119+
s3.upload_fileobj(
120+
Fileobj=BytesIO(encoded_text),
121+
Bucket=S3_CONFIG['bucket'],
122+
Key=file_name,
123+
ExtraArgs={
124+
'ContentType': 'text/plain; charset=utf-8',
125+
'ACL': 'public-read'
126+
}
127+
)
128+
except Exception as e:
129+
print(e)
130+
131+
return f'{S3_CONFIG["upload_domain"]}/{file_name}'

0 commit comments

Comments
 (0)