List of usage examples for twitter4j Status getText
String getText();
From source file:adapter.TwitterLanguageAdapter.java
License:Apache License
@Override public void run() { while (true) { try {//from w w w .ja va 2 s . com Status status = this.messageQueue.take(); Event event = new Event(); Tweet tweet = new Tweet(status.getId(), status.getText(), status.getCreatedAt(), status.getPlace(), status.getUser().getScreenName(), status.getUser().getLang(), status.getUser().getFollowersCount(), status.getUser().getFriendsCount(), status.getHashtagEntities(), status.getFavoriteCount(), status.getRetweetCount(), status.getGeoLocation()); eventCount++; // cantReplicas: Cantidad de PEs que se quieren generar para el proximo operador // Nota: recuerden que la topologa no necesariamente deba ser de este estilo // tambin poda ser por un hash int cantReplicas = 10; event.put("levelTweet", Integer.class, eventCount % cantReplicas); event.put("id", Integer.class, eventCount); event.put("tweet", Tweet.class, tweet); getRemoteStream().put(event); } catch (Exception e) { logger.error("Error: " + e); logger.error("Error al crear evento"); } } }
From source file:adapter.TwitterLocationAdapter.java
License:Apache License
@Override public void run() { while (true) { try {/* w w w. j a va 2 s. co m*/ Status status = this.messageQueue.take(); Event event = new Event(); Tweet tweet = new Tweet(status.getId(), status.getText(), status.getCreatedAt(), status.getPlace(), status.getUser().getScreenName(), status.getUser().getLang(), status.getUser().getFollowersCount(), status.getUser().getFriendsCount(), status.getHashtagEntities(), status.getFavoriteCount(), status.getRetweetCount(), status.getGeoLocation()); eventCount++; // cantReplicas: Cantidad de PEs que se quieren generar para el // proximo operador // Nota: recuerden que la topologa no necesariamente deba ser // de este estilo // tambin poda ser por un hash int cantReplicas = 10; event.put("levelTweet", Integer.class, eventCount % cantReplicas); event.put("id", Integer.class, eventCount); event.put("tweet", Tweet.class, tweet); getRemoteStream().put(event); } catch (Exception e) { logger.error("Error: " + e); logger.error("Error al crear evento"); } } }
From source file:ai.ilikeplaces.logic.Listeners.ListenerMain.java
License:Open Source License
/** * @param request__// w w w.ja v a 2 s .c o m * @param response__ */ @Override public void processRequest(final ItsNatServletRequest request__, final ItsNatServletResponse response__) { new AbstractListener(request__, response__) { protected String location; protected String superLocation; protected Long WOEID; /** * Initialize your document here by appending fragments */ @Override @SuppressWarnings("unchecked") @_todo(task = "If location is not available, it should be added through a w" + "id" + "get(or fragment maybe?)") protected final void init(final ItsNatHTMLDocument itsNatHTMLDocument__, final HTMLDocument hTMLDocument__, final ItsNatDocument itsNatDocument__, final Object... initArgs) { final SmartLogger sl = SmartLogger.start(Loggers.LEVEL.DEBUG, "Location Page.", 60000, null, true); //this.location = (String) request_.getServletRequest().getAttribute(RBGet.config.getString("HttpSessionAttr.location")); getLocationSuperLocation: { final String[] attr = ((String) request__.getServletRequest() .getAttribute(RBGet.globalConfig.getString(HTTP_SESSION_ATTR_LOCATION))).split("_"); location = attr[0]; if (attr.length == 3) { superLocation = attr[2]; } else { superLocation = EMPTY; } tryLocationId: { try { final String w = request__.getServletRequest().getParameter(Location.WOEID); if (w != null) { WOEID = Long.parseLong(request__.getServletRequest().getParameter(Location.WOEID)); } } catch (final NumberFormatException e) { Loggers.USER_EXCEPTION.error(WRONG_WOEID_FORMAT, e); } } } sl.appendToLogMSG(RETURNING_LOCATION + location + TO_USER); final ResourceBundle gUI = ResourceBundle.getBundle(AI_ILIKEPLACES_RBS_GUI); layoutNeededForAllPages: { setLoginWidget: { try { new SignInOn(request__, $(Main_login_widget), new SignInOnCriteria().setHumanId(new HumanId(getUsername())) .setSignInOnDisplayComponent( SignInOnCriteria.SignInOnDisplayComponent.MOMENTS)) { }; } catch (final Throwable t) { sl.l(ERROR_IN_UC_SET_LOGIN_WIDGET, t); } } SEO: { try { setMainTitle: { $(mainTitle).setTextContent( MessageFormat.format(gUI.getString("woeidpage.title"), location)); } setMetaDescription: { $(mainMetaDesc).setAttribute(MarkupTag.META.content(), MessageFormat.format(gUI.getString("woeidpage.desc"), location)); } } catch (final Throwable t) { sl.l(ERROR_IN_UC_SEO, t); } } signOnDisplayLink: { try { if (getUsername() != null) { $(Main_othersidebar_identity).setTextContent( gUI.getString(AI_ILIKEPLACES_LOGIC_LISTENERS_LISTENER_MAIN_0004) + getUsernameAsValid()); } else { $(Main_othersidebar_identity).setTextContent( gUI.getString(AI_ILIKEPLACES_LOGIC_LISTENERS_LISTENER_MAIN_0005) + location); } } catch (final Throwable t) { sl.l(ERROR_IN_UC_SIGN_ON_DISPLAY_LINK, t); } } setProfileLink: { try { if (getUsername() != null) { $(Main_othersidebar_profile_link).setAttribute(MarkupTag.A.href(), Controller.Page.Profile.getURL()); } else { $(Main_othersidebar_profile_link).setAttribute(MarkupTag.A.href(), Controller.Page.signup.getURL()); } } catch (final Throwable t) { sl.l(ERROR_IN_UC_SET_PROFILE_LINK, t); } } setProfilePhotoLink: { try { if (getUsername() != null) { /** * TODO check for db failure */ String url = DB.getHumanCRUDHumanLocal(true) .doDirtyRHumansProfilePhoto(new HumanId(getUsernameAsValid())) .returnValueBadly(); url = url == null ? null : RBGet.globalConfig.getString(PROFILE_PHOTOS) + url; if (url != null) { $(Main_profile_photo).setAttribute(MarkupTag.IMG.src(), url); //displayBlock($(Main_profile_photo)); } else { //displayNone($(Main_profile_photo)); } } else { //displayNone($(Main_profile_photo)); } } catch (final Throwable t) { sl.l(ERROR_IN_UC_SET_PROFILE_PHOTO_LINK, t); } } } final Return<Location> r; if (WOEID != null) { r = DB.getHumanCRUDLocationLocal(true).doRLocation(WOEID, REFRESH_SPEC); } else { r = new ReturnImpl<Location>(ExceptionCache.UNSUPPORTED_OPERATION_EXCEPTION, "Search Unavailable", false); //r = DB.getHumanCRUDLocationLocal(true).dirtyRLocation(location, superLocation); } if (r.returnStatus() == 0 && r.returnValue() != null) { final Location existingLocation_ = r.returnValue(); GEO: { if (existingLocation_.getLocationGeo1() == null || existingLocation_.getLocationGeo2() == null) { final Client ygpClient = YAHOO_GEO_PLANET_FACTORY .getInstance(RBGet.globalConfig.getString("where.yahooapis.com.v1.place")); final Place place = ygpClient.getPlace(existingLocation_.getLocationId().toString()); existingLocation_.setLocationGeo1(Double.toString(place.getCoordinates().getY())); existingLocation_.setLocationGeo2(Double.toString(place.getCoordinates().getX())); new Thread(new Runnable() { @Override public void run() { DB.getHumanCRUDLocationLocal(true).doULocationLatLng( new Obj<Long>(existingLocation_.getLocationId()), new Obj<Double>(place.getCoordinates().getY()), new Obj<Double>(place.getCoordinates().getX())); } }).run(); } } final Location locationSuperSet = existingLocation_.getLocationSuperSet(); GEO_WIDGET: { new ai.ilikeplaces.logic.Listeners.widgets.schema.thing.Comment(request__, new CommentCriteria(), $(Controller.Page.Main_right_column)) { @Override protected void init(CommentCriteria commentCriteria) { final ai.ilikeplaces.logic.Listeners.widgets.schema.thing.Place place = new ai.ilikeplaces.logic.Listeners.widgets.schema.thing.Place( request__, new PlaceCriteria() //This Place .setPlaceNamePre("Exciting events in ") .setPlaceName(existingLocation_.getLocationName()) .setPlaceLat(existingLocation_.getLocationGeo1()) .setPlaceLng(existingLocation_.getLocationGeo2()) //Parent Place //.setPlaceSuperName(locationSuperSet.getLocationName()) //.setPlaceSuperLat(locationSuperSet.getLocationGeo1()) //.setPlaceSuperLng(locationSuperSet.getLocationGeo2()) //Parent WOEID //.setPlaceSuperWOEID(locationSuperSet.getWOEID().toString()) , $$(CommentIds.commentPerson)); place.$$displayNone(place.$$( ai.ilikeplaces.logic.Listeners.widgets.schema.thing.Place.PlaceIds.placeWidget)); } }; } final List<String> titleManifest = new ArrayList<String>(); EVENTS_WIDGETS: { try { /* final JSONObject jsonObject = Modules.getModules().getYahooUplcomingFactory() .getInstance("http://upcoming.yahooapis.com/services/rest/") .get("", new HashMap<String, String>() { {//Don't worry, this is a static initializer of this map :) put("method", "event.search"); put("woeid", WOEID.toString()); put("format", "json"); } } ); final JSONArray events = jsonObject.getJSONObject("rsp").getJSONArray("event");*/ final JSONObject jsonObject = Modules.getModules().getEventulFactory() .getInstance("http://api.eventful.com/json/events/search/") .get("", new HashMap<String, String>() { {//Don't worry, this is a static initializer of this map :) put("location", "" + existingLocation_.getLocationGeo1() + "," + existingLocation_.getLocationGeo2()); put("within", "" + 100); } } ); Loggers.debug("Eventful Reply:" + jsonObject.toString()); // final String eventName = eventJSONObject.getString("title"); // final String eventUrl = eventJSONObject.getString("url"); // final String eventDate = eventJSONObject.getString("start_time"); // final String eventVenue = eventJSONObject.getString("venue_name"); final JSONArray events = jsonObject.getJSONObject("events").getJSONArray("event"); for (int i = 0; i < events.length(); i++) { final JSONObject eventJSONObject = new JSONObject(events.get(i).toString()); titleManifest.add(eventJSONObject.get("title").toString()); final String photoUrl; String temp = null; try { temp = eventJSONObject.getJSONObject("image").get("url").toString(); } catch (final Throwable e) { SmartLogger.g().l(e.getMessage()); } finally { photoUrl = temp; } //The pain I go through to make variables final :D new Event(request__, new EventCriteria() .setEventName(eventJSONObject.get("title").toString()) .setEventStartDate(eventJSONObject.get("start_time").toString()) .setEventPhoto(photoUrl) .setPlaceCriteria(new PlaceCriteria() .setPlaceNamePre("This event is taking place in ") .setPlaceName(existingLocation_.getLocationName()) .setPlaceLat(eventJSONObject.get("latitude").toString()) .setPlaceLng(eventJSONObject.get("longitude").toString()) //Parent Place .setPlaceSuperNamePre( existingLocation_.getLocationName() + " is located in ") .setPlaceSuperName(locationSuperSet.getLocationName()) .setPlaceSuperLat(locationSuperSet.getLocationGeo1()) .setPlaceSuperLng(locationSuperSet.getLocationGeo2()) //Parent WOEID .setPlaceSuperWOEID(locationSuperSet.getWOEID().toString()) ), $(Controller.Page.Main_right_column)); } } catch (final JSONException e) { sl.l("Error fetching data from Yahoo Upcoming: " + e.getMessage()); } } TWITTER_WIDGETS: { try { final Query _query = new Query( "fun OR happening OR enjoy OR nightclub OR restaurant OR party OR travel :)"); _query.geoCode( new GeoLocation(Double.parseDouble(existingLocation_.getLocationGeo1()), Double.parseDouble(existingLocation_.getLocationGeo2())), 40, Query.MILES); _query.setResultType(Query.MIXED); final QueryResult result = TWITTER.search(_query); //final QueryResult result = TWITTER.search(new Query("Happy").geoCode(new GeoLocation(Double.parseDouble(existingLocation_.getLocationGeo1()), Double.parseDouble(existingLocation_.getLocationGeo2())), 160, Query.MILES)); for (Status tweet : result.getTweets()) { new ai.ilikeplaces.logic.Listeners.widgets.schema.thing.Person(request__, new PersonCriteria().setPersonName(tweet.getUser().getName()) .setPersonPhoto(tweet.getUser().getProfileImageURL()) .setPersonData(tweet.getText()), $(Main_right_column)); titleManifest.add(tweet.getText()); } if (result.getTweets().size() == 0) { sl.l("No twitter results found"); } } catch (final Throwable t) { sl.l("An error occurred during twitter fetch:" + t.getMessage()); } } SEO: { setMetaGEOData: { $(Main_ICBM).setAttribute(MarkupTag.META.content(), existingLocation_.getLocationGeo1() + COMMA + existingLocation_.getLocationGeo2()); $(Main_geoposition).setAttribute(MarkupTag.META.content(), existingLocation_.getLocationGeo1() + COMMA + existingLocation_.getLocationGeo2()); $(Main_geoplacename).setAttribute(MarkupTag.META.content(), existingLocation_.getLocationName()); $(Main_georegion).setAttribute(MarkupTag.META.content(), locationSuperSet.getLocationName()); } } setLocationIdForJSReference: { try { final Element hiddenLocationIdInputTag = $(INPUT); hiddenLocationIdInputTag.setAttribute(INPUT.type(), INPUT.typeValueHidden()); hiddenLocationIdInputTag.setAttribute(INPUT.id(), JSCodeToSend.LocationId); hiddenLocationIdInputTag.setAttribute(INPUT.value(), existingLocation_.getLocationId().toString()); hTMLDocument__.getBody().appendChild(hiddenLocationIdInputTag); $(Main_location_name).setAttribute(INPUT.value(), existingLocation_.getLocationName() + ""); $(Main_super_location_name).setAttribute(INPUT.value(), locationSuperSet.getLocationName() + ""); } catch (final Throwable t) { sl.l(ERROR_IN_UC_SET_LOCATION_ID_FOR_JSREFERENCE, t); } } setLocationNameForJSReference: { try { final Element hiddenLocationIdInputTag = $(INPUT); hiddenLocationIdInputTag.setAttribute(INPUT.type(), INPUT.typeValueHidden()); hiddenLocationIdInputTag.setAttribute(INPUT.id(), JSCodeToSend.LocationName); hiddenLocationIdInputTag.setAttribute(INPUT.value(), existingLocation_.getLocationName() + OF + locationSuperSet.getLocationName()); hTMLDocument__.getBody().appendChild(hiddenLocationIdInputTag); } catch (final Throwable t) { sl.l(ERROR_IN_UC_SET_LOCATION_NAME_FOR_JSREFERENCE, t); } } setLocationAsPageTopic: { try { final StringBuilder title = new StringBuilder(); for (final String titleGuest : titleManifest) { title.append(titleGuest); } final String finalTitle = title.toString(); $(Main_center_main_location_title).setTextContent(finalTitle.isEmpty() ? (THIS_IS + existingLocation_.getLocationName() + OF + locationSuperSet) : finalTitle); for (final Element element : generateLocationLinks(DB.getHumanCRUDLocationLocal(true) .doDirtyRLocationsBySuperLocation(existingLocation_))) { $(Main_location_list).appendChild(element); displayBlock($(Main_notice_sh)); } } catch (final Throwable t) { sl.l(ERROR_IN_UC_SET_LOCATION_AS_PAGE_TOPIC, t); } } } else { noSupportForNewLocations: { try { // $(Main_notice).appendChild(($(P).appendChild( // hTMLDocument__.createTextNode(RBGet.logMsgs.getString("CANT_FIND_LOCATION") // + " Were you looking for " // )))); // for (final Element element : generateLocationLinks(DB.getHumanCRUDLocationLocal(true).dirtyRLikeLocations(location))) { // $(Main_notice).appendChild(element); // displayBlock($(Main_notice_sh)); // } NotSupportingLikeSearchTooForNow: { $(Main_notice).appendChild(($(P).appendChild(hTMLDocument__ .createTextNode(RBGet.logMsgs.getString("CANT_FIND_LOCATION"))))); } } catch (final Throwable t) { sl.l(ERROR_IN_UC_NO_SUPPORT_FOR_NEW_LOCATIONS, t); } } } sl.complete(Loggers.LEVEL.SERVER_STATUS, Loggers.DONE); } /** * Use ItsNatHTMLDocument variable stored in the AbstractListener class */ @Override protected void registerEventListeners(final ItsNatHTMLDocument itsNatHTMLDocument__, final HTMLDocument hTMLDocument__, final ItsNatDocument itsNatDocument__) { } private List<Element> generateLocationLinks(final List<Location> locationList) { final ElementComposer UList = ElementComposer.compose($(UL)).$ElementSetAttribute(MarkupTag.UL.id(), PLACE_LIST); for (Location location : locationList) { final Element link = $(A); link.setTextContent(TRAVEL_TO + location.getLocationName() + OF + location.getLocationSuperSet().getLocationName()); link.setAttribute(A.href(), PAGE + location.getLocationName() + _OF_ + location.getLocationSuperSet().getLocationName() + Parameter.get(Location.WOEID, location.getWOEID().toString(), true)); link.setAttribute(A.alt(), PAGE + location.getLocationName() + _OF_ + location.getLocationSuperSet().getLocationName()); link.setAttribute(A.title(), CLICK_TO_EXPLORE + location.getLocationName() + OF + location.getLocationSuperSet().getLocationName()); link.setAttribute(A.classs(), VTIP); final Element linkDiv = $(DIV); linkDiv.appendChild(link); UList.wrapThis(ElementComposer.compose($(LI)).wrapThis(linkDiv).get()); } final List<Element> elements = new ArrayList<Element>(); elements.add(UList.get()); return elements; } private Element generateLocationLink(final Location location) { final Element link = $(A); link.setTextContent(TRAVEL_TO + location.getLocationName() + OF + location.getLocationSuperSet().getLocationName()); link.setAttribute(A.href(), PAGE + location.getLocationName() + _OF_ + location.getLocationSuperSet().getLocationName() + Parameter.get(Location.WOEID, location.getWOEID().toString(), true)); link.setAttribute(A.alt(), PAGE + location.getLocationName() + _OF_ + location.getLocationSuperSet().getLocationName()); return link; } private Element generateSimpleLocationLink(final Location location) { final Element link = $(A); link.setTextContent(location.getLocationName()); link.setAttribute(A.href(), PAGE + location.getLocationName() + Parameter.get(Location.WOEID, location.getWOEID().toString(), true)); link.setAttribute(A.alt(), PAGE + location.getLocationName()); return link; } };//Listener }
From source file:aic.group5.topic3.analysis.TwitterSentimentAnalyzer.java
License:Apache License
public static SentimentResult analyzeTweets(String query, TwitterQueryWrapper twitterWrapper, Classifier classifier) {/*from w w w . ja va2 s. c o m*/ SentimentResult result = new SentimentResult(query); try { for (Status tweet : twitterWrapper.query(query)) { result.acceptResult(classifier.classify(tweet.getText())); } result.setSuccess(true); } catch (Exception ex) { ex.printStackTrace(); result.setSuccess(false); result.setException(ex.toString()); } return result; }
From source file:apptwitter.Metodos.java
public void verTL() throws TwitterException { List<Status> statuses = twitter.getHomeTimeline(); System.out.println("Showing home timeline."); for (Status status : statuses) { System.out.println(status.getUser().getName() + ":" + status.getText()); }/*from ww w .j a v a 2 s . c o m*/ }
From source file:apptwitter.Metodos.java
public void buscarTrending(String busqueda) throws TwitterException { Query query = new Query(busqueda); QueryResult result = twitter.search(query); for (Status status : result.getTweets()) { System.out.println("@" + status.getUser().getScreenName() + ":" + status.getText()); }/*from w w w . java 2 s. c om*/ }
From source file:apptwitter.Metodos.java
public void tweetear(String tweet) throws TwitterException { Status status = twitter.updateStatus(tweet); System.out.println("Successfully updated the status to [" + status.getText() + "]."); }
From source file:at.ac.tuwien.infosys.cloudscale.sample.sentiment.task.TwitterSentimentAnalyzer.java
License:Apache License
public static SentimentResult analyzeTweets(String query, TwitterQueryWrapper twitterWrapper, Classifier classifier, IEventSink events) { SentimentResult result = new SentimentResult(query); try {//from w w w . j a v a2 s. c om for (Status tweet : twitterWrapper.query(query)) { long begin = System.currentTimeMillis(); result.acceptResult(classifier.classify(tweet.getText())); long end = System.currentTimeMillis(); // trigger an event that contains the processing time for this tweet // TODO: there should be a nicer way to get this UUID serverId = CloudScaleServerRunner.getInstance().getId(); events.trigger( new ClassificationDurationEvent(tweet.getText(), (end - begin), serverId.toString())); } result.setSuccess(true); } catch (Exception ex) { ex.printStackTrace(); result.setSuccess(false); result.setException(ex.toString()); } return result; }
From source file:at.illecker.sentistorm.spout.TwitterStreamSpout.java
License:Apache License
@Override public void nextTuple() { Status tweet = m_tweetsQueue.poll(); if (tweet == null) { TimeUtils.sleepMillis(50); // sleep 50 ms } else {//from www. j a v a 2 s. co m // Emit tweet m_collector.emit(new Values(tweet.getId(), tweet.getText(), null)); } }
From source file:at.illecker.storm.commons.spout.TwitterFilesSpout.java
License:Apache License
public void nextTuple() { Status tweet = m_tweets.get(m_index); // infinite loop m_index++;/*w ww. ja v a2 s .c om*/ if (m_index >= m_tweets.size()) { m_index = 0; } // Emit tweet m_collector.emit(new Values(tweet.getId(), tweet.getText(), null)); // Optional sleep between emitting tuples if (m_tupleSleepMs != 0) { TimeUtils.sleepMillis(m_tupleSleepMs); } }