Skip to content

Commit

Permalink
Additional logs
Browse files Browse the repository at this point in the history
  • Loading branch information
This-Is-Ko committed Sep 23, 2024
1 parent 74df887 commit a24d30f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public void postToInstagram(Post post, List<ImageUrlEntry> imagesToUpload) throw
// Sample request "https://graph.facebook.com/v18.0/90010177253934/media?caption=Fruit%20candies&media_type=CAROUSEL&children=17899506308402767%2C18193870522147812%2C17853844403701904&access_token=EAAOc..."
InstagramUserMedia carouselCreateResponse = callInstagramUserMediaApi(facebookApiProperties.getInstagram().getUserId(), null, post.getCaption(), false, "CAROUSEL", individualImageContainer);
String carouselId = carouselCreateResponse.getId();
LogHelper.logWithSubject(log.atInfo().setMessage("Successfully created Instagram carousel container"), post);
LogHelper.logWithSubject(log.atInfo().setMessage("Successfully created Instagram carousel container with id=" + carouselId), post);

// Step 3 - publish carousel container
InstagramUserMedia publishResponse = callInstagramUserMediaPublishApi(facebookApiProperties.getInstagram().getUserId(), carouselId);
Expand Down Expand Up @@ -250,6 +250,7 @@ public InstagramUserMedia callInstagramUserMediaApi(String instagramUserId, Stri
if (caption != null) {
// Refer to https://stackoverflow.com/questions/54099777/inconsistent-line-breaks-when-posting-to-instagram
// https://www.fileformat.info/info/unicode/char/2063/index.htm
// Maximum 2200 characters, 30 hashtags, and 20 @ tags
urlBuilder.queryParam("caption", FacebookApiHelper.encodeTextToUtf8(caption.replace("\n", "\u2063\n")));
}
String apiUrl = urlBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,11 @@ public void generateSummaryImage(Post summaryPost, List<Post> playerPosts, Image
image = setUpBaseImageWithBackgroundImageUrl(backgroundImageGenParams);

// Add individual player stats
log.atInfo().setMessage("Adding player stats to summary image").log();
log.atInfo().setMessage("Adding player stats to summary image(s)").log();
List<BufferedImage> outputImages = summaryDrawPlayerStats(image, playerPosts);

// Add side image
log.atInfo().setMessage("Adding side image to summary image").log();
log.atInfo().setMessage("Adding side image to summary image(s)").log();
summaryDrawSideImage(outputImages, imageGenParams);

// Save the modified image
Expand Down Expand Up @@ -546,9 +546,12 @@ public List<BufferedImage> summaryDrawPlayerStats(BufferedImage image, List<Post
Graphics2D imageGraphics = currentImage.createGraphics();
imageGraphics.drawImage(teamLogo, 70, currentNameY - teamLogoOffsetFromNameY, null);
imageGraphics.dispose();
log.atInfo().setMessage("Team logo added to summary image").addKeyValue("player", playerPost.getPlayer().getName()).log();
} else {
log.atWarn().setMessage("Unable to determine team to draw team logo").addKeyValue("player", playerPost.getPlayer().getName()).log();
}
} catch (IOException e) {
log.atWarn().setMessage("URL to team logo was invalid").log();
log.atWarn().setMessage("URL to team logo was invalid").addKeyValue("player", playerPost.getPlayer().getName()).log();
}

playerNameGraphic.setColor(Color.BLACK);
Expand Down Expand Up @@ -692,11 +695,13 @@ public void summaryDrawSideImage(List<BufferedImage> outputImages, ImageGenParam
int horizontalOffset = (imageGenParams.getImageHorizontalOffset() != null ? imageGenParams.getImageHorizontalOffset() : 0);
BufferedImage croppedImage = scaledImage.getSubimage(horizontalOffset, 0, 1000 - statsDrawingAreaWidth, 1000);

int imageCount = 1;
for (BufferedImage image : outputImages) {
Graphics2D imageGraphics = image.createGraphics();
imageGraphics.drawImage(croppedImage, statsDrawingAreaWidth, 0, null);
imageGraphics.dispose();
log.atInfo().setMessage("Added side image to summary image").log();
log.atInfo().setMessage("Added side image to summary image " + imageCount).log();
imageCount++;
}
}

Expand Down

0 comments on commit a24d30f

Please sign in to comment.