List of usage examples for twitter4j URLEntity getURL
String getURL();
From source file:dk.netarkivet.harvester.tools.TwitterDecidingScope.java
License:Open Source License
/** * Adds links to embedded url's and media in a tweet. * * @param tweet The tweet from which links are to be extracted. *///from w w w . j a va 2 s . c om private void extractEmbeddedLinks(Tweet tweet) { final URLEntity[] urlEntities = tweet.getURLEntities(); if (urlEntities != null) { for (URLEntity urlEntity : urlEntities) { addSeedIfLegal(urlEntity.getURL().toString()); addSeedIfLegal(urlEntity.getExpandedURL().toString()); linkCount++; } } final MediaEntity[] mediaEntities = tweet.getMediaEntities(); if (mediaEntities != null) { for (MediaEntity mediaEntity : mediaEntities) { final String mediaUrl = mediaEntity.getMediaURL().toString(); addSeedIfLegal(mediaUrl); linkCount++; } } }
From source file:info.usbo.skypetwitter.Run.java
License:Apache License
public static void main(String[] args) throws SkypeException, IOException { System.out.println("Working Directory = " + System.getProperty("user.dir")); Properties props = new Properties(); loadProperties(props, "twitter4j.properties"); loadProperties(props, "skype.properties"); loadProperties(props, "app.properties"); String chat_group_id = props.getProperty("skype.chat_group_id"); String twitter_user_id = props.getProperty("twitter.user"); data_dir = props.getProperty("data.dir"); Integer twitter_timeout = Integer.parseInt(props.getProperty("twitter.timeout")); System.out.println("Twitter user: " + twitter_user_id); System.out.println("Twitter timeout: " + twitter_timeout); if ("".equals(twitter_user_id)) { return;// w w w .j a v a2s.c om } if (load_file() == 0) { System.out.println("File not found"); return; } while (true) { bChanged = 0; SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm"); System.out.println("Looking at " + sdf.format(Calendar.getInstance().getTime())); Chat ch = Skype.chat(chat_group_id); Twitter twitter = new TwitterFactory().getInstance(); try { List<Status> statuses; statuses = twitter.getUserTimeline(twitter_user_id); String sText; for (Status status : statuses) { Date d = status.getCreatedAt(); // ? Calendar cal = Calendar.getInstance(); cal.setTime(d); cal.add(Calendar.HOUR_OF_DAY, 7); d = cal.getTime(); sText = "@" + status.getUser().getScreenName() + " " + sdf.format(d) + " ( https://twitter.com/" + twitter_user_id + "/status/" + status.getId() + " ): \r\n" + status.getText() + "\r\n***"; for (URLEntity e : status.getURLEntities()) { sText = sText.replaceAll(e.getURL(), e.getExpandedURL()); } for (MediaEntity e : status.getMediaEntities()) { sText = sText.replaceAll(e.getURL(), e.getMediaURL()); } if (twitter_ids.indexOf(status.getId()) == -1) { System.out.println(sText); ch.send(sText); twitter_ids.add(status.getId()); bChanged = 1; } } } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); // System.exit(-1); } catch (SkypeException ex) { ex.printStackTrace(); System.out.println("Failed to send message: " + ex.getMessage()); } // VK try { vk(); for (VK v : vk) { if (vk_ids.indexOf(v.getId()) == -1) { Date d = v.getDate(); // ? Calendar cal = Calendar.getInstance(); cal.setTime(d); cal.add(Calendar.HOUR_OF_DAY, 7); d = cal.getTime(); String sText = "@Depersonilized (VK) " + sdf.format(d) + " ( http://vk.com/Depersonilized?w=wall-0_" + v.getId() + " ): \r\n" + v.getText(); if (!"".equals(v.getAttachment())) { sText += "\r\n" + v.getAttachment(); } sText += "\r\n***"; System.out.println(sText); ch.send(sText); vk_ids.add(v.getId()); bChanged = 1; } } } catch (ParseException e) { e.printStackTrace(); System.out.println("Failed to get vk: " + e.getMessage()); // System.exit(-1); } catch (SkypeException ex) { ex.printStackTrace(); System.out.println("Failed to send message: " + ex.getMessage()); } if (bChanged == 1) { save_file(); } try { Thread.sleep(1000 * 60 * twitter_timeout); } catch (InterruptedException ex) { ex.printStackTrace(); System.out.println("Failed to sleep: " + ex.getMessage()); } } }
From source file:net.lacolaco.smileessence.twitter.util.TwitterUtils.java
License:Open Source License
/** * Replace urls by entities/*from w w w.j a va2 s .c o m*/ * * @param text raw text * @param entities url entities * @param expand if true, use expanded url * @return replaced text */ public static String replaceURLEntities(String text, URLEntity[] entities, boolean expand) { if (TextUtils.isEmpty(text)) { return ""; } else if (entities == null) { return text; } if (entities.length == 0) { return text; } for (URLEntity entity : entities) { text = text.replace(entity.getURL(), expand ? entity.getExpandedURL() : entity.getDisplayURL()); } return text; }
From source file:net.nokok.twitduke.core.view.tweetcell.TweetPanelFactoryImpl.java
License:Open Source License
/** * ?????//from w ww . j a v a 2 s. c o m * * @return ? */ @Override public Component createTweetTextArea() { String text = activeStatus.getText(); for (URLEntity entity : status.getURLEntities()) { text = text.replaceAll(entity.getURL(), entity.getDisplayURL()); } for (MediaEntity entity : status.getMediaEntities()) { text = text.replace(entity.getURL(), entity.getDisplayURL()); } JTextArea textArea = TWTextArea.newNotEditableTextArea(text); return textArea; }
From source file:nz.net.speakman.android.dreamintweets.twitterstream.TwitterStreamAdapter.java
License:Apache License
private Spanned getTweetText(Status tweet) { String text = tweet.getText(); for (URLEntity urlEntity : tweet.getURLEntities()) { text = text.replace(urlEntity.getURL(), getClickableUrl(urlEntity)); }/*from w w w. j ava2 s . co m*/ for (MediaEntity mediaEntity : tweet.getMediaEntities()) { // TODO Optionally load images into stream text = text.replace(mediaEntity.getURL(), getClickableMedia(mediaEntity)); } // for (HashtagEntity hashtagEntity : tweet.getHashtagEntities()) { // // TODO Make clickable // } return Html.fromHtml(text); }
From source file:nz.net.speakman.android.dreamintweets.twitterstream.TwitterStreamAdapter.java
License:Apache License
private String getClickableUrl(URLEntity entity) { return getClickableUrl(entity.getURL(), entity.getDisplayURL()); }
From source file:org.tweetalib.android.model.TwitterMediaEntity.java
License:Apache License
public static TwitterMediaEntity createMediaEntity(Status status) { MediaEntity[] mediaEntities;//from w w w. j a v a 2 s . c o m URLEntity[] urlEntities; if (status.isRetweet()) { mediaEntities = status.getRetweetedStatus().getMediaEntities(); urlEntities = status.getRetweetedStatus().getURLEntities(); } else { mediaEntities = status.getMediaEntities(); urlEntities = status.getURLEntities(); } if (mediaEntities != null && mediaEntities.length > 0) { return new TwitterMediaEntity(mediaEntities[0]); } else if (urlEntities != null) { for (URLEntity urlEntity : urlEntities) { // This shouldn't be necessary, but is String expandedUrl = urlEntity.getExpandedURL(); if (expandedUrl == null) { continue; } TwitterMediaEntity entity = getTwitterMediaEntityFromUrl(urlEntity.getURL(), urlEntity.getExpandedURL()); if (entity != null) { return entity; } } } return null; }
From source file:org.tweetalib.android.model.TwitterMediaEntity.java
License:Apache License
public static TwitterMediaEntity createMediaEntity(DirectMessage status) { MediaEntity[] mediaEntities;//from ww w . j a va2 s. co m URLEntity[] urlEntities; mediaEntities = status.getMediaEntities(); urlEntities = status.getURLEntities(); if (mediaEntities != null && mediaEntities.length > 0) { return new TwitterMediaEntity(mediaEntities[0]); } else if (urlEntities != null) { for (URLEntity urlEntity : urlEntities) { // This shouldn't be necessary, but is String expandedUrl = urlEntity.getExpandedURL(); if (expandedUrl == null) { continue; } TwitterMediaEntity entity = getTwitterMediaEntityFromUrl(urlEntity.getURL(), urlEntity.getExpandedURL()); if (entity != null) { return entity; } } } return null; }
From source file:org.xmlsh.twitter.util.TwitterWriter.java
License:BSD License
private void write(URLEntity u) throws XMLStreamException { attribute("display-url", u.getDisplayURL()); attribute("end", u.getEnd()); attribute("expanded-url", u.getExpandedURL().toString()); attribute("start", u.getStart()); attribute("url", u.getURL().toString()); }