Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified internal/create-buggy-pr.sh
100644 → 100755
Empty file.
35 changes: 14 additions & 21 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
PORT = 3000


def convert_celsius_to_fahrenheit(celsius):
return (celsius * 9/5) + 32


@app.route('/api/weather-activity', methods=['GET'])
def weather_activity():
"""Get location from IP, weather, and activity recommendations"""
Expand All @@ -29,6 +33,8 @@ def weather_activity():
weather_response.raise_for_status()
weather = weather_response.json()['current_weather']

weather['temperature'] = convert_celsius_to_fahrenheit(weather['temperature'])

# Business logic: Recommend activity based on weather
recommended_activity = 'Play a board game'
if weather['temperature'] > 40:
Expand Down Expand Up @@ -95,31 +101,18 @@ def create_user():
return jsonify({'error': 'Failed to create user'}), 500


def get_post_with_comments(post_id):
post_response = requests.get(f'https://jsonplaceholder.typicode.com/posts/{post_id}')
post_response.raise_for_status()
return {'post': post_response.json(), 'comments': []}


@app.route('/api/post/<int:post_id>', methods=['GET'])
def get_post(post_id):
"""Get post with comments"""
try:
# Fetch post and comments in parallel using requests
import concurrent.futures

with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
post_future = executor.submit(
requests.get, f'https://jsonplaceholder.typicode.com/posts/{post_id}'
)
comments_future = executor.submit(
requests.get, f'https://jsonplaceholder.typicode.com/posts/{post_id}/comments'
)

post_response = post_future.result()
comments_response = comments_future.result()

post_response.raise_for_status()
comments_response.raise_for_status()

return jsonify({
'post': post_response.json(),
'comments': comments_response.json()
})
result = get_post_with_comments(post_id)
return jsonify(result)
except Exception as error:
return jsonify({'error': 'Failed to fetch post data'}), 500

Expand Down