Skip to content

Commit

Permalink
feat: add upload_to_xcpcio
Browse files Browse the repository at this point in the history
Signed-off-by: Dup4 <lyuzhi.pan@gmail.com>
  • Loading branch information
Dup4 committed May 24, 2024
1 parent f30e5d3 commit 387e132
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion xcpcio_board_spider/core/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


def init_logger():
logger = logging.getLogger(__name__)
logger = logging.getLogger()
logger.setLevel(logging.INFO)

formatter = logging.Formatter(
Expand Down
27 changes: 27 additions & 0 deletions xcpcio_board_spider/core/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import json
import time
import os
import logging
from typing import Dict
import requests

from xcpcio_board_spider import constants, Contest, Submissions


logger = logging.getLogger(__name__)


def json_input(path: str) -> None:
with open(path, 'r') as f:
return json.load(f)
Expand Down Expand Up @@ -94,3 +100,24 @@ def get_timestamp_from_iso8601(dt):

def get_now_timestamp_second():
return int(time.time())


def upload_to_xcpcio(token: str, files: Dict[str, str], url: str = "https://board-admin.xcpcio.com/upload-board-data"):
payload = {
"token": token,
"extra_files": files,
}
headers = {
"content-type": "application/json",
}
resp = requests.post(url, json=payload, headers=headers)
total_size = len(json.dumps(payload))

if resp.status_code == 200:
logger.info("upload successful. [resp={}] [size={}]".format(
resp.content, total_size))
else:
logger.error("upload failed. [status_code={}] [resp={}] [size={}]".format(
resp.status_code, resp.text, total_size))

return resp

0 comments on commit 387e132

Please sign in to comment.