HeadlinePuller can import all news articles for Fortune 50 within a date range from Yahoo Finance historical data, inserting the headline text into the headlines table of database cs6601p3 on woodyfolsom.net:3306.
Limited to 25 headline per day (with many reptitions) per Yahoo Finance REST functionality.
This commit is contained in:
@@ -7,5 +7,6 @@ import net.woodyfolsom.cs6601.p3.domain.Headline;
|
||||
|
||||
public interface HeadlineService {
|
||||
int insertHeadline(Headline headline);
|
||||
int[] insertHeadlines(List<Headline> headline);
|
||||
List<Headline> getHeadlines(String stock, Date date);
|
||||
}
|
||||
@@ -23,6 +23,11 @@ public class MySQLHeadlineServiceImpl implements HeadlineService {
|
||||
return headlineDao.insert(headline);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] insertHeadlines(List<Headline> headlines) {
|
||||
return headlineDao.insertBatch(headlines);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Headline> getHeadlines(String stock, Date date) {
|
||||
return headlineDao.select(stock, date);
|
||||
|
||||
@@ -31,13 +31,18 @@ public class YahooHeadlineServiceImpl implements HeadlineService {
|
||||
private static final String STORY_DATE_FIELD = "STORY_DATE";
|
||||
private static final String STOCK_SYMBOL_FIELD = "STOCK_SYMBOL";
|
||||
|
||||
private static final String QUERY_URL = "http://query.yahooapis.com/v1/public/yql?q=select%20content%20from%20html%20where%20url%3D%22http%3A%2F%2Ffinance.yahoo.com%2Fq%2Fh%3Fs%3DSTOCK_SYMBOL%26t%3DSTORY_DATE%22%20and%20xpath%3D'%2F%2Fdiv%5B%40class%3D%22mod%20yfi_quote_headline%20withsky%22%5D%2Ful%2Fli%2Fa'&diagnostics=true";
|
||||
private static final String QUERY_URL = "http://query.yahooapis.com/v1/public/yql?q=select%20content%20from%20html%20where%20url%3D%22http%3A%2F%2Ffinance.yahoo.com%2Fq%2Fh%3Fs%3DSTOCK_SYMBOL%26t%3DSTORY_DATE%22%20and%20xpath%3D'%2F%2Fdiv%5B%40class%3D%22mod%20yfi_quote_headline%20withsky%22%5D%2Ful%2Fli%2Fa'";
|
||||
|
||||
@Override
|
||||
public int insertHeadline(Headline headline) {
|
||||
throw new UnsupportedOperationException("This implementation does not support inserting headlines.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] insertHeadlines(List<Headline> headline) {
|
||||
throw new UnsupportedOperationException("This implementation does not support inserting headlines.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Headline> getHeadlines(String stock, Date date) {
|
||||
List<Headline> headlineList = new ArrayList<Headline>();
|
||||
@@ -57,7 +62,6 @@ public class YahooHeadlineServiceImpl implements HeadlineService {
|
||||
|
||||
while ((line = buf.readLine()) != null) {
|
||||
sb.append(line);
|
||||
//System.out.println(line);
|
||||
}
|
||||
|
||||
buf.close();
|
||||
@@ -67,7 +71,6 @@ public class YahooHeadlineServiceImpl implements HeadlineService {
|
||||
Pattern pattern = Pattern.compile("<a>.*?</a>");
|
||||
Matcher matcher = pattern.matcher(xmlResults);
|
||||
while (matcher.find()) {
|
||||
System.out.println();
|
||||
String anchorValue = xmlResults.substring(matcher.start()+3,matcher.end()-4);
|
||||
headlineList.add(new Headline(stock,anchorValue,date,1));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user