public static Long checkNumberOfNewImages(Instagram instagram, String tag) { Long nImages = getNumberOfImagesByTag(instagram, tag); TagInfo tagindb = TagInfo.get((long) 1); return nImages - tagindb.numberOfImages; }
public static void tagWatchDog(Instagram instagram) { Logger.info(" --tag watchdog"); Long nImages = checkNumberOfNewImages(instagram, appDisplayNameTag); if (nImages > 0) { // there are new images to take care of Logger.info(" number of new images: " + nImages); // get the first page of media feeds (images) TagMediaFeed mediaFeed = getMediaFeed(instagram); List<MediaFeedData> images = mediaFeed.getData(); // TODO: support adding new images from other pages // limit number of new images to the first page if (nImages > images.size()) { // number of new images excides the first page nImages = (long) images.size(); Logger.info(" number of limited images: " + nImages); } // TODO check if the image is already in db, double images problem!!! // for each new image from the first page for (int i = (int) (nImages - 1); i >= 0; i--) { // add new images to db MediaFeedData image = images.get(i); Caption caption = image.getCaption(); MImages newDbImage = new MImages( image.getId(), image.getImages().getLowResolution().getImageUrl(), "instagram", caption.getFrom().getFullName(), caption.getFrom().getProfilePicture(), image.getCreatedTime(), (long) image.getLikes().getCount(), (long) 0); MImages.addNew(newDbImage); Logger.info( " add image to db: index: " + i + " id: " + image.getId() + " from: " + caption.getFrom().getFullName()); // send the new image to clients sendImageToClients(newDbImage); } // update the tag count TagInfo.delete((long) 1); Logger.info(" update the tag +"); TagInfo.addNew( new TagInfo(appDisplayNameTag, getNumberOfImagesByTag(instagram, appDisplayNameTag))); displayTagInfo(); } else if (nImages < 0) { // TODO // some images have been deleted // for now keep them in the db, later consider deleting them // update the tag TagInfo.delete((long) 1); Logger.info(" update the tag -"); TagInfo.addNew( new TagInfo(appDisplayNameTag, getNumberOfImagesByTag(instagram, appDisplayNameTag))); displayTagInfo(); } Logger.info(" --tag watchdog---"); } // tagWatchDog()
public static void checkTag(Instagram instagram) { Logger.info("----TAG-----------------------"); // check if the tag is in db if (TagInfo.contains((long) 1)) { // tag found, check if it's the right tag if (TagInfo.contains(appDisplayNameTag)) { // tag is already in db, start the tag scheduler (tagWatchdog) Logger.info(" tag is in the db"); displayTagInfo(); // tag info in the db // display local folder path Logger.info(" local folder: " + urlPath); } else { // old tag is in the db, update it with the new one Logger.info(" old tag is in the db, update the old tag"); // delete the old tag, add the new tag Logger.info(" delete old tag"); TagInfo.delete((long) 1); Logger.info(" add the new tag"); TagInfo.addNew( new TagInfo(appDisplayNameTag, getNumberOfImagesByTag(instagram, appDisplayNameTag))); displayTagInfo(); // delete old images from the image db Logger.info(" delete old images"); deleteAllImagesFormDb(); // add new images to the db Logger.info(" add the new images"); addImagesToDB(instagram); // local // add new local folder info Logger.info(" delete old local info"); LocalInfo.delete((long) 1); Logger.info(" add new local info"); LocalInfo.addNew(new LocalInfo(urlPath, getNumberOfLocalImages())); Logger.info( " localPath: " + LocalInfo.get((long) 1).urlPath + " nImages: " + LocalInfo.get((long) 1).numberOfImages); // add loacal images to the db addLocalImagesToDb(); } } else { // add the new tag to db Logger.info(" tag is not in the db"); Logger.info(" add the new tag"); TagInfo.addNew( new TagInfo(appDisplayNameTag, getNumberOfImagesByTag(instagram, appDisplayNameTag))); displayTagInfo(); // add images of the new tag to the db Logger.info(" add the new images"); addImagesToDB(instagram); // local // add local folder info Logger.info(" add new local info"); LocalInfo.addNew(new LocalInfo(urlPath, getNumberOfLocalImages())); Logger.info( " localPath: " + LocalInfo.get((long) 1).urlPath + " nImages: " + LocalInfo.get((long) 1).numberOfImages); // add loacal images to the db addLocalImagesToDb(); } } // checkTag
public static void displayTagInfo() { TagInfo tagindb = TagInfo.get((long) 1); Logger.info(" tag_name : " + tagindb.tagName); Logger.info(" tag_count : " + tagindb.numberOfImages); } // displayTagInfo