Skip to content

Remove dependency on rss2json api #6

Description

@Wowfunhappy

This app currently relies on the rss2json api for xml parsing. While it's an excellent service—and I'm grateful to its developer, Molayli, for providing it—I don't like depending on an external API. Who can say how long it will be available?

Below is an alternate version of the getArticles() function I wrote earlier in development, which doesn't use an API. It largely worked, but couldn't handle a lot of edge cases, and had issues with performance and text encoding.

Could it be made more robust? If even just the text encoding issue could be resolved, that alone would be a great start. For an example of the text encoding problem, try loading a headline from the New York Times's RSS feed and watch what happens to most non-ASCII characters, such as .

(Note: This function was written a long time ago, and so some function definitions likely need to be updated to work with the latest version of the code. This should be trivial, but if not, let me know.)

	function getArticles() {
		loadingCard = new UI.Card(blackStatusBar);
		loadingCard.title(" ");
		loadingCard.subtitle(" ");
		loadingCard.body("        Loading...");
		loadingCard.show();
		articleList = [];
	
		xhr = new XMLHttpRequest();
		// xhr.responseType = "document"
		// xhr.overrideMimeType("text/html; charset=ISO-8859-1");
		// xhr.setRequestHeader("Accept-Charset", "ISO-8859-1");
		xhr.open('GET', currFeed.url);
		// xhr.overrideMimeType('text/xml; charset=iso-8859-1');
		xhr.onload = function() {
	
			articleList = [];
	
			items = xhr.response.match(/<item>([\s\S]*?)<\/item>|<entry>([\s\S]*?)<\/entry>/g);
			for (itemNum = 0; itemNum < items.length; itemNum++) {
				article = {};
	
				title = items[itemNum].match(/<title>([\s\S]*?)<\/title>/);
				if (title) {
			    	article.title = formatText(title[1]);
			  	}
	
				author = items[itemNum].match(/(<author>|<dc:creator>)([\s\S]*?)(<\/author>|<\/dc:creator>)/);
				if (author) {
					article.author = formatText(author[2]);
				}
	
				content = items[itemNum].match(/<content.*?>([\s\S]*?)<\/content.*?>/);
				if (content) {
					article.pages = makePages(content[1]);
				}
				else {
					article.pages = makePages(items[itemNum].match(/<description.*?>([\s\S]*?)<\/description.*?>/)[1]);
				}
	
			 	articleList.push(article);
			 	if (articleList.length === items.length) {
					loadingCard.hide();
					selectArticle(articleList);
				}
			}
		};
		xhr.send();
	} 

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions