Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency on rss2json api #6

Open
Wowfunhappy opened this issue Sep 18, 2019 · 2 comments
Open

Remove dependency on rss2json api #6

Wowfunhappy opened this issue Sep 18, 2019 · 2 comments
Labels
help wanted Extra attention is needed

Comments

@Wowfunhappy
Copy link
Owner

Wowfunhappy commented Sep 18, 2019

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();
	} 
@Wowfunhappy Wowfunhappy added the help wanted Extra attention is needed label Sep 18, 2019
@shrmnk
Copy link

shrmnk commented Oct 21, 2019

Have you considered using libraries like https://github.com/Leonidas-from-XIV/node-xml2js

@Wowfunhappy
Copy link
Owner Author

Wowfunhappy commented Oct 21, 2019

I believe I explored using https://github.com/isaacs/sax-js/ directly at one point (very eager to stay out of the npm dependency quagmire), but now I can't remember why I gave up on it! Something to look at!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants