Many thanks for reading.
I am using (and learning…) meteor to create an array of hashes (of files) contained in a mongodb collection:
Server Side
function builtJSON () {
var cursor = MyFiles.find({uploaded:1}).fetch();
let index = MyFiles.find({uploaded:1}).count();
let result;
var hashes_array = [];
for ( var i = 0 ; i< index ; i++ )
{
hashes_array.push(cursor[i]['hash']);
}
result = JSON.stringify(hashes_array);
return result;
}
The function is called with:
'builtJSON':function() {
return builtJSON();
},
etc...
In client side I am creating a simple route called /files_www/ and calling the builtJSON() function with
FlowRouter.route('/files_www/', {
action: function(params, queryParams) {
Meteor.call("builtJSON",{} , function(err, result) {
if(!err) {
document.write (result);}
else
{console.log (error);
}
})
}});
The code prints correctly the hashed when called with i.e. localhost:3000/files_www/
My problem is that I want to parse these values from Python with the requests package.
I am using:
r = requests.get('http://'+server_name+'/files_www/)
Although I thought I would have the document.write printed values , I have as a result
the meteor long list of scripts inside the html (as you can see in view source).
Is there a way I can get only the document.write values (as I print the correctly in console.log)
Many thanks for any comment or ideas…
Solution: it seems that the only way to accomplish this is to use a REST package (simple:rest in my case).
Then I have declared a publication like:
Meteor.startup(() => {
Meteor.publish('uploadedfiles', function() {
return MyFiles.find({uploaded:1} , {fields: { hash: 1 }});
});
and then this is accessed by the url :
http://localhost:3000/publications/uploadedfiles
which returns a json file, to be parsed somehow…