List of usage examples for twitter4j Status getFavoriteCount
int getFavoriteCount();
From source file:public_streaming.SampleStream.java
License:Apache License
public void onStatus(Status status) { System.out.println("tweet:" + status.getText());// System.out.println(status.getFavoriteCount()); System.out.println("User" + status.getUser().getName() + "@" + status.getUser().getScreenName());//??,?(@xx) System.out.println("Posted Time:" + status.getCreatedAt());// System.out.println("Application Name:" + status.getSource());// System.out.println("Time Zone:" + status.getUser().getTimeZone());// System.out.println("Created Date:" + status.getUser().getCreatedAt());//? System.out.println("GeoLocation:" + status.getUser().getLocation());//? System.out.println("postID:" + status.getId());//ID System.out.println("UserID" + status.getUser().getId());//ID System.out.println("Language:" + status.getUser().getLang());// System.out.println("Follow:" + status.getUser().getFriendsCount());// System.out.println("Follower:" + status.getUser().getFollowersCount());// }
From source file:rtb.PopularTweetCollector.java
License:Apache License
/** * Write out the list of tweets to JSON form. * @param statuses the list of statuses/* w w w . ja v a 2s .com*/ * @param fileName JSON file name * @throws JsonParseException * @throws IOException */ public void writeAsJson(List<? extends Status> statuses, String fileName) throws JsonParseException, IOException { if (statuses == null || fileName == null) throw new NullPointerException(); if (statuses.isEmpty()) return; // Convert Status to TweetPojo List<Tweet> pojos = new ArrayList<>(statuses.size()); for (Status s : statuses) { // Get tweet text String text = s.getText().replaceAll("[\n\t]", " "); // Get formatted date text DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm"); String date = formatter.format(s.getCreatedAt()); String screenName = s.getUser().getScreenName(); pojos.add(new Tweet(screenName, text, date, s.getFavoriteCount(), getTweetURL(s))); } // Write out TweetPojo as JSON FileWriter writer = new FileWriter(new File(fileName)); ObjectMapper mapper = new ObjectMapper(); mapper.writeValue(writer, pojos); }
From source file:ru.mail.sphere.java_hw5_vasilyev.twitteraccessor.Accessor.java
private static Tweet buildTweetFromStatus(final Status status) { return new Tweet(status.getText(), status.getCreatedAt(), status.getFavoriteCount(), status.getRetweetCount(), status.getLang()); }
From source file:tweets.Tweets.java
/** * @param args the command line arguments *//*from w ww . jav a2 s. com*/ public static void main(String[] args) throws Exception { ConfigurationBuilder configurtacion = new ConfigurationBuilder(); configurtacion.setDebugEnabled(true).setOAuthConsumerKey("KdVOb7h8mqcjWIfkXXED2G6sJ") .setOAuthConsumerSecret("EXImfgfGCYIbWZIOSEeYVvaDE5oxwJZY7UIuwUusbyRWf2ds7l") .setOAuthAccessToken("785481406654722049-aRARaHgZujPZIdpYla4mVZIMMlvzJRb") .setOAuthAccessTokenSecret("YWWQwbFw8K7rxsnivwpBRZVoQlUhMYy7gOs7KUWOb8Rvy"); Twitter twitter = new TwitterFactory(configurtacion.build()).getInstance(); twitter.getUserTimeline(); String hashtag = "#ElectionNight"; Query busqueda = new Query(hashtag); int numeroTweets = 1500; long ultimo = Long.MAX_VALUE; ArrayList<Status> tweets = new ArrayList<Status>(); while (tweets.size() < numeroTweets) { if (numeroTweets - tweets.size() > 255) { busqueda.setCount(255); } else { busqueda.setCount(numeroTweets - tweets.size()); } try { QueryResult result = twitter.search(busqueda); tweets.addAll(result.getTweets()); System.out.println("Generados " + tweets.size() + " tweets" + "\n"); for (Status t : tweets) { if (t.getId() < ultimo) { ultimo = t.getId(); } System.out.println("Generados " + tweets.size() + " tweets" + "\n"); } } catch (TwitterException excepcion) { System.out.println("Sin conexin " + excepcion); } ; busqueda.setMaxId(ultimo - 1); } // guardamos los datos java.util.Date fecha = new Date(); int hora = fecha.getHours(); int minuto = fecha.getMinutes(); System.out.println(); String nombre = "Datos_" + hashtag + " " + hora + " " + minuto + ".txt"; File f = new File(nombre); FileWriter fw = new FileWriter(f); BufferedWriter bw = new BufferedWriter(fw); System.out.println("identificador\tUsuario\ttweet\n"); for (int i = 0; i < tweets.size(); i++) { Status estadoTweet = (Status) tweets.get(i); GeoLocation loc = estadoTweet.getGeoLocation(); String user = estadoTweet.getUser().getScreenName(); String msg = estadoTweet.getText(); Boolean sensitive = estadoTweet.isPossiblySensitive(); int fav = estadoTweet.getFavoriteCount(); System.out.println("Id: " + i + "| User: " + user + "| Texto: " + msg + "| SentimientoPositivo: " + sensitive + "$\n"); int id = i + 1; bw.append(msg + " | " + sensitive + ";"); bw.newLine(); } bw.close(); }
From source file:Twitter.Frame.java
public Document statustoJSON(Status status) { Document doc = new Document(); if (status.getText() != null) doc.append("tweet", status.getText()); if (status.getUser().getName() != null) doc.append("name", status.getUser().getName()); if (status.getPlace() != null) doc.append("place", status.getPlace().toString()); if (status.getUser().getScreenName() != null) doc.append("nick", status.getUser().getScreenName()); if (status.getGeoLocation() != null) doc.append("gloc", status.getGeoLocation().toString()); doc.append("fcont", status.getFavoriteCount()); doc.append("rcunt", status.getRetweetCount()); if (status.getRetweetedStatus() != null) doc.append("rstate", status.getRetweetedStatus().getText()); tacol.setText(tacol.getText() + doc.toJson() + "\n");//imprimimos el tweet en el frame return doc;/*from w w w .ja v a 2 s. c om*/ }
From source file:TwitterDownload.TwitterExel.java
public static String writeTweets(long ID, List<Status> tweets, String path) { try {//ww w . j a v a 2s . com path = path + "Tweets"; File theDir = new File(path); // if the directory does not exist, create it if (!theDir.exists()) { theDir.mkdir(); } String exlPath = path + "/" + ID + ".xls"; File exlFile = new File(exlPath); WritableWorkbook writableWorkbook = null; WritableSheet writableSheet = null; int i = 0; while (exlFile.exists()) { i++; exlPath = path + "/" + ID + "_" + i + ".xls"; exlFile = new File(exlPath); } writableWorkbook = Workbook.createWorkbook(exlFile); writableSheet = writableWorkbook.createSheet("FerretData", 0); try { Workbook existing = Workbook.getWorkbook(exlFile); writableWorkbook = Workbook.createWorkbook(exlFile, existing); writableSheet = writableWorkbook.getSheet(0); } catch (BiffException be) { } //Create Cells with contents of different data types. //Also specify the Cell coordinates in the constructor i = 0; i = writableSheet.getRows(); if (i == 0) { Label text = new Label(0, 0, "Tweeted Text"); Label date = new Label(1, 0, "Tweeted Date"); Label reTweets = new Label(2, 0, "ReTweet Count"); Label favor = new Label(3, 0, "Favourite Count"); Label place = new Label(4, 0, "Place"); Label geo = new Label(5, 0, "GeoLocation"); Label link = new Label(6, 0, "Link"); Label user = new Label(7, 0, "User"); //Add the created Cells to the sheet writableSheet.addCell(text); writableSheet.addCell(date); writableSheet.addCell(reTweets); writableSheet.addCell(favor); writableSheet.addCell(place); writableSheet.addCell(geo); writableSheet.addCell(link); writableSheet.addCell(user); i = 1; } for (int j = 0; j < tweets.size(); j++) { Status s = tweets.get(j); String placeString = s.getPlace() != null ? s.getPlace().toString() : ""; if (placeString.contains("{")) placeString = placeString.substring(placeString.indexOf("{"), placeString.length() - 1); Label text = new Label(0, i + j, s.getText()); DateTime date = new DateTime(1, i + j, s.getCreatedAt()); Number reTweets = new Number(2, i + j, s.getRetweetCount()); Number favor = new Number(3, i + j, s.getFavoriteCount()); Label place = new Label(4, j + 1, placeString); Label geo = new Label(5, j + 1, s.getGeoLocation() != null ? s.getGeoLocation().toString() : ""); String link = "https://twitter.com/" + s.getUser().getScreenName() + "/status/" + s.getId(); URL url = new URL(link); WritableHyperlink hl = new WritableHyperlink(6, j + 1, url); Label user = new Label(7, j + 1, s.getUser().getScreenName()); //Add the created Cells to the sheet writableSheet.addCell(text); writableSheet.addCell(date); writableSheet.addCell(reTweets); writableSheet.addCell(favor); writableSheet.addCell(place); writableSheet.addCell(geo); writableSheet.addHyperlink(hl); writableSheet.addCell(user); } //Write and close the workbook writableWorkbook.write(); writableWorkbook.close(); return exlPath; } catch (IOException e) { e.printStackTrace(); } catch (RowsExceededException e) { e.printStackTrace(); } catch (WriteException e) { e.printStackTrace(); } return null; }
From source file:TwitterStats.Facade.Twitter.java
public List<Status> getTuitsCuenta(String user, int estudio, int cantidad) throws TwitterException { ResponseList res;/*from w ww .j a va 2 s.c om*/ List<Status> lista = new ArrayList<>(); for (int i = 1; i <= estudio / 200; i++) { res = twitter.getUserTimeline(user, new Paging(i, 200)); lista.addAll(res); } Collections.sort(lista, new Comparator<Status>() { public int compare(Status s1, Status s2) { return s1.getFavoriteCount() > s2.getFavoriteCount() ? -1 : (s1.getFavoriteCount() < s2.getFavoriteCount()) ? 1 : 0; } }); if (lista.size() > cantidad) { return lista.subList(0, cantidad); } else { return lista; } }
From source file:TwitterStats.Facade.Twitter.java
public List<Status> getTuitsCuenta(long id, int estudio, int cantidad) throws TwitterException { ResponseList res;//from w w w. ja v a 2 s . c o m List<Status> lista = new ArrayList<>(); for (int i = 1; i <= estudio / 200; i++) { res = twitter.getUserTimeline(id, new Paging(i, 200)); lista.addAll(res); } Collections.sort(lista, new Comparator<Status>() { public int compare(Status s1, Status s2) { return s1.getFavoriteCount() > s2.getFavoriteCount() ? -1 : (s1.getFavoriteCount() < s2.getFavoriteCount()) ? 1 : 0; } }); if (lista.size() > cantidad) { return lista.subList(0, cantidad); } else { return lista; } }
From source file:TwitterStats.Facade.Twitter.java
public List<Status> getTuitsCuenta(String user, Date desde, Date hasta, int cantidad) throws TwitterException { SimpleDateFormat dt = new SimpleDateFormat("yyyy-MM-dd"); Query q = new Query("from:" + user + " since:" + dt.format(desde) + " until:" + dt.format(hasta)); q.setCount(100);// www . j av a 2 s . com List<Status> lista = new ArrayList<>(); List<Status> res = twitter.search(q).getTweets(); while (res.size() > 1 && lista.size() < 3000) { lista.addAll(res); q.setMaxId(res.get(res.size() - 1).getId()); res = twitter.search(q).getTweets(); } Collections.sort(lista, new Comparator<Status>() { public int compare(Status s1, Status s2) { return s1.getFavoriteCount() > s2.getFavoriteCount() ? -1 : (s1.getFavoriteCount() < s2.getFavoriteCount()) ? 1 : 0; } }); if (lista.size() > cantidad) { return lista.subList(0, cantidad); } else { return lista; } }
From source file:uk.co.flax.ukmp.twitter.TweetUpdateThread.java
License:Apache License
private Tweet buildTweetFromStatus(Status status) { String text = status.getText(); Tweet tweet = new Tweet(); tweet.setId("" + status.getId()); tweet.setText(text);/* ww w .j a v a2 s . co m*/ tweet.setUserScreenName(status.getUser().getScreenName()); tweet.setUserName(status.getUser().getName()); tweet.setCreated(status.getCreatedAt()); if (status.getPlace() != null) { tweet.setPlaceName(status.getPlace().getFullName()); tweet.setCountry(status.getPlace().getCountry()); } tweet.setRetweetCount(status.getRetweetCount()); tweet.setFavouriteCount(status.getFavoriteCount()); tweet.setParty(partyListIds.get(status.getUser().getId())); if (status.getUserMentionEntities() != null) { List<String> screenNames = new ArrayList<>(status.getUserMentionEntities().length); List<String> fullNames = new ArrayList<>(status.getUserMentionEntities().length); for (UserMentionEntity ent : status.getUserMentionEntities()) { screenNames.add(ent.getScreenName()); if (StringUtils.isNotBlank(ent.getName())) { fullNames.add(ent.getName()); } } tweet.setMentionScreenNames(screenNames); tweet.setMentionFullNames(fullNames); } if (status.getHashtagEntities().length > 0) { List<String> hashtags = new ArrayList<>(status.getHashtagEntities().length); for (HashtagEntity ht : status.getHashtagEntities()) { hashtags.add(ht.getText()); } tweet.setHashtags(hashtags); } // Call the entity extraction service Map<String, List<String>> entities = entityExtraction.getEntities(text); if (entities != null && !entities.isEmpty()) { Map<String, Object> tweetEntities = new HashMap<String, Object>(); entities.keySet().forEach(type -> tweetEntities.put(type, entities.get(type))); tweet.setEntities(tweetEntities); } return tweet; }