Skip to content
This repository has been archived by the owner on Mar 17, 2019. It is now read-only.

source for parser #10

Open
synapse25 opened this issue Dec 8, 2016 · 3 comments
Open

source for parser #10

synapse25 opened this issue Dec 8, 2016 · 3 comments
Assignees
Labels

Comments

@synapse25
Copy link

Hi ! Where is the source for parser disclosed ? I can't find it, thanks.

@jamestomasino
Copy link
Owner

I've written it on Heroku, but it has my Mercury API hardcoded currently, so I don't have the source mirroring up here at the moment. I'll get that cleaned up and copied here for reference, but until then:

var http = require("http");
var url = require('url') ;
var Curl = require( 'node-libcurl' ).Curl;
var htmlToText = require('html-to-text');

function onRequest(request, response) {
	response.writeHead(200, {"Content-Type": "text/plain"});
	var queryObject = url.parse(request.url, true).query;
	if (typeof queryObject.url == "string") {
		var processURL = queryObject.url;
		var curl = new Curl();
		curl.setOpt( "URL", 'https://mercury.postlight.com/parser?url=' + processURL); //https://trackchanges.postlight.com/building-awesome-cms-f034344d8ed' );
		curl.setOpt( Curl.option.HTTPHEADER, ['x-api-key: xxxxxxx'] );

		curl.on( 'end', function( statusCode, body, headers ) {
			var r = JSON.parse(body);
			var o = htmlToText.fromString(r.content, { ignoreHref: true, ignoreImage: true, uppercaseHeadings: false, wordwrap: false });
			response.write(o);
			response.end();
			this.close();
		});

		curl.on( 'error', function() {
			this.close();
			response.write("There was a problem processing your request. Please select the text you want to read, right-click, and Read the selected text.");
			response.end();
		});

		curl.perform();
	} else {
		response.write("There was a problem processing your request. Please select the text you want to read, right-click, and Read the selected text.");
		response.end();
	}
}
var port = process.env.PORT || 5000;
http.createServer(onRequest).listen(port);

@jamestomasino jamestomasino self-assigned this Dec 9, 2016
@MicroDroid
Copy link

Migrating to a local parser addresses this issue. This should be closed

@jamestomasino
Copy link
Owner

Do you have a full-featured local parser that doesn't add significant bloat to the project? If so, please PR and I'll drop the Mercury/Heroku solution and keep this fully local and close this issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants