Spaces:
Sleeping
Sleeping
Upload main.py
Browse files42 unmodified lines434445464748491230 unmodified lines1280128112821283128412851286128712881289129012911292129312941295129612971298129942 unmodified lines# New spreadsheet for Teams and Servers dataTEAMS_SERVERS_SPREADSHEET_ID = os.getenv('TEAMS_SERVERS_SPREADSHEET_ID', '1HWnvzPd4AtRdAroXnwQaN4Dcpj6lZbtnCBavqiAxokQ')SCOPES = ['https://www.googleapis.com/auth/spreadsheets.readonly']# Sheet Names and Ranges within SCAMMER_DWC_SPREADSHEET_IDUSER_SCAMMER_SHEET = "User Scammer Files"1230 unmodified lines@app.post("/api/teams/like")async def like_team_member(data: TeamMemberLike):"""Increment like count for a team member (to be implemented with spreadsheet update)"""check_cache_readiness()# Find the team member by discord_user_iddiscord_user_id = data.discord_user_id.strip()teams = cache.get("teams", [])for member in teams:if member.get("discord_user_id") == discord_user_id:# In a real implementation, this would update the spreadsheet# For now, just update the cachemember["likes"] = member.get("likes", 0) + 1member["last_updated"] = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S")return {"success": True, "likes": member["likes"]}raise HTTPException(status_code=404, detail=f"Team member with discord_user_id {discord_user_id} not found")42 unmodified lines43444546474849505152531230 unmodified lines12841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134342 unmodified lines# New spreadsheet for Teams and Servers dataTEAMS_SERVERS_SPREADSHEET_ID = os.getenv('TEAMS_SERVERS_SPREADSHEET_ID', '1HWnvzPd4AtRdAroXnwQaN4Dcpj6lZbtnCBavqiAxokQ')# Scopes for read and write access to spreadsheetsSCOPES = ['https://www.googleapis.com/auth/spreadsheets.readonly','https://www.googleapis.com/auth/spreadsheets' # Added write access]# Sheet Names and Ranges within SCAMMER_DWC_SPREADSHEET_IDUSER_SCAMMER_SHEET = "User Scammer Files"1230 unmodified lines@app.post("/api/teams/like")async def like_team_member(data: TeamMemberLike):"""Increment like count for a team member and update spreadsheet"""check_cache_readiness()# Find the team member by discord_user_iddiscord_user_id = data.discord_user_id.strip()teams = cache.get("teams", [])for index, member in enumerate(teams):if member.get("discord_user_id") == discord_user_id:# Increment the like countcurrent_likes = member.get("likes", 0)new_likes = current_likes + 1member["likes"] = new_likes# Update the spreadsheettry:# We need to use sheets.spreadsheets().values().update()# First, find the row index in the sheet for this memberif sheets_service:# Get all values to find the correct rowresult = sheets_service.spreadsheets().values().get(spreadsheetId=TEAMS_SERVERS_SPREADSHEET_ID,range=f"{quote_sheet_name(TEAMS_SHEET)}!B:C" # Get discord usernames and IDs).execute()values = result.get('values', [])row_index = None# Find the row with matching discord_user_id (column C in the sheet)for i, row in enumerate(values):if len(row) > 1 and row[1] == discord_user_id:# Add 1 for header row and +5 since we start from row 6row_index = i + 6breakif row_index:# Update likes (column J)sheets_service.spreadsheets().values().update(spreadsheetId=TEAMS_SERVERS_SPREADSHEET_ID,range=f"{quote_sheet_name(TEAMS_SHEET)}!J{row_index}",valueInputOption="RAW",body={"values": [[new_likes]]}).execute()logger.info(f"Updated likes for user {discord_user_id} to {new_likes} in spreadsheet")else:logger.error(f"Could not find row for user {discord_user_id} in spreadsheet")else:logger.error("Google Sheets service not available for updating likes")except Exception as e:logger.error(f"Error updating likes in spreadsheet: {e}")# Continue with returning updated likes even if spreadsheet update failsreturn {"success": True, "likes": new_likes}raise HTTPException(status_code=404, detail=f"Team member with discord_user_id {discord_user_id} not found")
main.py+52-8