public static Location fromPlace(twitter4j.Place place) {

    Location location = new Location();

    if (place.getCountry() != null) {
      location.setCountry(place.getCountry());
    }

    if (place.getCountryCode() != null) {
      location.setCountryCode(place.getCountryCode());
    }

    location.setFullname(place.getFullName());

    location.setLocationType(place.getPlaceType());

    location.setUrl(place.getURL());

    if (place.getGeometryCoordinates() != null) {
      if (place.getGeometryCoordinates().length > 0) {
        if (place.getGeometryCoordinates()[0].length > 0) {
          GeoLocation loc = place.getGeometryCoordinates()[0][0];

          if (loc != null) {
            location.setLatitude(loc.getLatitude());
            location.setLongitude(loc.getLongitude());
          }
        }
      }
    }

    return location;
  }
  private Tweet getTweetObjectFromStatus(Status status) {

    Tweet tweet = new Tweet();
    tweet.setId(Long.toString(status.getId()));
    tweet.setText(status.getText());
    tweet.setCreatedAt(status.getCreatedAt());

    tweet.setFavCount(status.getFavoriteCount());

    User user = status.getUser();

    tweet.setUserId(user.getId());
    tweet.setUserName(user.getName());
    tweet.setUserScreenName(user.getScreenName());

    HashtagEntity[] hashtagEntities = status.getHashtagEntities();
    List<String> hashtags = new ArrayList<String>();

    for (HashtagEntity hashtagEntity : hashtagEntities) {
      hashtags.add(hashtagEntity.getText());
    }

    tweet.setHashTags(hashtags.toArray(new String[hashtags.size()]));

    GeoLocation geoLocation = status.getGeoLocation();
    if (geoLocation != null) {
      double[] coordinates = {geoLocation.getLongitude(), geoLocation.getLatitude()};
      tweet.setCoordinates(coordinates);
    }

    return tweet;
  }
示例#3
0
 private static List<List<List<Double>>> getPlaceCoordinates(GeoLocation[][] geoLocations) {
   List<List<List<Double>>> listListListBoundingBox = new ArrayList<>();
   for (GeoLocation[] geoLocation1 : geoLocations) {
     List<List<Double>> listListBoundingBox = new ArrayList<>();
     for (GeoLocation geoLocation2 : geoLocation1) {
       List<Double> listBoundingBox = new ArrayList<>();
       listBoundingBox.add(geoLocation2.getLatitude());
       listBoundingBox.add(geoLocation2.getLongitude());
       listListBoundingBox.add(listBoundingBox);
     }
     listListListBoundingBox.add(listListBoundingBox);
   }
   return listListListBoundingBox;
 }
示例#4
0
  /*
   * (non-Javadoc)
   *
   * @see edu.umd.cs.dmonner.tweater.StatusEater#persist(java.util.List, twitter4j.Status)
   */
  public void persist(final List<QueryItem> matches, final Status status) {
    final User user = status.getUser();

    // get location information
    final GeoLocation loc = status.getGeoLocation();
    final double lat = loc == null ? 0D : loc.getLatitude();
    final double lon = loc == null ? 0D : loc.getLongitude();
    final String locStr = user.getLocation() == null ? "" : scrub(user.getLocation());
    final String lang = user.getLang() == null ? "" : scrub(user.getLang());

    // get retweet information
    final boolean rt = status.isRetweet();
    final long rtct = rt ? status.getRetweetCount() : 0;
    final long rtid = rt ? status.getRetweetedStatus().getId() : -1;

    synchronized (outfile) {
      this.outfile.println(
          user.getId()
              + ",\""
              + //
              user.getScreenName()
              + "\",\""
              + //
              locStr
              + "\","
              + //
              user.getFollowersCount()
              + ","
              + //
              user.getFriendsCount()
              + ","
              + //
              status.getId()
              + ","
              + //
              status.getCreatedAt()
              + ",\""
              + //
              scrub(status.getText())
              + "\","
              + //
              rt
              + ","
              + //
              rtid
              + ","
              + //
              rtct
              + ","
              + //
              lat
              + ","
              + //
              lon
              + ","
              + //
              user.getCreatedAt()
              + ","
              + //
              user.getStatusesCount()
              + ","
              + //
              user.getListedCount()
              + ","
              + //
              user.isVerified()
              + ",\""
              + //
              lang
              + "\","
              + //
              user.getUtcOffset() / 3600
              + ",\""
              + //
              matches.get(0).toString()
              + "\"");
      this.outfile.flush();
    }
  }