Inital commit

This commit is contained in:
2022-03-06 18:36:36 +01:00
commit bedd69436b
175 changed files with 9965 additions and 0 deletions

76
proto/filterTest.js Normal file
View File

@ -0,0 +1,76 @@
const sensemap = require("../apiHandler/opensensemap/main");
const ttnantennas = require("../apiHandler/ttnantennas/main");
const autobahn = require("../apiHandler/autobahn/main");
const libs = require("../libs/metaHandler.lib.js");
const mods = [sensemap, ttnantennas, autobahn]; // Provided by main.ts in a real env.
const jsonData = {
filters: [
["tag", "webcam"],
["country", "DEU"],
],
conjunction: "AND",
}; // Provided by request in a real env
const uMods = mods.filter(function (elm) {
// Loops through all elements in a list and lets you decide if weather to keep 'em or not
let amount = 0;
for (fId in jsonData.filters) {
// Do this is each provided filter
const fi = jsonData.filters[fId]; // Gets the current filters name
switch (fi[0]) {
case "tag":
if (jsonData.conjunction == "OR") {
if (libs.returnTags(elm).includes(fi[1])) {
return elm;
} else {
break;
}
} else {
if (libs.returnTags(elm).includes(fi[1])) {
amount++;
}
break;
}
case "country":
if (jsonData.conjunction == "OR") {
if (libs.returnCountries(elm).includes(fi[1])) {
return elm;
} else {
break;
}
} else {
if (libs.returnCountries(elm).includes(fi[1])) {
amount++;
}
break;
}
}
}
if (jsonData.conjunction == "AND") {
if (amount == jsonData.filters.length) {
return elm;
}
}
});
console.log(uMods);
/**
* This things is sorting all given modules by a JSON array.
* You can supply the ˋfilterˋ array with a list of filters
* They are made up of ["metaData", "metaValue"]
* Another argument is ˋconjunctionˋ it can be either AND or OR
* OR means that any of the given filters should apply
* AND means that all filter HAVE to apply
*
* Current state
* This things can already handle OR requests, AND requests
* are not supported yet. I also use the /libs/metaHandler lib,
* at least I finnaly found a usecase for that waste of space.
*
* This is a small prototype which will be added into /routes/api.route.js
* at some point. But what I was doing before was almost production testing.
* Not good. I will need to test this further and throw some edge cases at it.
*/

58
proto/scrapeDemo.js Normal file
View File

@ -0,0 +1,58 @@
// Trying to scrape https://www.opentopia.com/hiddencam.php?p=n for data
// THIS IS A PROTOTYPE - DO NOT USE
// [Project-Name-Here] 2021
// Current state: Able to get cams from page, get location, unable to get live feed
process.exit(1)
const fs = require("fs");
const request = require("request");
function requestCamList(n){
request("http://www.opentopia.com/hiddencam.php?showmode=standard&country=%2A&seewhat=highlyrated&p="+n, { json: false }, (err, res2, body) => {
if (err) {
throw err;
}
let part = body.split("<body>")[1]
// part = part.split('<div style="clear:both">')[0]
//part = part.split('<ul class="camgrid camgrid3">')[1]
part = part.split("/webcam/")
part.shift()
for(h in part){
part[h] = part[h].replace("\t", "")
part[h] = part[h].split('target="_self">')[0].replace('"', "").split(">")[0]
console.log(part[h])
}
return(part)
});
}
function getMoreInfo(id){
const baseurl = "http://www.opentopia.com/webcam/"
const url = baseurl + id + "?viewmode=livevideo"
request(url, { json: false }, (err, res2, body) => {
if (err) {
throw err;
}
let result = {name: "", url:"", location:{lat:0,lng:0}}
let part = body.split("<body>")[1]
camPart = part.split("<div class=\"big\">")[1]
camPart = camPart.split('<img src="')[1]
camPart = camPart.split('"')[0]
result.url = camPart
part = part.split("Facility")[1]
part = part.split("Rating")[0]
part = part.split('<label class="right">')[1]
result.name = part.split("</label></div>")[0]
result.name = result.name.replaceAll("\t", "").replaceAll(" ", "")
part = part.split("<label class=\"right geo\">")[1]
part = part.split('<span class="latitude">')[1]
result.location.lat = parseFloat(part.split("</span>")[0])
part = part.split("<span class=\"longitude\">")[1]
result.location.lng = parseFloat(part.split("</span>")[0])
console.log(result)
});
}
console.log(getMoreInfo(6576))