use of org.magic.api.beans.MagicNewsContent in project MtgDesktopCompanion by nicho92.
the class TwitterNewsProvider method listNews.
@Override
public List<MagicNewsContent> listNews(MagicNews n) throws IOException {
Twitter twitter = tf.getInstance();
Query query = new Query(n.getName());
query.setCount(Integer.parseInt(getString("MAX_RESULT")));
List<MagicNewsContent> ret = new ArrayList<>();
QueryResult result;
try {
result = twitter.search(query);
for (Status status : result.getTweets()) {
MagicNewsContent content = new MagicNewsContent();
content.setAuthor(status.getUser().getScreenName());
content.setDate(status.getCreatedAt());
content.setContent(status.getText());
content.setLink(new URL("https://twitter.com/" + status.getUser().getScreenName() + "/status/" + status.getId()));
content.setTitle(status.getText());
ret.add(content);
}
} catch (TwitterException e) {
throw new IOException(e);
}
return ret;
}
use of org.magic.api.beans.MagicNewsContent in project MtgDesktopCompanion by nicho92.
the class RSSNewsProvider method listNews.
@Override
public List<MagicNewsContent> listNews(MagicNews rssBean) throws IOException {
InputStream is = null;
SyndFeed feed;
List<MagicNewsContent> ret = new ArrayList<>();
try {
HttpURLConnection openConnection = (HttpURLConnection) new URL(rssBean.getUrl()).openConnection();
logger.debug("reading " + rssBean.getUrl());
openConnection.setRequestProperty("User-Agent", MTGConstants.USER_AGENT);
openConnection.setInstanceFollowRedirects(true);
is = openConnection.getInputStream();
InputSource source = new InputSource(is);
feed = input.build(source);
String baseURI = feed.getLink();
for (SyndEntry s : feed.getEntries()) {
MagicNewsContent content = new MagicNewsContent();
content.setTitle(s.getTitle());
content.setAuthor(s.getAuthor());
content.setDate(s.getPublishedDate());
URL link;
if (!s.getLink().startsWith(baseURI))
link = new URL(baseURI + s.getLink());
else
link = new URL(s.getLink());
content.setLink(link);
ret.add(content);
}
return ret;
} catch (IllegalArgumentException | FeedException e) {
throw new IOException(e);
} finally {
if (is != null)
is.close();
}
}
Aggregations