-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added eslint and --fixed the javascript files
- Loading branch information
1 parent
bb4e38b
commit 050d4ac
Showing
9 changed files
with
847 additions
and
320 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": ["plugin:prettier/recommended"], | ||
"parserOptions": { | ||
"ecmaVersion": 7 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,32 @@ | ||
require('dotenv').config(); | ||
require("dotenv").config(); | ||
|
||
let statusCode = 200; | ||
const headers = { | ||
"Access-Control-Allow-Origin" : "*", | ||
"Access-Control-Allow-Headers": "Content-Type" | ||
"Access-Control-Allow-Origin": "*", | ||
"Access-Control-Allow-Headers": "Content-Type" | ||
}; | ||
|
||
const https = require("https"); | ||
const githubId = process.env.GITHUB_ID; | ||
const githubSecret = process.env.GITHUB_SECRET; | ||
|
||
exports.handler = function (event, context, callback) { | ||
async function fetchWeekContributions(username, format = '') { | ||
https | ||
.get( | ||
'https://robertcooper-github-contributions-api.now.sh/v1/robertcoopercode', | ||
(res) => { | ||
res.headers['content-type']; | ||
res.setEncoding('utf8'); | ||
let rawData = ""; | ||
res.on("data", chunk => { | ||
rawData += chunk | ||
}); | ||
res.on("end", () => { | ||
callback(null, {statusCode, headers, body: rawData}) | ||
}) | ||
}, | ||
) | ||
exports.handler = function(event, context, callback) { | ||
function fetchWeekContributions(username, format = "") { | ||
https.get( | ||
"https://robertcooper-github-contributions-api.now.sh/v1/robertcoopercode", | ||
res => { | ||
res.headers["content-type"]; | ||
res.setEncoding("utf8"); | ||
let rawData = ""; | ||
res.on("data", chunk => { | ||
rawData += chunk; | ||
}); | ||
res.on("end", () => { | ||
callback(null, { statusCode, headers, body: rawData }); | ||
}); | ||
} | ||
|
||
fetchWeekContributions('robertcoopercode') | ||
}; | ||
); | ||
} | ||
|
||
fetchWeekContributions("robertcoopercode"); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,44 @@ | ||
require('dotenv').config(); | ||
require("dotenv").config(); | ||
|
||
const statusCode = 200; | ||
const headers = { | ||
"Access-Control-Allow-Origin" : "*", | ||
"Access-Control-Allow-Headers": "Content-Type" | ||
"Access-Control-Allow-Origin": "*", | ||
"Access-Control-Allow-Headers": "Content-Type" | ||
}; | ||
|
||
const https = require('https'); | ||
const https = require("https"); | ||
const goodreadsKey = process.env.GOODREADS_KEY; | ||
|
||
exports.handler = function (event, context, callback) { | ||
https | ||
.get( | ||
{ | ||
host: "www.goodreads.com", | ||
path: `/review/list/62347534.xml?key=${goodreadsKey}&v=2&shelf=currently-reading` | ||
}, | ||
res => { | ||
let rawData = ""; | ||
res.on("data", chunk => { | ||
rawData += chunk | ||
}); | ||
res.on("end", () => { | ||
try { | ||
// Get all the titles of the books i'm currently reading and add them to an array | ||
const parseXml = require('xml2js').parseString; | ||
let currentlyReadingBooks = []; | ||
parseXml(rawData, function (err, result) { | ||
result.GoodreadsResponse["reviews"][0].review.forEach( (book) => { | ||
currentlyReadingBooks.push(book.book[0].title[0]) | ||
}); | ||
}); | ||
callback(null, {statusCode, headers, body: JSON.stringify(currentlyReadingBooks)}) | ||
} catch (error) { | ||
return; | ||
} | ||
}) | ||
} | ||
) | ||
}; | ||
exports.handler = function(event, context, callback) { | ||
https.get( | ||
{ | ||
host: "www.goodreads.com", | ||
path: `/review/list/62347534.xml?key=${goodreadsKey}&v=2&shelf=currently-reading` | ||
}, | ||
res => { | ||
let rawData = ""; | ||
res.on("data", chunk => { | ||
rawData += chunk; | ||
}); | ||
res.on("end", () => { | ||
try { | ||
// Get all the titles of the books i'm currently reading and add them to an array | ||
const parseXml = require("xml2js").parseString; | ||
let currentlyReadingBooks = []; | ||
parseXml(rawData, function(err, result) { | ||
result.GoodreadsResponse["reviews"][0].review.forEach(book => { | ||
currentlyReadingBooks.push(book.book[0].title[0]); | ||
}); | ||
}); | ||
callback(null, { | ||
statusCode, | ||
headers, | ||
body: JSON.stringify(currentlyReadingBooks) | ||
}); | ||
} catch (error) { | ||
return; | ||
} | ||
}); | ||
} | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,63 @@ | ||
require('dotenv').config(); | ||
require("dotenv").config(); | ||
|
||
const statusCode = 200; | ||
const headers = { | ||
"Access-Control-Allow-Origin" : "*", | ||
"Access-Control-Allow-Headers": "Content-Type" | ||
"Access-Control-Allow-Origin": "*", | ||
"Access-Control-Allow-Headers": "Content-Type" | ||
}; | ||
|
||
const https = require('https'); | ||
const https = require("https"); | ||
|
||
exports.handler = function (event, context, callback) { | ||
let mediumData = {}; | ||
https | ||
.get( | ||
{ | ||
host: "medium.com", | ||
path: "/@robertcooper_rc/latest", | ||
headers: { | ||
Accept: "application/json", | ||
}, | ||
}, | ||
res => { | ||
res.setEncoding("utf8"); | ||
let rawData = ""; | ||
res.on("data", chunk => { | ||
rawData += chunk | ||
}); | ||
res.on("end", () => { | ||
rawData = rawData.replace("])}while(1);</x>", ""); | ||
try { | ||
let parsedData = JSON.parse(rawData); | ||
let posts = parsedData["payload"]["references"]["Post"]; | ||
for (let i = 1; i <= 6; i++) { | ||
let post = posts[Object.keys(posts)[i - 1]]; | ||
mediumData["readingTime" + i] = Math.ceil(post["virtuals"]["readingTime"]); | ||
let tags = []; | ||
post["virtuals"]["tags"].forEach( (tag) => { | ||
tags.push(tag); | ||
}); | ||
mediumData["tags" + i] = tags; | ||
mediumData["title" + i] = post["title"]; | ||
mediumData["excerpt" + i] = | ||
post["content"]["subtitle"]; | ||
mediumData["url" + i] = | ||
"https://medium.com/@robertcooper_18384/" + | ||
post["uniqueSlug"]; | ||
mediumData["claps" + i] = | ||
post["virtuals"]["totalClapCount"] | ||
} | ||
} catch (error) { | ||
return | ||
} | ||
callback(null, {statusCode, headers, body: JSON.stringify(mediumData)}) | ||
}) | ||
}, | ||
) | ||
.on("error", (error) => { | ||
return | ||
}) | ||
}; | ||
exports.handler = function(event, context, callback) { | ||
let mediumData = {}; | ||
https | ||
.get( | ||
{ | ||
host: "medium.com", | ||
path: "/@robertcooper_rc/latest", | ||
headers: { | ||
Accept: "application/json" | ||
} | ||
}, | ||
res => { | ||
res.setEncoding("utf8"); | ||
let rawData = ""; | ||
res.on("data", chunk => { | ||
rawData += chunk; | ||
}); | ||
res.on("end", () => { | ||
rawData = rawData.replace("])}while(1);</x>", ""); | ||
try { | ||
let parsedData = JSON.parse(rawData); | ||
let posts = parsedData["payload"]["references"]["Post"]; | ||
for (let i = 1; i <= 6; i++) { | ||
let post = posts[Object.keys(posts)[i - 1]]; | ||
mediumData["readingTime" + i] = Math.ceil( | ||
post["virtuals"]["readingTime"] | ||
); | ||
let tags = []; | ||
post["virtuals"]["tags"].forEach(tag => { | ||
tags.push(tag); | ||
}); | ||
mediumData["tags" + i] = tags; | ||
mediumData["title" + i] = post["title"]; | ||
mediumData["excerpt" + i] = post["content"]["subtitle"]; | ||
mediumData["url" + i] = | ||
"https://medium.com/@robertcooper_18384/" + post["uniqueSlug"]; | ||
mediumData["claps" + i] = post["virtuals"]["totalClapCount"]; | ||
} | ||
} catch (error) { | ||
return; | ||
} | ||
callback(null, { | ||
statusCode, | ||
headers, | ||
body: JSON.stringify(mediumData) | ||
}); | ||
}); | ||
} | ||
) | ||
.on("error", error => { | ||
return; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,64 @@ | ||
require('dotenv').config(); | ||
require("dotenv").config(); | ||
|
||
const statusCode = 200; | ||
const headers = { | ||
"Access-Control-Allow-Origin" : "*", | ||
"Access-Control-Allow-Headers": "Content-Type" | ||
"Access-Control-Allow-Origin": "*", | ||
"Access-Control-Allow-Headers": "Content-Type" | ||
}; | ||
|
||
const https = require('https'); | ||
const https = require("https"); | ||
const stravaToken = process.env.STRAVA_TOKEN; | ||
|
||
exports.handler = function (event, context, callback) { | ||
let stravaData = {}; | ||
https.get("https://www.strava.com/api/v3/athlete/activities?access_token=" + stravaToken, res => { | ||
exports.handler = function(event, context, callback) { | ||
let stravaData = {}; | ||
https | ||
.get( | ||
"https://www.strava.com/api/v3/athlete/activities?access_token=" + | ||
stravaToken, | ||
res => { | ||
res.setEncoding("utf8"); | ||
let rawData = ""; | ||
res.on("data", chunk => { | ||
rawData += chunk; | ||
rawData += chunk; | ||
}); | ||
res.on("end", () => { | ||
try { | ||
let parsedData = JSON.parse(rawData); | ||
for (let i = 0; i < parsedData.length; i++) { | ||
if (parsedData[i]["type"] === "Run") { | ||
let duration = new Date(null); | ||
duration.setSeconds(parsedData[i]["moving_time"]); | ||
duration = duration.toISOString().substr(11, 8); | ||
// Remove leading zeros from run duration | ||
if (duration.startsWith("00:")) { | ||
duration = duration.slice(3); | ||
} else if (duration.startsWith("0")) { | ||
duration = duration.slice(1); | ||
} | ||
let distance_meters = parsedData[i]["distance"]; | ||
let distance_km = distance_meters / 1000; | ||
distance_km = distance_km.toFixed(2); | ||
let date_string = parsedData[i]["start_date_local"]; | ||
let date = new Date(date_string); | ||
let dateStr = date.toLocaleDateString(); | ||
stravaData.distance = distance_km; | ||
stravaData.date = dateStr; | ||
stravaData.duration = duration; | ||
break; | ||
} | ||
try { | ||
let parsedData = JSON.parse(rawData); | ||
for (let i = 0; i < parsedData.length; i++) { | ||
if (parsedData[i]["type"] === "Run") { | ||
let duration = new Date(null); | ||
duration.setSeconds(parsedData[i]["moving_time"]); | ||
duration = duration.toISOString().substr(11, 8); | ||
// Remove leading zeros from run duration | ||
if (duration.startsWith("00:")) { | ||
duration = duration.slice(3); | ||
} else if (duration.startsWith("0")) { | ||
duration = duration.slice(1); | ||
} | ||
callback(null, { statusCode, headers, body: JSON.stringify(stravaData) }); | ||
} catch (error) { | ||
return; | ||
let distance_meters = parsedData[i]["distance"]; | ||
let distance_km = distance_meters / 1000; | ||
distance_km = distance_km.toFixed(2); | ||
let date_string = parsedData[i]["start_date_local"]; | ||
let date = new Date(date_string); | ||
let dateStr = date.toLocaleDateString(); | ||
stravaData.distance = distance_km; | ||
stravaData.date = dateStr; | ||
stravaData.duration = duration; | ||
break; | ||
} | ||
} | ||
callback(null, { | ||
statusCode, | ||
headers, | ||
body: JSON.stringify(stravaData) | ||
}); | ||
} catch (error) { | ||
return; | ||
} | ||
}); | ||
}).on("error", (error) => { | ||
return; | ||
} | ||
) | ||
.on("error", error => { | ||
return; | ||
}); | ||
}; | ||
}; |
Oops, something went wrong.