Upload app.py
Browse files264 unmodified lines265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342264 unmodified linesreturn Nonedef convert_topcoder_challenge(self, tc_data: Dict) -> Challenge:"""Convert real Topcoder challenge data with enhanced parsing"""# Extract real fields from Topcoder data structurechallenge_id = str(tc_data.get('id', 'unknown'))title = tc_data.get('name', 'Topcoder Challenge')description = tc_data.get('description', 'Challenge description not available')# Extract technologies from skills arraytechnologies = []skills = tc_data.get('skills', [])for skill in skills:if isinstance(skill, dict) and 'name' in skill:technologies.append(skill['name'])# Also check for direct technologies fieldif 'technologies' in tc_data:tech_list = tc_data['technologies']if isinstance(tech_list, list):for tech in tech_list:if isinstance(tech, dict) and 'name' in tech:technologies.append(tech['name'])elif isinstance(tech, str):technologies.append(tech)# Calculate total prize from prizeSetstotal_prize = 0prize_sets = tc_data.get('prizeSets', [])for prize_set in prize_sets:if prize_set.get('type') == 'placement':prizes = prize_set.get('prizes', [])for prize in prizes:if prize.get('type') == 'USD':total_prize += prize.get('value', 0)prize = f"${total_prize:,}" if total_prize > 0 else "Merit-based"# Map challenge type to difficultychallenge_type = tc_data.get('type', 'Unknown')difficulty_mapping = {'First2Finish': 'Beginner','Code': 'Intermediate','Assembly Competition': 'Advanced','UI Prototype Competition': 'Intermediate','Copilot Posting': 'Beginner','Bug Hunt': 'Beginner','Test Suites': 'Intermediate'}difficulty = difficulty_mapping.get(challenge_type, 'Intermediate')# Time estimate and registrantstime_estimate = "Variable duration"registrants = tc_data.get('numOfRegistrants', 0)status = tc_data.get('status', '')if status == 'Completed':time_estimate = "Recently completed"elif status in ['Active', 'Draft']:time_estimate = "Active challenge"return Challenge(id=challenge_id,title=title,description=description[:300] + "..." if len(description) > 300 else description,technologies=technologies,difficulty=difficulty,prize=prize,time_estimate=time_estimate,registrants=registrants)async def fetch_real_challenges(self, limit: int = 30) -> List[Challenge]:"""Fetch real challenges from Topcoder MCP with enhanced error handling"""264 unmodified lines265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344264 unmodified linesreturn Nonedef convert_topcoder_challenge(self, tc_data: Dict) -> Challenge:"""Convert real Topcoder challenge data with enhanced parsing"""# Extract real fields from Topcoder data structurechallenge_id = str(tc_data.get('id', 'unknown'))title = tc_data.get('name', 'Topcoder Challenge')description = tc_data.get('description', 'Challenge description not available')# Extract technologies from skills arraytechnologies = []skills = tc_data.get('skills', [])for skill in skills:if isinstance(skill, dict) and 'name' in skill:technologies.append(skill['name'])# Also check for direct technologies fieldif 'technologies' in tc_data:tech_list = tc_data['technologies']if isinstance(tech_list, list):for tech in tech_list:if isinstance(tech, dict) and 'name' in tech:technologies.append(tech['name'])elif isinstance(tech, str):technologies.append(tech)# Calculate total prize from prizeSetstotal_prize = 0prize_sets = tc_data.get('prizeSets', [])for prize_set in prize_sets:if prize_set.get('type') == 'placement':prizes = prize_set.get('prizes', [])if prizes: # FIXED: Proper indentation herefor prize in prizes:if prize.get('type') == 'USD':total_prize += prize.get('value', 0)prize = f"${total_prize:,}" if total_prize > 0 else "Merit-based"# Map challenge type to difficultychallenge_type = tc_data.get('type', 'Unknown')difficulty_mapping = {'First2Finish': 'Beginner','Code': 'Intermediate','Assembly Competition': 'Advanced','UI Prototype Competition': 'Intermediate','Copilot Posting': 'Beginner','Bug Hunt': 'Beginner','Test Suites': 'Intermediate'}difficulty = difficulty_mapping.get(challenge_type, 'Intermediate')# Time estimate and registrantstime_estimate = "Variable duration"registrants = tc_data.get('numOfRegistrants', 0)status = tc_data.get('status', '')if status == 'Completed':time_estimate = "Recently completed"elif status in ['Active', 'Draft']:time_estimate = "Active challenge"return Challenge(id=challenge_id,title=title,description=description[:300] + "..." if len(description) > 300 else description,technologies=technologies,difficulty=difficulty,prize=prize,time_estimate=time_estimate,registrants=registrants)async def fetch_real_challenges(self, limit: int = 30) -> List[Challenge]:"""Fetch real challenges from Topcoder MCP with enhanced error handling"""
app.py+71-69