Skip to content

Commit 1a941de

Browse files
committed
Finish up serverless logic
1 parent 631dda2 commit 1a941de

File tree

2 files changed

+15
-23
lines changed

2 files changed

+15
-23
lines changed

serverless/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
GitPython==3.1.40
2-
pycryptodome==3.18.0
2+
python-dotenv==1.0.0

serverless/run.py

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
BASE_URL = os.environ.get("BASE_URL")
1111
PASSWORD_HEADER = os.environ.get("PASSWORD_HEADER")
1212

13-
14-
1513
def make_api_request(request_data):
1614

1715
# Make an HTTP POST request to the API
@@ -20,17 +18,14 @@ def make_api_request(request_data):
2018
print (request_data)
2119
response = requests.post(url, json=request_data, headers={"PASSWORD_HEADER": PASSWORD_HEADER})
2220
response.raise_for_status() # Raise an exception for HTTP errors (4xx and 5xx)
21+
22+
print(f"API response status: {response.status_code}")
23+
print(f"API response: {response.json()}")
24+
return
2325

24-
# Handle the API response here
25-
response_data = response.json()
26-
return response_data
2726
except requests.exceptions.RequestException as e:
2827
print(f"Error making the API request: {e}")
29-
return None
3028

31-
32-
33-
3429
def load_problems():
3530
with tempfile.TemporaryDirectory() as base_path:
3631
Repo.clone_from("https://github.com/kyle8998/Practice-Coding-Questions.git", base_path)
@@ -63,24 +58,30 @@ def load_problems():
6358
def parse(qn):
6459
try:
6560
qn = qn.split("\n")
61+
6662
title = qn[0][2:]
6763
qn.pop(0)
64+
6865
while qn[0].strip() == "":
6966
qn.pop(0)
67+
7068
difficulty = qn[0].split(" ")[2].strip().upper()
69+
difficulty = difficulty[0].upper() + difficulty[1:].lower()
70+
7171
qn.pop(0)
7272
while qn[0].strip() == "":
7373
qn.pop(0)
7474

75-
if difficulty not in ["EASY", "MEDIUM", "HARD"]:
75+
qn = '\n'.join(qn)
76+
77+
if difficulty not in ["Easy", "Medium", "Hard"]:
7678
return None
7779

7880
if title.split(" ")[0] != "Problem" and title.split(" ")[1][-1] != ":":
7981
return None
8082
else:
8183
title = " ".join(title.split(" ")[2:])
8284

83-
qn = '\n'.join(qn)
8485

8586
search_space = title + qn
8687
tags = []
@@ -91,23 +92,14 @@ def parse(qn):
9192
if tags == []:
9293
return None
9394

94-
return { "title": title, "difficulty": difficulty, "question": qn, "tags": tags}
95+
return { "title": title, "difficulty": difficulty, "description": qn, "tags": tags}
9596
except:
9697
return None
9798

98-
def send_to_questions_service(qn):
99-
data = {}
100-
data['title'] = qn["title"]
101-
data['difficulty'] = qn["difficulty"][0].upper() + qn["difficulty"][1:].lower()
102-
data['description'] = qn["question"]
103-
data['tags'] = qn["tags"]
104-
105-
response = make_api_request(data)
106-
10799
problems = load_problems()
108100
problems = [parse(qn) for qn in problems]
109101
problems = [qn for qn in problems if qn is not None]
110102
print(f"Total number of questions parsed: {len(problems)}")
111103

112104
for qn in [problems[3]]:
113-
send_to_questions_service(qn)
105+
make_api_request(qn)

0 commit comments

Comments
 (0)