Comments (2)
Hey, sorry, I missed this issue before.
Unfortunately, I won't be opening the backend source code because it is around ~50 lines of code that consists of a couple of functions that contain security tokens and stuff like that, so there is no value in that. However, if you are looking for parsers, I have already open-sourced them:
- GitHub Trending: karakanb/gh-trending-parser
- HackerNews: karakanb/hn-parser
You can install them with NPM and expose them via a simple HTTP server. In the end, assuming you have a method to run HTTP GET
requests, you can deploy your API with literally 3 lines of code: get the HTML, pass it to the parser, return the response.
In fact, I tried to gather the pieces to a single file and remove the details, and below is what the API looks like, as you can see the majority of the code is boilerplate, and the core API handler is a single method call, and it is not even the best way to write it probably. I haven't tested the below, sharing just to give you all an idea.
const https = require('https');
const ghParser = require('gh-trending-parser');
function httpsGet(url, successCallback, errorCallback) {
var req = https.get(url, function (res) {
var output = '';
res.setEncoding('utf8');
res.on('data', function (chunk) {
output += chunk;
});
res.on('end', () => {
successCallback(output);
});
});
req.on('error', (err) => {
errorCallback(err);
});
}
function response(statusCode, data) {
return {
statusCode,
headers: {
"Access-Control-Allow-Origin": "*"
},
body: JSON.stringify({
success: statusCode === 200,
data,
}),
}
}
module.exports.github = (event, context, callback) => {
httpsGet(
'https://github.com/trending',
output => callback(null, response(200, ghParser.parse(output))),
err => callback(null, response(500, err.message))
);
};
from devo.
What's the verdict? :)
from devo.
Related Issues (20)
- Product Hunt feed does not refresh. HOT 9
- 404 error on ProductHunt tab HOT 1
- Introduce GitHub CI for building the package to upload the stores
- Add support for Lobsters on burakkarakan.com/devo/ HOT 1
- Remove productivity tag from Github repo HOT 1
- Wrong height when loading HOT 1
- API seems to be erroring, no content will load HOT 2
- Always resets to light mode HOT 3
- Github Trending, Product Hunt and Hacker News have problems HOT 1
- Add support for filtering based on languages and time range. HOT 6
- Lobste.rs: doesn't link to comment threads
- Grid views not working HOT 4
- DEV community shows old feed HOT 1
- Options button does not work on chrome new tab extension HOT 3
- Follow system theme feature HOT 2
- Extension blocked by windows security HOT 4
- Website/extension looks broken. HOT 1
- GitHub Trending tab to disappear HOT 1
- Hacker News wont appear HOT 2
- Demo is not working HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from devo.