aboutsummaryrefslogtreecommitdiff
path: root/Functions
diff options
context:
space:
mode:
authorJoel Kronqvist <work.joelkronqvist@pm.me>2022-03-11 20:41:42 +0200
committerJoel Kronqvist <work.joelkronqvist@pm.me>2022-03-11 20:41:42 +0200
commit5ac7049a9d30733165cc212dee308163c2a14644 (patch)
tree92dbb85e2e3dc408d06b8cea6fbf32503482bbbb /Functions
parent01f3f5f2ab89432a253c24f76227b8f6855d8446 (diff)
downloadLYLLRuoka-5ac7049a9d30733165cc212dee308163c2a14644.tar.gz
LYLLRuoka-5ac7049a9d30733165cc212dee308163c2a14644.zip
Food scraping updation
Diffstat (limited to 'Functions')
-rw-r--r--Functions/dateFuncs.js21
-rw-r--r--Functions/open.js23
2 files changed, 42 insertions, 2 deletions
diff --git a/Functions/dateFuncs.js b/Functions/dateFuncs.js
index 10c4250..9b1237a 100644
--- a/Functions/dateFuncs.js
+++ b/Functions/dateFuncs.js
@@ -17,7 +17,26 @@ function approxDate(d)
return new Date(`${d.getFullYear()}-${(d.getMonth() + 1).toString().padStart(2, "0")}-${d.getDate().toString().padStart(2, "0")}`);
}
+function weekdayToNumber(s)
+{
+ const weekdays = [
+ /ma.*/i,
+ /ti.*/i,
+ /ke.*/i,
+ /to.*/i,
+ /pe.*/i,
+ /la.*/i,
+ /su.*/i
+ ];
+ for(let day = 0; day < weekdays.length; day++)
+ {
+ if (s.match(weekdays[day]))
+ return day;
+ }
+}
+
module.exports = {
fromString: stringToDate,
- between: isBetweenDates
+ between: isBetweenDates,
+ weekdayToNumber: weekdayToNumber
} \ No newline at end of file
diff --git a/Functions/open.js b/Functions/open.js
index f04201b..f532721 100644
--- a/Functions/open.js
+++ b/Functions/open.js
@@ -1,4 +1,5 @@
const fs = require("fs");
+const https = require("https");
function openFile(path)
{
@@ -13,4 +14,24 @@ function openFile(path)
});
}
-exports.file = openFile;
+async function urlOpen(path)
+{
+ return new Promise((resolve, reject) =>
+ {
+ let req = https.get(path, res =>
+ {
+ res.on("data", resolve);
+ });
+ });
+ req.on("error", e =>
+ {
+ console.error(e);
+ });
+ req.end();
+}
+
+
+module.exports = {
+ file: openFile,
+ url: urlOpen
+}; \ No newline at end of file