Example usage for twitter4j Location getWoeid

List of usage examples for twitter4j Location getWoeid

Introduction

In this page you can find the example usage for twitter4j Location getWoeid.

Prototype

int getWoeid();

Source Link

Usage

From source file:Trending.java

private void generateCodes() {
    try {/*from ww  w. jav a 2  s  .  co  m*/
        locations = twitter.getAvailableTrends();
        for (Location location : locations) {
            for (int i = 0; i < size; i++) {
                if (location.getName().equals(countries[i])) {
                    codes[i] = location.getWoeid();
                }
            }
        }
    } catch (TwitterException ex) {
        java.util.logging.Logger.getLogger(Trending.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:ColourUs.Trending.java

private void generateCodes() {
    try {/*from w  w  w  .  j  ava  2s .  c om*/
        locations = twitter.getAvailableTrends();
        for (Location location : locations) {
            for (int i = 0; i < size; i++) {
                if (location.getName().equals(countries[i])) {
                    codes[i] = location.getWoeid();
                }
            }
        }
    } catch (TwitterException ex) {
        java.util.logging.Logger.getLogger(Trending.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.javielinux.tweettopics2.TrendsLocationActivity.java

License:Apache License

private void createTrendsLocationColumn(Location trendslocation) {

    ArrayList<Entity> created_column_list = DataFramework.getInstance().getEntityList("columns",
            "location_id=" + trendslocation.getWoeid());

    int position = 0;

    if (created_column_list.size() == 0) {
        position = ColumnsUtils.nextPositionColumn();

        Entity type = new Entity("type_columns", (long) TweetTopicsUtils.COLUMN_TRENDING_TOPIC);
        Entity user_list = new Entity("columns");
        user_list.setValue("description", trendslocation.getName());
        user_list.setValue("type_id", type);
        user_list.setValue("position", position);
        user_list.setValue("location_id", trendslocation.getWoeid());
        user_list.save();//  www .ja v a  2  s .c  om
        Toast.makeText(this, getString(R.string.column_created, trendslocation.getName()), Toast.LENGTH_LONG)
                .show();
    } else {
        position = created_column_list.get(0).getInt("position");
    }

    Intent intent = getIntent();
    intent.putExtra("position", position);

    setResult(RESULT_OK, intent);
    finish();
}

From source file:com.mmiagency.knime.nodes.twitter.trends.TwitterTrendsNodeDialog.java

License:Open Source License

private void initWoeid(TwitterApiConnection twitterApiConnection) throws TwitterException {

    // don't run again if it's already initialized
    if (m_country.getItemCount() > 1) {
        return;/*from w w w  .ja  v a 2 s  . c  o m*/
    }

    // add worldwide as default
    woeidMap.put(1, "Worldwide");
    placeMap.put("Worldwide", 1);

    // if Twitter API Connection is not available, use Worldwide as default
    if (twitterApiConnection == null) {
        m_country.addItem("Worldwide");
        return;
    }

    Twitter twitter = twitterApiConnection.getTwitter();

    ResponseList<Location> response = twitter.getAvailableTrends();

    for (Location location : response) {
        // skip worldwide as it's already added as default
        if (location.getWoeid() == 1)
            continue;
        // check if it's city or country
        if (location.getPlaceCode() == 12) {
            woeidMap.put(location.getWoeid(), location.getCountryName());
            placeMap.put(location.getCountryName(), location.getWoeid());
        } else {
            woeidMap.put(location.getWoeid(), location.getCountryName() + "|" + location.getName());
            placeMap.put(location.getCountryName() + "|" + location.getName(), location.getWoeid());
        }
    }

    // split country and city
    List<String> cities;
    String[] tokens;
    String lastCountry = "";
    for (Map.Entry<String, Integer> entry : placeMap.entrySet()) {
        // skip worldwide as it's already added as default
        if (entry.getValue() == 1)
            continue;
        tokens = entry.getKey().split("\\|");
        if (!lastCountry.equals(tokens[0])) {
            m_country.addItem(tokens[0]);
        }
        lastCountry = tokens[0];
        if (countryCityMap.containsKey(tokens[0])) {
            cities = countryCityMap.get(tokens[0]);
        } else {
            cities = new ArrayList<String>();
            countryCityMap.put(tokens[0], cities);
        }
        if (tokens.length > 1) {
            cities.add(tokens[1]);
        } else {
            cities.add("-" + tokens[0] + "-");
        }
    }

}

From source file:DataCollections.LocationHelper.java

public void insertLocations(Location[] l) {
    boolean[] selection = new boolean[Location_dbo.nooffields];
    Location_dbo loc;//from w  w w.j av a 2  s  .  c o m

    //LogPrinter.printLog("No of Locations to be Processed: "+l.length);

    for (Location l1 : l) {
        if (LocationsTable.select("woeid = " + l1.getWoeid(), 0, 1).length == 0) {
            LogPrinter.printLog("Processing a location " + l1.getName());
            loc = convertLocationToLocation_dbo(l1);
            for (int j = 0; j < Location_dbo.nooffields; j++) {
                selection[j] = loc.values[j].used;
            }
            LocationsTable.insert(loc, selection);
        }
    }
}

From source file:DataCollections.LocationHelper.java

public Location_dbo convertLocationToLocation_dbo(Location l) {

    Location_dbo loc = new Location_dbo();
    //LogPrinter.printLog("Conversion of current location to database object is started");
    loc.values[Location_dbo.map.get("country_code")].setValue(l.getCountryCode());
    loc.values[Location_dbo.map.get("country_name")].setValue(l.getCountryName());
    loc.values[Location_dbo.map.get("name")].setValue(l.getName());
    loc.values[Location_dbo.map.get("place_code")].setValue(String.valueOf(l.getPlaceCode()));
    loc.values[Location_dbo.map.get("place_name")].setValue(l.getPlaceName());
    loc.values[Location_dbo.map.get("url")].setValue(l.getURL());
    loc.values[Location_dbo.map.get("woeid")].setValue(String.valueOf(l.getWoeid()));
    //LogPrinter.printLog("Conversion of current location to database object complete");
    return loc;/*from  w  w w.j  a  v  a 2s  .com*/
}

From source file:DataCollections.TrendsCollections.java

public void collectLatestTrendingHashTags() throws InterruptedException {

    ListIterator<Location> i = locations.listIterator();

    while (i.hasNext()) {
        Location l = i.next();

        try {/*from  w  w  w.  ja  v a  2  s  .c  om*/
            trends = trendsresources.getPlaceTrends(l.getWoeid());
        } catch (TwitterException e) {
            Thread.sleep((e).getRetryAfter() * 1000 + 5000);
            i.previous();
            continue;

        }

        System.out.println("\nLocation:- CountryCode: " + l.getCountryCode() + " Country Name: "
                + l.getCountryName() + " Name: " + l.getName() + " PlaceCode: " + l.getPlaceCode()
                + " PlaceName: " + l.getPlaceName() + " URL: " + l.getURL() + " Woeid: " + l.getWoeid() + "\n");
        Trend[] ts = trends.getTrends();

        for (int t = 0; t < ts.length; t++) {
            System.out.println("Trend " + t + ts[t].getName() + " " + ts[t].toString());
        }
        htaghelper.insertTrends(ts);
    }
}

From source file:de.vanita5.twittnuker.preference.TrendsLocationPreference.java

License:Open Source License

@Override
public void onClick(final DialogInterface dialog, final int which) {
    final SharedPreferences.Editor editor = getEditor();
    if (editor == null)
        return;/*from  w ww. ja  v  a  2 s .c  o  m*/
    final Location item = mAdapter.getItem(which);
    if (item != null) {
        editor.putInt(KEY_LOCAL_TRENDS_WOEID, item.getWoeid());
        editor.commit();
    }
    if (mDialog != null && mDialog.isShowing()) {
        mDialog.dismiss();
    }
}

From source file:ontoSentiment.Util.java

public static Integer getTrendLocationId(String locationName, boolean imprimeTrendName)
        throws TwitterException {

    int idTrendLocation = 0;

    ResponseList<Location> locations;
    locations = getTwitter().getAvailableTrends();

    for (Location location : locations) {
        if (imprimeTrendName) {
            System.out.println("Trend name: " + location.getName());
        }/*  w ww  .  ja  va  2 s .  com*/
        if (location.getName().toLowerCase().equals(locationName.toLowerCase())) {
            idTrendLocation = location.getWoeid();
            break;
        }
    }

    if (idTrendLocation > 0) {
        return idTrendLocation;
    }

    return null;
}

From source file:org.getlantern.firetweet.preference.TrendsLocationPreference.java

License:Open Source License

@Override
public void onClick(final DialogInterface dialog, final int which) {
    final SharedPreferences.Editor editor = getEditor();
    if (editor == null)
        return;//w w w.  j  av a2 s.  c o  m
    final Location item = mAdapter.getItem(which);
    if (item != null) {
        editor.putInt(KEY_LOCAL_TRENDS_WOEID, item.getWoeid());
        editor.apply();
    }
    if (mDialog != null && mDialog.isShowing()) {
        mDialog.dismiss();
    }
}