List of usage examples for twitter4j User getLocation
String getLocation();
From source file:com.twitt4droid.data.dao.impl.sqlite.UserSQLiteDAO.java
License:Apache License
/** {@inheritDoc} */ @Override// w w w .ja v a 2s . com public void save(User user) { getSQLiteTemplate().execute(getSqlString(R.string.twitt4droid_insert_user_sql), new String[] { Objects.toString(user.getId()), user.getName(), user.getScreenName(), user.getProfileImageURL(), user.getProfileBannerURL(), user.getURL(), user.getDescription(), user.getLocation() }); }
From source file:DataCollections.UserHelper.java
public User_dbo convertUserToUser_dbo(User user) { User_dbo u = new User_dbo(); u.values[User_dbo.map.get("user_id")].setValue(String.valueOf(user.getId())); u.values[User_dbo.map.get("name")].setValue(removeEscapeCharacters(user.getName())); u.values[User_dbo.map.get("screename")].setValue(removeEscapeCharacters(user.getScreenName())); u.values[User_dbo.map.get("lang")].setValue(user.getLang()); u.values[User_dbo.map.get("location")].setValue(removeEscapeCharacters(user.getLocation())); u.values[User_dbo.map.get("geoenabled")].setValue(String.valueOf(user.isGeoEnabled())); u.values[User_dbo.map.get("timezone")].setValue(user.getTimeZone()); u.values[User_dbo.map.get("profileurl")].setValue(user.getURL()); u.values[User_dbo.map.get("protected")].setValue(String.valueOf(user.isProtected())); u.values[User_dbo.map.get("verified")].setValue(String.valueOf(user.isVerified())); u.values[User_dbo.map.get("description")].setValue(removeEscapeCharacters(user.getDescription())); if (geoinfoavailable) { double[] geocoor = geohelper.searchGeoLocCoor(user.getLocation()); u.values[User_dbo.map.get("probased_geoinfo")].setValue(String.valueOf("true")); //u.values[User_dbo.map.get("descbased_geoinfo")].setValue(String.valueOf("false")); u.values[User_dbo.map.get("probased_lat")].setValue(String.valueOf(geocoor[0])); u.values[User_dbo.map.get("probased_lon")].setValue(String.valueOf(geocoor[1])); }//www.j a v a 2 s . c o m u.values[User_dbo.map.get("udetails_processed")].setValue(String.valueOf(true)); u.values[User_dbo.map.get("totaltweets")].setValue(String.valueOf(user.getStatusesCount())); return u; }
From source file:de.binfalse.jatter.processors.JabberMessageProcessor.java
License:Open Source License
/** * Translate user.//w ww .j a v a 2s . c o m * * @param user the user * @param profile the profile * @return the string */ public static String translateUser(User user, String profile) { String ret = "profile of *" + profile + "*\n" + "name: " + user.getName() + "\n" + "screen name: " + user.getScreenName() + "\n" + "id: " + user.getId() + "\n"; if (user.getDescription() != null) ret += "description: " + user.getDescription() + "\n"; if (user.getURL() != null) ret += "url: " + JatterTools.expandUrl(user.getURL()) + "\n"; if (user.getLang() != null) ret += "language: " + user.getLang() + "\n"; if (user.getLocation() != null) ret += "location: " + user.getLocation() + "\n"; if (user.getTimeZone() != null) ret += "time zone: " + user.getTimeZone() + "\n"; ret += "tweets: " + user.getStatusesCount() + "\n"; ret += "favourites: " + user.getFavouritesCount() + "\n"; ret += "followers: " + user.getFollowersCount() + "\n"; ret += "friends: " + user.getFriendsCount() + "\n"; if (user.getStatus() != null) ret += "last status: " + TwitterStatusProcessor.translateTwitterStatus(user.getStatus()); return ret; }
From source file:de.jetwick.data.JUser.java
License:Apache License
/** * This method refreshes the properties of this user by the specified * Twitter4j user//from w w w . ja v a 2s . c o m * @param user */ public Status updateFieldsBy(User user) { twitterId = user.getId(); setProtected(user.isProtected()); setTwitterCreatedAt(user.getCreatedAt()); setDescription(user.getDescription()); addLanguage(user.getLang()); setLocation(TwitterSearch.toStandardLocation(user.getLocation())); setRealName(user.getName()); // user.getFollowersCount(); // user.getFriendsCount(); // user.getTimeZone() if (user.getProfileImageURL() != null) setProfileImageUrl(user.getProfileImageURL().toString()); if (user.getURL() != null) setWebUrl(user.getURL().toString()); setFollowersCount(user.getFollowersCount()); setFriendsCount(user.getFriendsCount()); return user.getStatus(); }
From source file:de.jetwick.tw.TwitterSearch.java
License:Apache License
public static Twitter4JTweet toTweet(Status st, User user) { if (user == null) throw new IllegalArgumentException("User mustn't be null!"); if (st == null) throw new IllegalArgumentException("Status mustn't be null!"); Twitter4JTweet tw = new Twitter4JTweet(st.getId(), st.getText(), user.getScreenName()); tw.setCreatedAt(st.getCreatedAt());//from w w w . j a v a 2 s . co m tw.setFromUser(user.getScreenName()); if (user.getProfileImageURL() != null) tw.setProfileImageUrl(user.getProfileImageURL().toString()); tw.setSource(st.getSource()); tw.setToUser(st.getInReplyToUserId(), st.getInReplyToScreenName()); tw.setInReplyToStatusId(st.getInReplyToStatusId()); if (st.getGeoLocation() != null) { tw.setGeoLocation(st.getGeoLocation()); tw.setLocation(st.getGeoLocation().getLatitude() + ", " + st.getGeoLocation().getLongitude()); } else if (st.getPlace() != null) tw.setLocation(st.getPlace().getCountryCode()); else if (user.getLocation() != null) tw.setLocation(toStandardLocation(user.getLocation())); return tw; }
From source file:de.vanita5.twittnuker.model.ParcelableUser.java
License:Open Source License
public ParcelableUser(final User user, final long account_id, final long position) { this.position = position; this.account_id = account_id; final URLEntity[] urls_url_entities = user.getURLEntities(); id = user.getId();// ww w. j a va2 s . c om created_at = getTime(user.getCreatedAt()); is_protected = user.isProtected(); is_verified = user.isVerified(); name = user.getName(); screen_name = user.getScreenName(); description_plain = user.getDescription(); description_html = formatUserDescription(user); description_expanded = formatExpandedUserDescription(user); location = user.getLocation(); profile_image_url = ParseUtils.parseString(user.getProfileImageUrlHttps()); profile_banner_url = user.getProfileBannerImageUrl(); url = ParseUtils.parseString(user.getURL()); url_expanded = url != null && urls_url_entities != null && urls_url_entities.length > 0 ? ParseUtils.parseString(urls_url_entities[0].getExpandedURL()) : null; is_follow_request_sent = user.isFollowRequestSent(); followers_count = user.getFollowersCount(); friends_count = user.getFriendsCount(); statuses_count = user.getStatusesCount(); favorites_count = user.getFavouritesCount(); listed_count = user.getListedCount(); is_cache = false; is_following = user.isFollowing(); description_unescaped = toPlainText(description_html); }
From source file:de.vanita5.twittnuker.util.ContentValuesCreator.java
License:Open Source License
public static ContentValues makeCachedUserContentValues(final User user) { if (user == null || user.getId() <= 0) return null; final String profile_image_url = ParseUtils.parseString(user.getProfileImageUrlHttps()); final String url = ParseUtils.parseString(user.getURL()); final URLEntity[] urls = user.getURLEntities(); final ContentValues values = new ContentValues(); values.put(CachedUsers.USER_ID, user.getId()); values.put(CachedUsers.NAME, user.getName()); values.put(CachedUsers.SCREEN_NAME, user.getScreenName()); values.put(CachedUsers.PROFILE_IMAGE_URL, profile_image_url); values.put(CachedUsers.CREATED_AT, user.getCreatedAt().getTime()); values.put(CachedUsers.IS_PROTECTED, user.isProtected()); values.put(CachedUsers.IS_VERIFIED, user.isVerified()); values.put(CachedUsers.IS_FOLLOWING, user.isFollowing()); values.put(CachedUsers.FAVORITES_COUNT, user.getFavouritesCount()); values.put(CachedUsers.FOLLOWERS_COUNT, user.getFollowersCount()); values.put(CachedUsers.FRIENDS_COUNT, user.getFriendsCount()); values.put(CachedUsers.STATUSES_COUNT, user.getStatusesCount()); values.put(CachedUsers.LISTED_COUNT, user.getListedCount()); values.put(CachedUsers.LOCATION, user.getLocation()); values.put(CachedUsers.DESCRIPTION_PLAIN, user.getDescription()); values.put(CachedUsers.DESCRIPTION_HTML, Utils.formatUserDescription(user)); values.put(CachedUsers.DESCRIPTION_EXPANDED, Utils.formatExpandedUserDescription(user)); values.put(CachedUsers.URL, url); values.put(CachedUsers.URL_EXPANDED, url != null && urls != null && urls.length > 0 ? ParseUtils.parseString(urls[0].getExpandedURL()) : null);//from www.j av a2 s . c om values.put(CachedUsers.PROFILE_BANNER_URL, user.getProfileBannerImageUrl()); return values; }
From source file:edu.cmu.geolocator.coder.utils.JSON2Tweet.java
License:Apache License
public JSONTweet readLine() { String line;/*from www .java2 s. com*/ try { line = br.readLine(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); return null; } if (line == null) return null; Status tweet = null; try { // parse json to object type tweet = DataObjectFactory.createStatus(line); } catch (TwitterException e) { System.err.println("error parsing tweet object"); return null; } jsontweet.JSON = line; jsontweet.id = tweet.getId(); jsontweet.source = tweet.getSource(); jsontweet.text = tweet.getText(); jsontweet.createdat = tweet.getCreatedAt(); jsontweet.tweetgeolocation = tweet.getGeoLocation(); User user; if ((user = tweet.getUser()) != null) { jsontweet.userdescription = user.getDescription(); jsontweet.userid = user.getId(); jsontweet.userlanguage = user.getLang(); jsontweet.userlocation = user.getLocation(); jsontweet.username = user.getName(); jsontweet.usertimezone = user.getTimeZone(); jsontweet.usergeoenabled = user.isGeoEnabled(); if (user.getURL() != null) { String url = user.getURL().toString(); jsontweet.userurl = url; String addr = url.substring(7).split("/")[0]; String[] countrysuffix = addr.split("[.]"); String suffix = countrysuffix[countrysuffix.length - 1]; jsontweet.userurlsuffix = suffix; try { InetAddress address = null;//InetAddress.getByName(user.getURL().getHost()); String generate_URL // = // "http://www.geobytes.com/IpLocator.htm?GetLocation&template=php3.txt&IpAddress=" = "http://www.geoplugin.net/php.gp?ip=" + address.getHostAddress(); URL data = new URL(generate_URL); URLConnection yc = data.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream())); String inputLine; String temp = ""; while ((inputLine = in.readLine()) != null) { temp += inputLine + "\n"; } temp = temp.split("s:2:\"")[1].split("\"")[0]; jsontweet.userurllocation = temp; } catch (Exception uhe) { //uhe.printStackTrace(); jsontweet.userurllocation = null; } } } return jsontweet; }
From source file:edu.cmu.geolocator.coder.utils.JSON2Tweet.java
License:Apache License
public static JSONTweet getJSONTweet(String JSONString) { JSONTweet jsontweet = new JSONTweet(); if (JSONString == null) return null; Status tweet = null;/*from w w w . ja v a 2 s .com*/ try { // parse json to object type tweet = DataObjectFactory.createStatus(JSONString); } catch (TwitterException e) { System.err.println("error parsing tweet object"); return null; } jsontweet.JSON = JSONString; jsontweet.id = tweet.getId(); jsontweet.source = tweet.getSource(); jsontweet.text = tweet.getText(); jsontweet.createdat = tweet.getCreatedAt(); jsontweet.tweetgeolocation = tweet.getGeoLocation(); User user; if ((user = tweet.getUser()) != null) { jsontweet.userdescription = user.getDescription(); jsontweet.userid = user.getId(); jsontweet.userlanguage = user.getLang(); jsontweet.userlocation = user.getLocation(); jsontweet.username = user.getName(); jsontweet.usertimezone = user.getTimeZone(); jsontweet.usergeoenabled = user.isGeoEnabled(); if (user.getURL() != null) { String url = user.getURL().toString(); jsontweet.userurl = url; String addr = url.substring(7).split("/")[0]; String[] countrysuffix = addr.split("[.]"); String suffix = countrysuffix[countrysuffix.length - 1]; jsontweet.userurlsuffix = suffix; try { InetAddress address = null;//InetAddress.getByName(user.getURL().getHost()); String generate_URL // = // "http://www.geobytes.com/IpLocator.htm?GetLocation&template=php3.txt&IpAddress=" = "http://www.geoplugin.net/php.gp?ip=" + address.getHostAddress(); URL data = new URL(generate_URL); URLConnection yc = data.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream())); String inputLine; String temp = ""; while ((inputLine = in.readLine()) != null) { temp += inputLine + "\n"; } temp = temp.split("s:2:\"")[1].split("\"")[0]; jsontweet.userurllocation = temp; } catch (Exception uhe) { //uhe.printStackTrace(); jsontweet.userurllocation = null; } } } return jsontweet; }
From source file:flight_ranker.Flight_colllector.java
public static void main(String[] args) throws FileNotFoundException, IOException { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true);// w w w.j av a2 s . c o m cb.setOAuthConsumerKey("Oa6WAzH0j3sgVrP0CNGvxnWA2"); cb.setOAuthConsumerSecret("sLdoFybvJvVFz7Lxbbv9KWQDFeKcVeZAkWDC4QMHnx5lV2OmGE"); cb.setOAuthAccessToken("2691889945-5NOBWKUgT9FiAoyOQSCFg8CLlPRlDMbWcUrJBdK"); cb.setOAuthAccessTokenSecret("J6tA8Sxrtz2JNSFdQwAonbGxNfLNuD9I54Zfvomku3p5t"); TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); StatusListener listener = new StatusListener() { @Override public void onException(Exception arg0) { // TODO Auto-generated method stub } @Override public void onDeletionNotice(StatusDeletionNotice arg0) { // TODO Auto-generated method stub } @Override public void onScrubGeo(long arg0, long arg1) { // TODO Auto-generated method stub } @Override public void onStatus(Status status) { User user = status.getUser(); // gets Username String username = status.getUser().getScreenName(); long followers = user.getFollowersCount(); long retweets = status.getRetweetCount(); long favs = status.getFavoriteCount(); System.out.println("USERNAME--> " + username); System.out.println("FOLLOWERS--> " + followers); String profileLocation = user.getLocation(); // System.out.println("RETWEETS--> "+retweets); // System.out.println("FAVOURITES--> "+favs); System.out.println("LOCATION--> " + profileLocation); long tweetId = status.getId(); System.out.println("TWEET ID--> " + tweetId); String content = status.getText(); System.out.println("TWEET--> " + content + "\n"); BufferedWriter b1 = null, b2, b3, b4, b5, b6, b7 = null; try { //output_file = new BufferedReader(new FileReader("G:\\Sentiwords.txt")); FileWriter f1 = new FileWriter("G:\\flights_data.txt", true); b1 = new BufferedWriter(f1); b1.write("#USERNAME- " + username); b1.newLine(); b1.write("#Followers- " + followers); b1.newLine(); b1.write("#Location- " + profileLocation); b1.newLine(); b1.write("#ID- " + tweetId); b1.newLine(); b1.write("#Tweet- " + content); b1.newLine(); b1.newLine(); tweet_editor modified_tweet = new tweet_editor(content); //tweet_tagger tagged_tweet = new tweet_tagger(modified_tweet.edited_tweet); //System.out.println(tagged_tweet.tagged); sentiment_calculator senti_value = new sentiment_calculator(modified_tweet.edited_tweet); if (content.contains("Indigo")) { System.out.println("indigo"); FileWriter f2 = new FileWriter("G:\\Indigo.txt", true); b2 = new BufferedWriter(f2); b2.write(Double.toString(senti_value.senti_rate)); b2.newLine(); } if (content.contains("Jet")) { System.out.println("jet"); FileWriter f3 = new FileWriter("G:\\jet.txt", true); b3 = new BufferedWriter(f3); b3.write(Double.toString(senti_value.senti_rate)); b3.newLine(); } if (content.contains("Indian")) { System.out.println("indian"); FileWriter f4 = new FileWriter("G:\\Indian.txt", true); b4 = new BufferedWriter(f4); b4.write(Double.toString(senti_value.senti_rate)); b4.newLine(); } if (content.contains("Spicejet")) { System.out.println("spicejet"); FileWriter f5 = new FileWriter("G:\\spicejet.txt", true); b5 = new BufferedWriter(f5); b5.write(Double.toString(senti_value.senti_rate)); b5.newLine(); } if (content.contains("AirAsia")) { System.out.println("airasia"); FileWriter f6 = new FileWriter("G:\\airasia.txt", true); b6 = new BufferedWriter(f6); b6.write(Double.toString(senti_value.senti_rate)); b6.newLine(); } try { //output_file = new BufferedReader(new FileReader("G:\\Sentiwords.txt")); FileWriter f7 = new FileWriter("G:\\flight_senti.txt", true); b7 = new BufferedWriter(f7); b7.write(String.valueOf(senti_value.senti_rate)); b7.newLine(); } catch (IOException e) { e.printStackTrace(); } finally { try { b7.close(); } catch (IOException ex) { Logger.getLogger(Flight_colllector.class.getName()).log(Level.SEVERE, null, ex); } } } catch (IOException e) { e.printStackTrace(); } finally { try { b1.close(); } catch (IOException ex) { Logger.getLogger(Flight_colllector.class.getName()).log(Level.SEVERE, null, ex); } } } @Override public void onTrackLimitationNotice(int arg0) { // TODO Auto-generated method stub } @Override public void onStallWarning(StallWarning sw) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }; FilterQuery fq = new FilterQuery(); String keywords[] = { "Indian Airlines, Indigo Airlines, Indigo Airline , Indian Airline , Spicejet , jetAirways , Jet Airways, Jet Airlines , airasia" }; //we will pass stock related keyword here fq.track(keywords); twitterStream.addListener(listener); twitterStream.filter(fq); }