From 199af4b46b4263384802e7dd590a6f2ac08ade60 Mon Sep 17 00:00:00 2001 From: marcel-tan Date: Tue, 6 Jan 2026 20:27:04 -0800 Subject: [PATCH] feat: add Fahrenheit temperature conversion --- internal/buggy-branch-diff.diff | 59 +++++++++++++++++++++++++++------ internal/create-buggy-pr.sh | 0 server.py | 35 ++++++++----------- 3 files changed, 63 insertions(+), 31 deletions(-) mode change 100644 => 100755 internal/create-buggy-pr.sh diff --git a/internal/buggy-branch-diff.diff b/internal/buggy-branch-diff.diff index 2ceef3a..340d15d 100644 --- a/internal/buggy-branch-diff.diff +++ b/internal/buggy-branch-diff.diff @@ -1,23 +1,62 @@ -diff --git a/server.py b/server.py ---- a/server.py -+++ b/server.py -@@ -5,6 +5,10 @@ import requests - app = Flask(__name__) +--- server.py 2026-01-06 20:18:25 ++++ server.py 2026-01-06 20:24:44 +@@ -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(): -@@ -28,6 +32,8 @@ def weather_activity(): + """Get location from IP, weather, and activity recommendations""" +@@ -29,6 +33,8 @@ 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: +@@ -95,31 +101,18 @@ + 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/', 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 + diff --git a/internal/create-buggy-pr.sh b/internal/create-buggy-pr.sh old mode 100644 new mode 100755 diff --git a/server.py b/server.py index f6ba079..9ba07da 100644 --- a/server.py +++ b/server.py @@ -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""" @@ -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: @@ -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/', 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