Skip to content
This repository has been archived by the owner on Oct 3, 2020. It is now read-only.

Commit

Permalink
adding commets, fixed bug
Browse files Browse the repository at this point in the history
  • Loading branch information
FultonBrowne committed Sep 28, 2019
1 parent b7741ec commit b4338d6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
17 changes: 14 additions & 3 deletions src/main/java/com/andromeda/araserver/RssMain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,50 @@ import java.net.URL
import java.util.*

object RssMain {
//Exceptions Throne
@Throws(IOException::class, FeedException::class)
//Main Function
fun rssMain1(mode: Int): SyndFeed {
//Feed link text
val feeds = arrayOfNulls<String>(2)
when (mode) {
1 -> {
//World news
feeds[0] = "https://www.cbsnews.com/latest/rss/world"
feeds[1] = "http://feeds.foxnews.com/foxnews/world"
}
2 -> {
// Us news
feeds[0] = "https://www.cbsnews.com/latest/rss/us"
feeds[1] = "http://feeds.foxnews.com/foxnews/national"
}
3 -> {
//Tech news
feeds[0] = "https://www.cnet.com/rss/news/"
feeds[1] = "http://www.foxnews.com/about/rss"
}
4 -> {
//Business news
feeds[0] = "http://feeds.reuters.com/reuters/businessNews"
feeds[1] = "https://www.espn.com/espn/rss/news/rss.xml"
}
else -> {
// general news
feeds[0] = "https://www.cbsnews.com/latest/rss/main/"
feeds[1] = "http://feeds.foxnews.com/foxnews/latest"
}
}
//feeds[0] = "https://www.cbsnews.com/latest/rss/main/";
//feeds[1] = "https://www.espn.com/espn/rss/news/rss.xml";
//Declare Feed
val feed = SyndFeedImpl()
//Set feed type
feed.feedType = "rss_2.0"
//Entries of the feeds
val entries = ArrayList<SyndEntry>()
//Entries after sorting by date
val sortedEntries = ArrayList<SyndEntry>()
feed.entries = entries


// set general feed info
feed.title = "Ara feed"
feed.description = "a hole lot of feeds in one"
feed.author = "Andromeda Software"
Expand Down
34 changes: 24 additions & 10 deletions src/main/java/com/andromeda/araserver/Run.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,25 @@ public class Run extends NanoHTTPD {



//Function to declare port
private Run(int port) throws IOException {
//Get Port
super(port);

System.getenv("PORT");
//Start Server
start(NanoHTTPD.SOCKET_READ_TIMEOUT, false);
System.out.println( System.getenv("PORT") + "\n hi Running! Point your browsers to http://localhost:80/ \n");
}


// Static function, to be run on start.
public static void main(String[] args) {
// If this is in a heroku environment, get the port number
String webPort = System.getenv("PORT");
if(webPort == null || webPort.isEmpty()) {
// If not set to 80
webPort = "80";
}
//Get port value and start server
try {
new Run(Integer.parseInt(webPort));
} catch (IOException ioe) {
Expand All @@ -37,21 +42,27 @@ public static void main(String[] args) {
}

@Override
//If connected to
public NanoHTTPD.Response serve(NanoHTTPD.IHTTPSession session) {
//RSS feed type, if any
int tag;
//URI passed from client
String sessionUri = session.getUri();
SyndFeed main1 = null;
//Feed if any
SyndFeed syndFeed = null;
//Text to be outputted
String main2 = "err";
//Functions related to the search api
//Start API function
if (sessionUri.startsWith("/api")) main2 = new apiStart().apiMain(sessionUri);
//Start the Hello function
else if (sessionUri.startsWith("/hi")) main2 = new Hello().hello();

else if(sessionUri.startsWith("/yelpclient")) main2 = new locdec().main(sessionUri);
else if (sessionUri.startsWith("/search")) main2 = new GetInfo().main(sessionUri);
else if (sessionUri.startsWith("/math")) main2 = new equations().main(sessionUri);
else if (sessionUri.startsWith("/update")) main2 = new Update().update(sessionUri);

else {

// if getting RSS info set tag value this will be used to get the correct feed
switch (sessionUri) {
case "/world":
tag = 1;
Expand All @@ -72,14 +83,16 @@ public NanoHTTPD.Response serve(NanoHTTPD.IHTTPSession session) {
}

try {
main1 = RssMain.INSTANCE.rssMain1(tag);

// get Rss feed from RssMain.kt
syndFeed = RssMain.INSTANCE.rssMain1(tag);
} catch (IOException | FeedException e) {
// if any issues
e.printStackTrace();
}
// turn feed content in to XML text
try {
assert main1 != null;
main2 = new SyndFeedOutput().outputString(main1);
assert syndFeed != null;
main2 = new SyndFeedOutput().outputString(syndFeed);
} catch (FeedException e) {
e.printStackTrace();
}
Expand All @@ -88,6 +101,7 @@ public NanoHTTPD.Response serve(NanoHTTPD.IHTTPSession session) {


System.out.println(sessionUri);
//Output response
return newFixedLengthResponse(main2);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/andromeda/araserver/apiStart.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ private String sqltest(String search){
break;
}
}
if(!(linkval == null)) if (linkval.contains(" "))
linkval = linkval.replace(" ", "");
System.out.println(linkval );
String url = linkval;
Expand Down

0 comments on commit b4338d6

Please sign in to comment.