コード例 #1
0
  public static void sendImage(MediaFeedData feed, WebSocket.Out<JsonNode> out) {

    if (feed != null) {

      Logger.info("			image id:" + feed.getId());

      Caption caption = feed.getCaption();
      Images images = feed.getImages();

      ObjectNode msg = Json.newObject();
      msg.put("kind", "newImage");
      msg.put("id", feed.getId());
      msg.put("createdTime", feed.getCreatedTime());
      if (caption != null) {
        msg.put("authorFullName", caption.getFrom().getFullName());
        msg.put("authorPic", caption.getFrom().getProfilePicture());
      }
      msg.put("nLikes", feed.getLikes().getCount());
      msg.put("uLikes", feed.getLikes().getLikesUserList().toString());
      msg.put("nComments", feed.getComments().getCount());
      msg.put("uComments", feed.getComments().getComments().toString());
      msg.put("stdImageUrl", images.getStandardResolution().getImageUrl());
      out.write(msg);
    }
  } // sendImage
コード例 #2
0
  // ----------------------------------------------------------------
  // ---- Image Database---------------------------------------------
  public static void addImagesToDB(Instagram instagram) {
    Logger.info("  --Add images to db-------------");

    TagMediaFeed mediaFeed = getMediaFeed(instagram);

    List<MediaFeedData> images = mediaFeed.getData();
    List<MediaFeedData> imagesAll = new ArrayList<MediaFeedData>();

    // add first media feeds to imagesAll
    for (int i = 0; i < images.size(); i++) {
      if (imagesAll.size() < maxNumberOfImagesInst) {
        imagesAll.add(0, images.get(i));
      }
    }

    // add additional media feed to imagesAll[maxNumberOfImagesInst]
    String nextMaxId = getPagination(mediaFeed);
    while ((imagesAll.size() < maxNumberOfImagesInst) && (nextMaxId != null)) {
      // get new set of images
      TagMediaFeed nextMediaFeed = getNextMediaFeed(instagram, nextMaxId);
      List<MediaFeedData> imagesNext = nextMediaFeed.getData();

      // add  imagesNext to imagesAll
      for (int i = 0; i < imagesNext.size(); i++) {
        if (imagesAll.size() < maxNumberOfImagesInst) {
          imagesAll.add(0, imagesNext.get(i));
        }
      }

      nextMaxId = getPagination(nextMediaFeed);

      // Logger.info("imagesNext: "+imagesNext.size());
      Logger.info("imagesAll: " + imagesAll.size());
    } // while

    // print all images and add them to the db
    Logger.info("imagesAll: " + imagesAll.size());
    if (imagesAll != null) {
      int counter = 1;
      for (MediaFeedData image : imagesAll) {
        if (image != null) {
          Date d = new Date(Long.parseLong(image.getCreatedTime()) * 1000);
          Caption caption = image.getCaption();
          Logger.info(
              "   " + (counter++) + "." + " id:" + image.getId() + " time: " + d.toString() + " ");

          if (caption != null) {
            Logger.info("       from, full name: " + caption.getFrom().getFullName());
            // add image to db
            MImages.addNew(
                new MImages(
                    image.getId(),
                    image.getImages().getLowResolution().getImageUrl(),
                    "instagram",
                    caption.getFrom().getFullName(),
                    caption.getFrom().getProfilePicture(),
                    image.getCreatedTime(),
                    (long) image.getLikes().getCount(),
                    (long) 0));
          } // if
        } // if
      } // for
    } // if
  } // addImagesToDB
コード例 #3
0
  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()