public static void main(String[] args) throws TwitterException, IOException { Twitter twitter = TwitterFactory.getSingleton(); JLanguageTool langTool = new JLanguageTool(new AmericanEnglish()); List<String> twts = new ArrayList<String>(); for (String arg : args) { Query query = new Query(arg); QueryResult result; int counter = 0; do { result = twitter.search(query); List<Status> tweets = result.getTweets(); for (Status tweet : tweets) { if (isEligible(tweet)) { System.out.println("@" + tweet.getUser().getScreenName() + " - " + tweet.getText()); System.out.println(tweet.getLang()); twts.add(tweet.getText()); counter++; } } } while ((query = result.nextQuery()) != null && counter < 5); } for (String str : twts) { List<RuleMatch> matches = langTool.check(str); for (RuleMatch match : matches) { System.out.println( "Potential error at line " + match.getLine() + ", column " + match.getColumn() + ": " + match.getMessage()); System.out.println("Suggested correction: " + match.getSuggestedReplacements()); } } }
public static boolean isEligible(Status tweet) { if (!tweet.getLang().equalsIgnoreCase("en")) { return false; } else if (tweet.isRetweet()) { return false; } else { return true; } }
public boolean getFavorites(List<Status> statuses) { boolean newActivity = false; for (Status s : statuses) { if (s.getCreatedAt().getTime() > originalTime && tryInsertFavorites(s)) { newActivity = true; } } return newActivity; }
public boolean getRetweets(Twitter twitter, List<Status> statuses) { boolean newActivity = false; for (Status s : statuses) { if (s.getCreatedAt().getTime() > originalTime && tryInsertRetweets(s, twitter)) { newActivity = true; } } return newActivity; }
/** * Called when the user's timeline has arrived * * @param statuses The user's latest statuses */ @Override public void gotUserTimeline(ResponseList<Status> statuses) { SoomlaUtils.LogDebug(TAG, "getFeed/onComplete"); List<String> feeds = new ArrayList<String>(); for (Status post : statuses) { feeds.add(post.getText()); } boolean hasMore; if (feeds.size() >= PAGE_SIZE) { lastFeedCursor++; hasMore = true; } else { lastFeedCursor = 1; hasMore = false; } RefFeedListener.success(feeds, hasMore); clearListener(ACTION_GET_FEED); }
@Test public void testGetOspfLinkStatusDown() { EasyMock.expect( m_alarmDao.findMatching(EasyMock.anyObject(org.opennms.core.criteria.Criteria.class))) .andReturn(createDownAlarm()); EasyMock.expect( m_ospfLinkDao.findMatching(EasyMock.<org.opennms.core.criteria.Criteria>anyObject())) .andReturn(createOspfLinks()); EasyMock.replay(m_alarmDao, m_ospfLinkDao); List<EdgeRef> edges = createEdges(); Map<EdgeRef, Status> statusMap = m_statusProvider.getStatusForEdges(m_edgeProvider, edges, new Criteria[0]); assertEquals(1, statusMap.size()); assertEquals(edges.get(0), new ArrayList<EdgeRef>(statusMap.keySet()).get(0)); Status status = statusMap.get(edges.get(0)); assertEquals("down", status.computeStatus()); }
/** * Checks for a victory condition. * * @param {string} boardString Current state of the board. * @return {number} Status code for the victory state. */ @ApiMethod(name = "board.checkForVictory", path = "checkForVictory", httpMethod = "POST") public Status checkForVictory(Board board) { CellContainer cellContainer = CellContainer.fromJson(board.getState()); ArrayList<Cell> cells = cellContainer.cells; int num_free = 0; int score_player1 = 0; int score_player2 = 0; for (int i = 0; i < cells.size(); i++) { Cell cell = cells.get(i); if (0 < cell.val && cell.val <= 10) { num_free += 1; } else if (10 < cell.val && cell.val <= 20) { score_player1 += cell.val - 10; } else if (20 < cell.val && cell.val <= 30) { score_player2 += cell.val - 20; } } Status s = new Status(); System.out.println("num free:" + num_free); if (num_free > 0) { s.setStatus(0); return s; } if (score_player1 > score_player2) { s.setStatus(1); return s; } if (score_player1 < score_player2) { s.setStatus(2); return s; } s.setStatus(3); return s; };
/** * Update the tree according to the list of loaded roots * * @param roots the list of roots to add to the tree * @param uncheckedCommits the map from vcs root to commit identifiers that should be * uncheckedCommits */ private void updateTree(List<Root> roots, Map<VirtualFile, Set<String>> uncheckedCommits) { myTreeRoot.removeAllChildren(); if (roots == null) { roots = Collections.emptyList(); } for (Root r : roots) { CheckedTreeNode rootNode = new CheckedTreeNode(r); Status status = new Status(); status.root = r; rootNode.add(new DefaultMutableTreeNode(status, false)); Set<String> unchecked = uncheckedCommits != null && uncheckedCommits.containsKey(r.root) ? uncheckedCommits.get(r.root) : Collections.<String>emptySet(); for (Commit c : r.commits) { CheckedTreeNode child = new CheckedTreeNode(c); rootNode.add(child); child.setChecked(r.remoteName != null && !unchecked.contains(c.commitId())); } myTreeRoot.add(rootNode); } }
@Override public void readObject(BufferInput buffer, Alleycat alleycat) { status = Status.forId(buffer.readByte()); if (status == Status.OK) { error = null; term = buffer.readLong(); leader = buffer.readInt(); session = buffer.readLong(); members = alleycat.readObject(buffer); } else { error = RaftError.forId(buffer.readByte()); } }
@Test public void testStatus() { try { // get row count of experiments in the dataset int expected = getDataSet().getTable("Status").getRowCount(); // get number of experiments from the DAO int actual = getStatusDAO().count(); // test data contains 2 experiments, check size of returned list TestCase.assertEquals("Wrong number of Status", expected, actual); System.out.println("Expected number of Status: " + expected + ", actual: " + actual); for (Status d : random(getStatusDAO(), actual, 5)) { TestCase.assertNotNull(d); TestCase.assertNotNull(d.getStatusId()); } } catch (Exception e) { e.printStackTrace(); TestCase.fail(); } }
public CacheItemHolder mapRow(ResultSet rs, Connection connection) throws SQLException { URI uri = URI.create(rs.getString("uri")); Vary vary = convertToVary(rs.getString("vary")); Blob blob = rs.getBlob("payload"); Payload payload = null; if (blob != null && !rs.wasNull()) { payload = new InputStreamPayload( new ResultSetInputStream(rs, connection, blob.getBinaryStream()), MIMEType.valueOf(rs.getString("mimetype"))); } Status status = Status.valueOf(rs.getInt("status")); Headers headers = convertToHeaders(rs.getString("headers")); DateTime cacheTime = new DateTime(rs.getTimestamp("cachetime").getTime()); HTTPResponse response = new HTTPResponse(payload, status, headers); return new CacheItemHolder(uri, vary, new CacheItem(rewriteResponse(response), cacheTime)); }
private Map<String, Run> processRunJSON( HealthType ht, JSONArray runs, RequestManager requestManager) { Map<String, Run> updatedRuns = new HashMap<String, Run>(); List<Run> runsToSave = new ArrayList<Run>(); // 2011-01-25 15:37:27.093 DateFormat logDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); DateFormat simpleLogDateFormat = new SimpleDateFormat("yyyyMMdd"); Pattern simpleDateRegex = Pattern.compile("[0-9]{8}"); StringBuilder sb = new StringBuilder(); for (JSONObject run : (Iterable<JSONObject>) runs) { String runName = run.getString("runName"); sb.append("Processing " + runName + "\n"); log.debug("Processing " + runName); if (run.has("status")) { String xml = run.getString("status"); Status is = new SolidStatus(xml); is.setHealth(ht); is.setRunName(runName); Run r = null; Matcher m = p.matcher(runName); if (m.matches()) { try { r = requestManager.getRunByAlias(runName); } catch (IOException ioe) { log.warn( "Cannot find run by this alias. This usually means the run hasn't been previously imported. If attemptRunPopulation is false, processing will not take place for this run!"); } } try { if (attemptRunPopulation) { if (r == null) { log.debug("Saving new run and status: " + is.getRunName()); r = new SolidRun(xml); r.getStatus().setHealth(ht); if (run.has("fullPath")) { r.setFilePath(run.getString("fullPath")); } SequencerReference sr = null; if (run.has("sequencerName")) { sr = requestManager.getSequencerReferenceByName(run.getString("sequencerName")); r.getStatus().setInstrumentName(run.getString("sequencerName")); r.setSequencerReference(sr); } if (r.getSequencerReference() == null) { sr = requestManager.getSequencerReferenceByName(m.group(1)); r.getStatus().setInstrumentName(m.group(1)); r.setSequencerReference(sr); } if (r.getSequencerReference() == null) { sr = requestManager.getSequencerReferenceByName(r.getStatus().getInstrumentName()); r.setSequencerReference(sr); } if (r.getSequencerReference() != null) { if (run.has("startDate")) { try { log.debug("Updating start date:" + run.getString("startDate")); Matcher m2 = simpleDateRegex.matcher(run.getString("startDate")); if (m2.matches()) { r.getStatus() .setStartDate(simpleLogDateFormat.parse(run.getString("startDate"))); } else { r.getStatus().setStartDate(logDateFormat.parse(run.getString("startDate"))); } } catch (ParseException e) { log.error(e.getMessage()); e.printStackTrace(); } } if (run.has("completionDate")) { try { if (run.get("completionDate") != null && !run.getString("completionDate").equals("null")) { log.debug("Updating completion date:" + run.getString("completionDate")); r.getStatus() .setCompletionDate(logDateFormat.parse(run.getString("completionDate"))); } else { r.getStatus().setCompletionDate(null); } } catch (ParseException e) { log.error(e.getMessage()); e.printStackTrace(); } } } } else { log.debug("Updating existing run and status: " + is.getRunName()); r.setAlias(runName); r.setPlatformType(PlatformType.SOLID); if (r.getSequencerReference() == null) { SequencerReference sr = null; if (run.has("sequencerName")) { sr = requestManager.getSequencerReferenceByName(run.getString("sequencerName")); r.getStatus().setInstrumentName(run.getString("sequencerName")); r.setSequencerReference(sr); } if (r.getSequencerReference() == null) { sr = requestManager.getSequencerReferenceByName(m.group(1)); r.getStatus().setInstrumentName(m.group(1)); r.setSequencerReference(sr); } if (r.getSequencerReference() == null) { sr = requestManager.getSequencerReferenceByName(r.getStatus().getInstrumentName()); r.setSequencerReference(sr); } } if (r.getSequencerReference() != null) { if (run.has("startDate")) { try { log.debug("Updating start date:" + run.getString("startDate")); Matcher m2 = simpleDateRegex.matcher(run.getString("startDate")); if (m2.matches()) { r.getStatus() .setStartDate(simpleLogDateFormat.parse(run.getString("startDate"))); } else { r.getStatus().setStartDate(logDateFormat.parse(run.getString("startDate"))); } } catch (ParseException e) { log.error(e.getMessage()); e.printStackTrace(); } } if (run.has("completionDate")) { try { if (run.get("completionDate") != null && !run.getString("completionDate").equals("null")) { log.debug("Updating completion date:" + run.getString("completionDate")); r.getStatus() .setCompletionDate(logDateFormat.parse(run.getString("completionDate"))); } else { r.getStatus().setCompletionDate(null); } } catch (ParseException e) { log.error(e.getMessage()); e.printStackTrace(); } } // update path if changed if (run.has("fullPath") && !"".equals(run.getString("fullPath")) && r.getFilePath() != null && !"".equals(r.getFilePath())) { if (!run.getString("fullPath").equals(r.getFilePath())) { log.debug( "Updating run file path:" + r.getFilePath() + " -> " + run.getString("fullPath")); r.setFilePath(run.getString("fullPath")); } } // update status if run isn't completed or failed if (!r.getStatus().getHealth().equals(HealthType.Completed) && !r.getStatus().getHealth().equals(HealthType.Failed)) { log.debug( "Saving previously saved status: " + is.getRunName() + " (" + r.getStatus().getHealth().getKey() + " -> " + is.getHealth().getKey() + ")"); r.setStatus(is); } } } if (r.getSequencerReference() != null) { List<SequencerPartitionContainer<SequencerPoolPartition>> fs = ((SolidRun) r).getSequencerPartitionContainers(); if (fs.isEmpty()) { if (run.has("containerId") && !"".equals(run.getString("containerId"))) { Collection<SequencerPartitionContainer<SequencerPoolPartition>> pfs = requestManager.listSequencerPartitionContainersByBarcode( run.getString("containerId")); if (!pfs.isEmpty()) { if (pfs.size() == 1) { SequencerPartitionContainer lf = new ArrayList<SequencerPartitionContainer<SequencerPoolPartition>>(pfs) .get(0); if (lf.getSecurityProfile() != null && r.getSecurityProfile() == null) { r.setSecurityProfile(lf.getSecurityProfile()); } if (lf.getPlatform() == null && r.getSequencerReference().getPlatform() != null) { lf.setPlatform(r.getSequencerReference().getPlatform()); } // else { // lf.setPlatformType(PlatformType.SOLID); // } ((RunImpl) r).addSequencerPartitionContainer(lf); } } else { log.debug("No containers linked to run " + r.getId() + ": creating..."); SequencerPartitionContainer f = new SequencerPartitionContainerImpl(); f.setSecurityProfile(r.getSecurityProfile()); f.initEmptyPartitions(); f.setIdentificationBarcode(run.getString("containerNum")); if (f.getPlatform() == null && r.getSequencerReference().getPlatform() != null) { f.setPlatform(r.getSequencerReference().getPlatform()); } // else { // f.setPlatformType(PlatformType.SOLID); // } // f.setPaired(r.getPairedEnd()); ((RunImpl) r).addSequencerPartitionContainer(f); } } } else { SequencerPartitionContainer f = fs.iterator().next(); log.debug("Got container " + f.getId()); if (f.getSecurityProfile() == null) { f.setSecurityProfile(r.getSecurityProfile()); } if (f.getPlatform() == null && r.getSequencerReference().getPlatform() != null) { f.setPlatform(r.getSequencerReference().getPlatform()); } // else { // f.setPlatformType(PlatformType.SOLID); // } if (run.has("containerId") && !"".equals(run.getString("containerId"))) { f.setIdentificationBarcode(run.getString("containerId")); } long flowId = requestManager.saveSequencerPartitionContainer(f); f.setId(flowId); } updatedRuns.put(r.getAlias(), r); runsToSave.add(r); } } } catch (IOException e) { log.error(e.getMessage()); e.printStackTrace(); } } } try { if (runsToSave.size() > 0) { int[] saved = requestManager.saveRuns(runsToSave); log.info("Batch saved " + saved.length + " / " + runs.size() + " runs"); } } catch (IOException e) { log.error("Couldn't save run batch: " + e.getMessage()); e.printStackTrace(); } return updatedRuns; }
private scholl.both.analyzer.social.Post getSocial(Status s) { return new scholl.both.analyzer.social.Post( s.getText(), s.getCreatedAt().getTime(), new TwitterUser(s.getUser())); }
public static Record buildTweet(Schema schema, Status status) { GenericRecordBuilder builderTweet = new GenericRecordBuilder(schema); builderTweet.set("created_at", status.getCreatedAt().getTime()); builderTweet.set("favorite_count", status.getFavoriteCount()); builderTweet.set("favorited", status.isFavorited()); builderTweet.set("id", status.getId()); builderTweet.set("in_reply_to_screen_name", status.getInReplyToScreenName()); if (status.getInReplyToStatusId() != -1) builderTweet.set("in_reply_to_status_id", status.getInReplyToStatusId()); if (status.getInReplyToUserId() != -1) builderTweet.set("in_reply_to_user_id", status.getInReplyToUserId()); builderTweet.set("lang", status.getLang()); builderTweet.set("possibly_sensitive", status.isPossiblySensitive()); builderTweet.set("retweet_count", status.getRetweetCount()); builderTweet.set("retweeted", status.isRetweeted()); builderTweet.set("source", status.getSource()); builderTweet.set("text", status.getText()); builderTweet.set("truncated", status.isTruncated()); if (status.getWithheldInCountries() != null) builderTweet.set("withheld_in_countries", Arrays.asList(status.getWithheldInCountries())); if (status.getGeoLocation() != null) builderTweet.set( "coordinates", Arrays.asList( status.getGeoLocation().getLatitude(), status.getGeoLocation().getLongitude())); builderTweet.set("entities", buildEntities(schema.getField("entities").schema(), status)); if (status.getPlace() != null) builderTweet.set( "place", buildPlace(schema.getField("place").schema().getTypes().get(1), status.getPlace())); User user = status.getUser(); if (user != null && schema.getField("user") != null) { Schema schemaUser = schema.getField("user").schema(); GenericRecordBuilder builderUser = new GenericRecordBuilder(schemaUser); builderUser.set("contributors_enabled", user.isContributorsEnabled()); builderUser.set("created_at", user.getCreatedAt().getTime()); builderUser.set("default_profile", user.isDefaultProfile()); builderUser.set("default_profile_image", user.isDefaultProfileImage()); builderUser.set("description", user.getDescription()); builderUser.set( "entities", buildURLEntity(schemaUser.getField("entities").schema(), user.getURLEntity())); builderUser.set("favourites_count", user.getFavouritesCount()); builderUser.set("followers_count", user.getFollowersCount()); builderUser.set("friends_count", user.getFriendsCount()); builderUser.set("geo_enabled", user.isGeoEnabled()); builderUser.set("id", user.getId()); builderUser.set("is_translator", user.isTranslator()); builderUser.set("lang", user.getLang()); builderUser.set("listed_count", user.getListedCount()); builderUser.set("location", user.getLocation()); builderUser.set("name", user.getName()); builderUser.set("screen_name", user.getScreenName()); builderUser.set("profile_background_color", user.getProfileBackgroundColor()); builderUser.set("profile_background_image_url", user.getProfileBackgroundImageURL()); builderUser.set( "profile_background_image_url_https", user.getProfileBackgroundImageUrlHttps()); builderUser.set("profile_background_tile", user.isProfileBackgroundTiled()); builderUser.set("profile_banner_url", user.getProfileBannerURL()); builderUser.set("profile_image_url", user.getProfileImageURL()); builderUser.set("profile_image_url_https", user.getProfileBackgroundImageUrlHttps()); builderUser.set("profile_link_color", user.getProfileLinkColor()); builderUser.set("profile_sidebar_border_color", user.getProfileSidebarBorderColor()); builderUser.set("profile_sidebar_fill_color", user.getProfileSidebarFillColor()); builderUser.set("profile_text_color", user.getProfileTextColor()); builderUser.set("profile_use_background_image", user.isProfileUseBackgroundImage()); builderUser.set("protected", user.isProtected()); builderUser.set("show_all_inline_media", user.isShowAllInlineMedia()); builderUser.set("statuses_count", user.getStatusesCount()); builderUser.set("time_zone", user.getTimeZone()); builderUser.set("url", user.getURL()); builderUser.set("utc_offset", user.getUtcOffset()); builderUser.set("verified", user.isVerified()); if (user.getStatus() != null && schemaUser.getField("status") != null) builderUser.set( "status", buildTweet(schemaUser.getField("status").schema().getTypes().get(1), user.getStatus())); if (user.getWithheldInCountries() != null) builderUser.set("withheld_in_countries", Arrays.asList(user.getWithheldInCountries())); builderTweet.set("user", builderUser.build()); } if (status.getQuotedStatus() != null && schema.getField("quoted_status") != null) builderTweet.set( "quoted_status", buildTweet( schema.getField("quoted_status").schema().getTypes().get(1), status.getQuotedStatus())); if (status.getRetweetedStatus() != null && schema.getField("retweeted_status") != null) builderTweet.set( "retweeted_status", buildTweet( schema.getField("retweeted_status").schema().getTypes().get(1), status.getRetweetedStatus())); return builderTweet.build(); }
private static Record buildEntities(Schema schemaEntities, Status status) { GenericRecordBuilder builderEntities = new GenericRecordBuilder(schemaEntities); if (status.getHashtagEntities().length > 0) { Schema schemaHashtagObject = schemaEntities.getField("hashtags").schema().getElementType(); List<GenericRecord> listHashtagObjects = new ArrayList<>(); for (HashtagEntity hashtagEntity : status.getHashtagEntities()) { GenericRecordBuilder builderHashtagObject = new GenericRecordBuilder(schemaHashtagObject); builderHashtagObject.set("text", hashtagEntity.getText()); builderHashtagObject.set("start", hashtagEntity.getStart()); builderHashtagObject.set("end", hashtagEntity.getEnd()); listHashtagObjects.add(builderHashtagObject.build()); } builderEntities.set("hashtags", listHashtagObjects); } else builderEntities.set("hashtags", Collections.emptyList()); if (status.getSymbolEntities().length > 0) { Schema schemaSymbolObject = schemaEntities.getField("symbols").schema().getElementType(); List<GenericRecord> listSymbolObject = new ArrayList<>(); for (SymbolEntity symbolEntity : status.getSymbolEntities()) { GenericRecordBuilder builderSymbolObject = new GenericRecordBuilder(schemaSymbolObject); builderSymbolObject.set("text", symbolEntity.getText()); builderSymbolObject.set("start", symbolEntity.getStart()); builderSymbolObject.set("end", symbolEntity.getEnd()); listSymbolObject.add(builderSymbolObject.build()); } builderEntities.set("symbols", listSymbolObject); } else builderEntities.set("symbols", Collections.emptyList()); if (status.getMediaEntities().length > 0) { Schema schemaMediaObject = schemaEntities.getField("media").schema().getElementType(); List<GenericRecord> listMediaObject = new ArrayList<>(); for (MediaEntity mediaEntity : status.getMediaEntities()) { GenericRecordBuilder builderMediaObject = new GenericRecordBuilder(schemaMediaObject); builderMediaObject.set("url", mediaEntity.getURL()); builderMediaObject.set("display_url", mediaEntity.getDisplayURL()); builderMediaObject.set("expanded_url", mediaEntity.getExpandedURL()); builderMediaObject.set("id", mediaEntity.getId()); builderMediaObject.set("media_url", mediaEntity.getMediaURL()); builderMediaObject.set("media_url_https", mediaEntity.getMediaURLHttps()); builderMediaObject.set("type", mediaEntity.getType()); builderMediaObject.set("text", mediaEntity.getText()); builderMediaObject.set("start", mediaEntity.getStart()); builderMediaObject.set("end", mediaEntity.getEnd()); Schema schemaSize = schemaMediaObject.getField("sizes").schema().getValueType(); GenericRecordBuilder builderSize = new GenericRecordBuilder(schemaSize); Map<String, GenericRecord> mapSizes = new HashMap<>(4); for (int key : mediaEntity.getSizes().keySet()) { Size size = mediaEntity.getSizes().get(key); builderSize.set("h", size.getHeight()); builderSize.set("w", size.getWidth()); builderSize.set("resize", size.getResize()); mapSizes.put(Integer.toString(key), builderSize.build()); } builderMediaObject.set("sizes", mapSizes); listMediaObject.add(builderMediaObject.build()); } builderEntities.set("media", listMediaObject); } else builderEntities.set("media", Collections.emptyList()); if (status.getURLEntities().length > 0) { Schema schemaURLObject = schemaEntities.getField("urls").schema().getElementType(); List<GenericRecord> listURLObject1 = new ArrayList<>(); for (URLEntity urlEntity : status.getURLEntities()) listURLObject1.add(buildURLEntity(schemaURLObject, urlEntity)); builderEntities.set("urls", listURLObject1); } else builderEntities.set("urls", Collections.emptyList()); if (status.getUserMentionEntities().length > 0) { Schema schemaUserMentionObject = schemaEntities.getField("user_mentions").schema().getElementType(); List<GenericRecord> listUserMentionObject = new ArrayList<>(); for (UserMentionEntity userMentionEntity : status.getUserMentionEntities()) { GenericRecordBuilder builderUserMentionObject = new GenericRecordBuilder(schemaUserMentionObject); builderUserMentionObject.set("name", userMentionEntity.getName()); builderUserMentionObject.set("screen_name", userMentionEntity.getScreenName()); builderUserMentionObject.set("text", userMentionEntity.getText()); builderUserMentionObject.set("id", userMentionEntity.getId()); builderUserMentionObject.set("start", userMentionEntity.getStart()); builderUserMentionObject.set("end", userMentionEntity.getEnd()); listUserMentionObject.add(builderUserMentionObject.build()); } builderEntities.set("user_mentions", listUserMentionObject); } else builderEntities.set("user_mentions", Collections.emptyList()); if (status.getExtendedMediaEntities().length > 0) { Schema schemaExtendedMediaObject = schemaEntities.getField("extended_entities").schema().getElementType(); List<GenericRecord> listExtendedMediaObject = new ArrayList<>(); for (ExtendedMediaEntity extendedMediaEntity : status.getExtendedMediaEntities()) { GenericRecordBuilder builderExtendedMediaObject = new GenericRecordBuilder(schemaExtendedMediaObject); builderExtendedMediaObject.set("url", extendedMediaEntity.getURL()); builderExtendedMediaObject.set("display_url", extendedMediaEntity.getDisplayURL()); builderExtendedMediaObject.set("expanded_url", extendedMediaEntity.getExpandedURL()); builderExtendedMediaObject.set("id", extendedMediaEntity.getId()); builderExtendedMediaObject.set("media_url", extendedMediaEntity.getMediaURL()); builderExtendedMediaObject.set("media_url_https", extendedMediaEntity.getMediaURLHttps()); builderExtendedMediaObject.set("type", extendedMediaEntity.getType()); builderExtendedMediaObject.set("text", extendedMediaEntity.getText()); builderExtendedMediaObject.set("start", extendedMediaEntity.getStart()); builderExtendedMediaObject.set("end", extendedMediaEntity.getEnd()); Schema schemaSize = schemaExtendedMediaObject.getField("sizes").schema().getValueType(); GenericRecordBuilder builderSize = new GenericRecordBuilder(schemaSize); Map<String, GenericRecord> mapSizes = new HashMap<>(4); for (int key : extendedMediaEntity.getSizes().keySet()) { Size size = extendedMediaEntity.getSizes().get(key); builderSize.set("h", size.getHeight()); builderSize.set("w", size.getWidth()); builderSize.set("resize", size.getResize()); mapSizes.put(Integer.toString(key), builderSize.build()); } builderExtendedMediaObject.set("sizes", mapSizes); Schema schemaVideoInfo = schemaExtendedMediaObject.getField("video_info").schema(); GenericRecordBuilder builderVideoInfo = new GenericRecordBuilder(schemaVideoInfo); builderVideoInfo.set("h", extendedMediaEntity.getVideoAspectRatioHeight()); builderVideoInfo.set("w", extendedMediaEntity.getVideoAspectRatioWidth()); builderVideoInfo.set("duration_millis", extendedMediaEntity.getVideoDurationMillis()); Schema schemaVideoVariants = schemaVideoInfo.getField("variants").schema().getElementType(); List<GenericRecord> listVideoVariants = new ArrayList<>(); for (Variant extendedVideoVariant : extendedMediaEntity.getVideoVariants()) { GenericRecordBuilder builderVideoVariant = new GenericRecordBuilder(schemaVideoVariants); builderVideoVariant.set("bitrate", extendedVideoVariant.getBitrate()); builderVideoVariant.set("content_type", extendedVideoVariant.getContentType()); builderVideoVariant.set("url", extendedVideoVariant.getUrl()); listVideoVariants.add(builderVideoVariant.build()); } builderVideoInfo.set("variants", listVideoVariants); builderExtendedMediaObject.set("video_info", builderVideoInfo.build()); listExtendedMediaObject.add(builderExtendedMediaObject.build()); } builderEntities.set("extended_entities", listExtendedMediaObject); } else builderEntities.set("extended_entities", Collections.emptyList()); return builderEntities.build(); }
public void testStatusAsJSON() throws Exception { // single Status HttpClientImpl http = new HttpClientImpl(); List<Status> statuses = StatusJSONImpl.createStatusList( http.get("http://twitter4j.org/en/testcases/statuses/public_timeline.json"), conf); Status status = statuses.get(0); Assert.assertEquals(new Date(1259041785000l), status.getCreatedAt()); Assert.assertEquals(6000554383l, status.getId()); Assert.assertEquals("G_Shock22", status.getInReplyToScreenName()); Assert.assertEquals(6000444309l, status.getInReplyToStatusId()); Assert.assertEquals(20159829, status.getInReplyToUserId()); Assert.assertNull(status.getGeoLocation()); Assert.assertEquals("web", status.getSource()); Assert.assertEquals( "@G_Shock22 I smelled a roast session coming when yu said that shyt about @2koolNicia lol....", status.getText()); Assert.assertEquals(23459577, status.getUser().getId()); Assert.assertFalse(status.isRetweet()); assertDeserializedFormIsEqual(statuses); }
public void testRetweetStatusAsJSON() throws Exception { // single Status HttpClientImpl http = new HttpClientImpl(); Status status = new StatusJSONImpl( http.get("http://twitter4j.org/en/testcases/statuses/retweet/6010814202.json"), conf); Assert.assertEquals(new Date(1259078050000l), status.getCreatedAt()); Assert.assertEquals(6011259778l, status.getId()); Assert.assertEquals(null, status.getInReplyToScreenName()); Assert.assertEquals(-1l, status.getInReplyToStatusId()); Assert.assertEquals(-1, status.getInReplyToUserId()); Assert.assertNull(status.getGeoLocation()); Assert.assertEquals( "<a href=\"http://apiwiki.twitter.com/\" rel=\"nofollow\">API</a>", status.getSource()); Assert.assertEquals( "RT @yusukey: この前取材受けた奴 -> 次世代のシステム環境を見据えたアプリケーションサーバー製品の選択 ITpro: http://special.nikkeibp.co.jp/ts/article/0iaa/104388/", status.getText()); Assert.assertEquals(6358482, status.getUser().getId()); Assert.assertTrue(status.isRetweet()); assertDeserializedFormIsEqual(status); }
public static void main(String[] args) { try { meet myobj = new meet(); // load jsiconfig.txt ArrayList<String> myconfiglist = new ArrayList<String>(); myconfiglist = myobj.loadArray("jsiconfig.txt"); // The text uri // "mongodb://*****:*****@ds023288.mongolab.com:23288/sample"; String textUri = myconfiglist.get(0); // Create MongoClientURI object from which you get MongoClient obj MongoClientURI uri = new MongoClientURI(textUri); // Connect to that uri MongoClient m = new MongoClient(uri); // get the database named sample String DBname = myconfiglist.get(1); DB d = m.getDB(DBname); // get the collection mycollection in sample String collectionName = myconfiglist.get(2); DBCollection collection = d.getCollection(collectionName); // System.out.println("Config: "+textUri+":"+DBname+":"+collectionName); // twitter4j // Twitter twitter = new TwitterFactory().getInstance(); Twitter twitter = new TwitterFactory().getSingleton(); User user = twitter.verifyCredentials(); // Twitter collection of latest tweets into the home account - defaulted to latest 20 tweets// ////////////////////////////////////////////////////////////// ArrayList<String> mylatesttweetslist = new ArrayList<String>(); // get list of tweets from a user or the next tweet listed try { long actid = 0; // twitter.createFriendship(actid); // The factory instance is re-useable and thread safe. // Twitter twitter = TwitterFactory.getSingleton(); List<Status> statuses = twitter.getHomeTimeline(); System.out.println("Showing home timeline."); for (Status status : statuses) { // System.out.println(status.getUser().getName() + ":" +status.getText()); // Addes timeline to an array String mytweets = status.getUser().getName() + ":" + status.getText(); mylatesttweetslist.add(mytweets); } ; } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); System.exit(-1); } // MongoDB Insert Below // ////////////////////////// // System Date Date sd = new Date(); String sysdate = sd.toString(); // Toggle the below to display and insert the transactions as required boolean showtrans = true; boolean inserttrans = true; // checkArray - loads args to a text string to allow the contains function String checkString = ""; for (int ck = 0; ck < args.length; ck++) { checkString = checkString + args[ck]; } ; // display transactions flag on runnning jsimongo eg: java jsimongo -d will NOT display // transactions // insert transactions flag on runnning jsimongo eg: java jsimongo -i will NOT insert // transactions if (args.length > 0) { if (checkString.contains("-d")) showtrans = false; if (checkString.contains("-i")) inserttrans = false; } ; int x = 0; for (String atweet : mylatesttweetslist) { x++; // Display tweets to console if (showtrans == true) { System.out.println("tweet : " + atweet); System.out.println("Created_DateTime : " + sysdate); // was sysdate } ; // Insert JSON into MongoDB if (inserttrans == true) { BasicDBObject b = new BasicDBObject(); System.out.println("tweet : " + atweet); System.out.println("Created_DateTime : " + sysdate); // was sysdate // Insert the JSON object into the chosen collection collection.insert(b); } ; Thread.sleep(1); } ; System.out.println("End, the number of tweets inserted at this time was: " + x); } catch (Exception e) { e.printStackTrace(); } }