$.POST not posting Data - show the result in snippet - javascript

The POSTED DATA is EMPTY but why its like this. Pls check!!!
function AData(mid,murl,mdata)
{
$.post( murl, mdata)
.done(function( data ) {
$("#res"+mid).html(data);
});
}
AData('1','http://api.techsoul.in/movies/techsoul-update-movies.php?token=777&fun=addmovie','{ detail:"PHA%2BTW92aWUgRGV0YWlscyBPZiA6IEFycml2YWwgPC9wPjxiciAvPgo8cD4gQSBNb3ZpZSBEaXJlY3RvciBOYW1lIDogRGVuaXMgVmlsbGVuZXV2ZTwvcD48YnIgLz4KPHA%2BIENhc3RpbmcgSW4gTW92aWUgOiBBbXkgQWRhbXMsIEplcmVteSBSZW5uZXIsIEZvcmVzdCBXaGl0YWtlcjwvcD48YnIgLz4KPHA%2BIFJlbGVhc2VkIFllYXIgOiAyMDE2PC9wPjxiciAvPgo8cD4gQ291bnRyeSBGcm9tIDogVVNBPC9wPjxiciAvPgo8cD4gTGFuZ3VhZ2UgVXNlZCA6IEVuZ2xpc2g8L3A%2BPGJyIC8%2BCjxwPiBHZW5yZXMgc2VlbXMgOiBEcmFtYSwgTXlzdGVyeSwgU2NpLUZpIDwvcD4%3D",category:"aG9sbHl3b29kLW1vdmllcy0yMDE2",poster:"aHR0cDovL29ubGluZW1vdmlld2F0Y2hzLnR2L3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDE2LzExL0Fycml2YWwtTW92aWUtUG9zdGVyLmpwZw%3D%3D",rate:"MA%3D%3D",year:"MjAxNg%3D%3D",quality:"TkE%3D",name:"QXJyaXZhbA%3D%3D",genre:"RHJhbWEsIE15c3RlcnksIFNjaS1GaQ%3D%3D",link:"aHR0cDovL29ubGluZW1vdmlld2F0Y2hzLnR2L2Fycml2YWwtMjAxNi1mdWxsLW1vdmllLW9ubGluZS1mcmVlLWhkLw%3D%3D",src:"aHR0cDovLzE2My4xNzIuMjE0LjEwNS95a2dpcGltZWs2MmJpcm1wbmh3Z3J6bHJlMjZkajI1d29veTZ0Y2Y2MzdhM2ZnamRiY3duan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ZWQtdDBpNDZodXplMG5lLmh0bWw%3D",status:"MQ%3D%3D" }');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p id='res1'></p>

Because you passing your parameter mdataas a string, not as an object. Remove the single quotes before and after, format your json correctly as an array and it works:
var details = [
{
detail: "PHA%2BTW92aWUgRGV0YWlscyBPZiA6IEFycml2YWwgPC9wPjxiciAvPgo8cD4gQSBNb3ZpZSBEaXJlY3RvciBOYW1lIDogRGVuaXMgVmlsbGVuZXV2ZTwvcD48YnIgLz4KPHA%2BIENhc3RpbmcgSW4gTW92aWUgOiBBbXkgQWRhbXMsIEplcmVteSBSZW5uZXIsIEZvcmVzdCBXaGl0YWtlcjwvcD48YnIgLz4KPHA%2BIFJlbGVhc2VkIFllYXIgOiAyMDE2PC9wPjxiciAvPgo8cD4gQ291bnRyeSBGcm9tIDogVVNBPC9wPjxiciAvPgo8cD4gTGFuZ3VhZ2UgVXNlZCA6IEVuZ2xpc2g8L3A%2BPGJyIC8%2BCjxwPiBHZW5yZXMgc2VlbXMgOiBEcmFtYSwgTXlzdGVyeSwgU2NpLUZpIDwvcD4%3D",
category: "aG9sbHl3b29kLW1vdmllcy0yMDE2",
poster: "aHR0cDovL29ubGluZW1vdmlld2F0Y2hzLnR2L3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDE2LzExL0Fycml2YWwtTW92aWUtUG9zdGVyLmpwZw%3D%3D",
rate: "MA%3D%3D",
year: "MjAxNg%3D%3D",
quality: "TkE%3D",
name: "QXJyaXZhbA%3D%3D",
genre: "RHJhbWEsIE15c3RlcnksIFNjaS1GaQ%3D%3D",
link: "aHR0cDovL29ubGluZW1vdmlld2F0Y2hzLnR2L2Fycml2YWwtMjAxNi1mdWxsLW1vdmllLW9ubGluZS1mcmVlLWhkLw%3D%3D",
src: "aHR0cDovLzE2My4xNzIuMjE0LjEwNS95a2dpcGltZWs2MmJpcm1wbmh3Z3J6bHJlMjZkajI1d29veTZ0Y2Y2MzdhM2ZnamRiY3duanc0c3V3aGEvdi5tcDQ%3D",
playersrc: "aHR0cDovL3B1dGxvYWQudHYvZW1iZWQtdDBpNDZodXplMG5lLmh0bWw%3D",
status: "MQ%3D%3D"
},
{
detail: "PHA%2BTW92aWUgRGV0YWlscyBPZiA6IEFycml2YWwgPC9wPjxiciAvPgo8cD4gQSBNb3ZpZSBEaXJlY3RvciBOYW1lIDogRGVuaXMgVmlsbGVuZXV2ZTwvcD48YnIgLz4KPHA%2BIENhc3RpbmcgSW4gTW92aWUgOiBBbXkgQWRhbXMsIEplcmVteSBSZW5uZXIsIEZvcmVzdCBXaGl0YWtlcjwvcD48YnIgLz4KPHA%2BIFJlbGVhc2VkIFllYXIgOiAyMDE2PC9wPjxiciAvPgo8cD4gQ291bnRyeSBGcm9tIDogVVNBPC9wPjxiciAvPgo8cD4gTGFuZ3VhZ2UgVXNlZCA6IEVuZ2xpc2g8L3A%2BPGJyIC8%2BCjxwPiBHZW5yZXMgc2VlbXMgOiBEcmFtYSwgTXlzdGVyeSwgU2NpLUZpIDwvcD4%3D",
category: "aG9sbHl3b29kLW1vdmllcy0yMDE2",
poster: "aHR0cDovL29ubGluZW1vdmlld2F0Y2hzLnR2L3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDE2LzExL0Fycml2YWwtTW92aWUtUG9zdGVyLmpwZw%3D%3D",
rate: "MA%3D%3D",
year: "MjAxNg%3D%3D",
quality: "TkE%3D",
name: "QXJyaXZhbA%3D%3D",
genre: "RHJhbWEsIE15c3RlcnksIFNjaS1GaQ%3D%3D",
link: "aHR0cDovL29ubGluZW1vdmlld2F0Y2hzLnR2L2Fycml2YWwtMjAxNi1mdWxsLW1vdmllLW9ubGluZS1mcmVlLWhkLw%3D%3D",
src: "aHR0cDovLzE2My4xNzIuMjE0LjEwNS95a2dpcGltZWs2MmJpcm1wbmh3Z3J6bHJlMjZkajI1d29veTZ0Y2Y2MzdhM2ZnamRiY3duanc0c3V3aGEvdi5tcDQ%3D",
playersrc: "aHR0cDovL3B1dGxvYWQudHYvZW1iZWQtdDBpNDZodXplMG5lLmh0bWw%3D",
status: "MQ%3D%3D"
}
];
AData(
'1',
'http://api.techsoul.in/movies/techsoul-update-movies.php?token=777&fun=addmovie',
details
);
Edit: In first version on this post, I did not see, that your json was not valid. Look at my answer now and it should work without any errors. Also, please inform youself about the JSON standard and fit it to your needs.

Related

JSPDF-INVOICE-TEMPLATE Create a pdf with N pages fetching data to a internal orders route

Hi to every one reading this. I am struggling with a PDF.js problem. I am using this library: https://github.com/edisonneza/jspdf-invoice-template to render a PDF with data that I am getting from an internal axios route that returns orders. This orders are listed with a checkbox, for the orders checked I generate a new array with the objects of the different orders checked.
Up to this I was doing fine, but the next thing I need is to generate this PDFs. I got it to work rendering one single pdf with the data order, but i would like to generete a PDF with (N) numbers of pages, using the checked orders to print with a button.
Below are the blocks of the code that i wrote.
printAllbtn.addEventListener('click',function(){
try {
if(ordersSelectedToPrint.length \> 1){
console.log(ordersSelectedToPrint);
for (let orderPrint of ordersSelectedToPrint) {
let pdfObject = jsPDFInvoiceTemplate.default(props);
console.log( 'object created' + pdfObject + orderPrint)
var props = {
outputType: jsPDFInvoiceTemplate.OutputType.Save,
returnJsPDFDocObject: true,
fileName: "remito",
orientationLandscape: false,
compress: true,
business: {
name: "Isidorito",
address: "San Pedro, Buenos",
phone: "(3329) 069 11 11 111",
email: "contacto#isidorito.com",
website: "www.isidorito.com.ar/nosotros",
},
contact: {
label: "Remito dirigito a:",
name: `${orderPrint.cliente.dueño}`,
address:`${orderPrint.cliente.direccion}`,
phone: `${orderPrint.cliente.telefono1}`,
email: `${orderPrint.cliente.correo}`,
},
invoice: {
label: "Pedido #",
num: 19,
invDate: `${orderPrint.createdAt}`,
invGenDate: `28/10/2022`,
headerBorder: false,
tableBodyBorder: false,
header: [
{
title: "#",
style: {
width: 10
}
},
{
title: "Productos descripción",
style: {
width: 70
}
},
{
title: "Cantidad ",
style: {
width:20
}
},
{ title: "Por Unidad",
style:{width:30}},
// { title: "Cantidad"},
{ title: "Por tot",
style:{
width:30
}},
{ title: "Total",
style:{
width:30
}}
],
table: Array.from(orderPrint.productosPedidosNombre).forEach(function(productoIm, index){[
index + 1,
`${productoIm.nombre} - ${productoIm.marca} - ${productoIm.presentacion}`,
`${productoIm.cantidad}`,
`${productoIm.cantidad}`,
`${productoIm.cantidad}`,
`${productoIm.cantidad}`,
]}),
invDescLabel: "Cliente:",
invDesc: `${orderPrint.cliente.nombreLocal}`,
},
footer: {
text: "Este remito generado digitalmente es valido para el pedido realizado",
},
pageEnable: true,
pageLabel: "Page ",
};
} } } catch (error) { console.log(error); }
});
The first note is that "orderPrint.productosPedidosNombre" is an array of products of the order. In the example from the documentation its represented in this way.
table: Array.from(Array(10), (item, index)=>([
index + 1,
"There are many variations ",
"Lorem Ipsum is simply dummy text dummy text ",
200.5,
4.5,
"m2",
400.5
])),
And the way I generate the PDF is:
let pdfObject = jsPDFInvoiceTemplate.default(props);
First I would like to know if it is possible the loops and iteration to generate this type of single file with N number of order pages, and each page with different data. It's possible with this library.
Thanks you. It's my second question I've asked in StackOverflow, so I welcome the feedback on the how to ask in stack overflow.

BigQuery API does not return newest table of a dataset

I need to find the most recent table by creation time in a BigQuery dataset. I have an Google Apps Script function that could find the newest table and it used to work fine when there were only a few tables in the dataset, but ever since there are more tables in the dataset(72 to be exact) it just keeps returning the same "newest" table (e.g tablename_1623468444656), even though I know that there exists a newer one.
The problem seems to be the size of the logger output, because when I log the output it says: "Logging output too large. Truncating output". But regardless of whether I log the output or not, it just returns the allegedly newest table (e.g tablename_1623468444656).
I don't know what I need to change so that the function can find the actual newest table again. The function looks like this:
function findNewestTables() {
const data = BigQuery.Tables.list('Projectname', 'Datasetname');
let
maxSoFar = 0,
id = "";
data.tables.forEach(table => {
const time = parseInt(table.creationTime);
if(time > maxSoFar){
maxSoFar = time;
id = table.id;
}
});
const formattedId = id.replace(":", ".");
// return formattedId;
console.log(data);
console.log(formattedId);
};
Part of the output looks something like this and then it is just abruptly cut off.
Logging output too large. Truncating output. { totalItems: 72,
kind: 'bigquery#tableList',
etag: '7+eK1beNA7CVq0xasdfdsfYw==',
nextPageToken: 'Team_1627356444573',
tables:
[ { id: 'tablename_1623468444656',
type: 'TABLE',
kind: 'bigquery#table',
creationTime: '1628585864499',
tableReference: [Object] },
{ tableReference: [Object],
id: 'tablename_1623554844685',
kind: 'bigquery#table',
creationTime: '1628585864503',
type: 'TABLE' },
{ id: 'tablename_1623641244614',
type: 'TABLE',
kind: 'bigquery#table',
tableReference: [Object],
creationTime: '1628585864573' },
{ tableReference: [Object],
kind: 'bigquery#table',
creationTime: '1628585864714',
type: 'TABLE',
id: 'tablename_1623727644545' },
{ tableReference: [Object],
kind: 'bigquery#table',
type: 'TABLE',
creationTime: '1628585865059',
id: 'tablename_1623814044558' },
{ creationTime: '1628585865037',
id: 'tablename_1623900444676',
type:
Thanks in advance for any tips.
So, this is one of those cases where you need to paginate. See the nextPageToken? If that value isn't empty/nil, it means you can call tables.list again and pass that token as the pageToken GET param in a subsequent request to get the next page of results.
More details about the API: https://cloud.google.com/bigquery/docs/reference/rest/v2/tables/list

update multiple different documents in mongodb (nodejs backend) [duplicate]

This question already has answers here:
MongoDB: How to update multiple documents with a single command?
(13 answers)
Closed 3 years ago.
I looked at other questions and I feel mine was different enough to ask.
I am sending a (potentially) large amount of information back to my backend, here is an example data set:
[ { orders: [Array],
_id: '5c919285bde87b1fc32b7553',
name: 'Test',
date: '2019-03-19',
customerName: 'Amego',
customerPhone: '9991112222',
customerStreet: 'Lost Ave',
customerCity: 'WestZone',
driver: 'CoolCat',
driverReq: false, // this is always false when it is ready to print
isPrinted: false, // < this is important
deliveryCost: '3',
total: '38.48',
taxTotal: '5.00',
finalTotal: '43.48',
__v: 0 },
{ orders: [Array],
_id: '5c919233bde87b1fc32b7552',
name: 'Test',
date: '2019-03-19',
customerName: 'Foo',
customerPhone: '9991112222',
customerStreet: 'Found Ave',
customerCity: 'EastZone',
driver: 'ChillDog',
driverReq: false,// this is always false when it is ready to print
isPrinted: false, // < this is important
deliveryCost: '3',
total: '9.99',
taxTotal: '1.30',
finalTotal: '11.29',
__v: 0 },
{ orders: [Array],
_id: '5c91903b6e0b7f1f4afc5c43',
name: 'Test',
date: '2019-03-19',
customerName: 'Boobert',
customerPhone: '9991112222',
customerStreet: 'Narnia',
customerCity: 'SouthSzone',
driver: 'SadSeal',
driverReq: false,// this is always false when it is ready to print
isPrinted: false, // < this is important
deliveryCost: '3',
total: '41.78',
taxTotal: '5.43',
finalTotal: '47.21',
__v: 0 } ] }
My front end can find all the orders that include isPrinted:false, I then allow the end user to 'print' all the orders that are prepared, in which, I need to change isPrinted into true, that way when I pull up a next batch I won't have reprints.
I was looking at db.test.updateMany({foo: "bar"}, {$set: {isPrinted: true}}), and I currently allow each order to set a new driver, which I update by:
Order.update({
_id: mongoose.Types.ObjectId(req.body.id)
},
{
$set: {
driver:req.body.driver, driverReq:false
}
which is pretty straight forward, as only 1 order comes back at a time.
I have considered my front end doing a foreach and posting each order individually, then updating the isPrinted individually but that seems quite inefficient. Is there a elegant solutions within mongo for this?
I'm not sure how I would user updateMany considering each _id is unique, unless I grab all the order's who are both driverReq:false and isPrinted:false (because that is the case where they are ready to print.
I found a solution, that was in fact using UpdateMany.
Order.updateMany({
isPrinted: false, driverReq:false
},
{
$set: {
isPrinted: true
}
consider there this special case where both are false when it needs to be changed too true. But I do wonder if there is a way to iterate over multiple document id's with ease.

How to parse a Non-Json data hemera

I am new to Json and JavaScript. Currently I have a url which returns a JSON response. But the problem is that, It is not in correct format. Please see my response below
var pd={ player:
{ id: 363609002,
game: 'bf4',
plat: 'pc',
name: 'm4jes',
tag: 'BPt',
dateCheck: 1487204427149,
dateUpdate: 1474581052618,
dateCreate: 1384980182606,
dateStreak: 1474581052618,
lastDay: '20160715',
country: '',
countryName: null,
rank:
{ nr: 121,
imgLarge: 'bf4/ranks/r121.png',
img: 'r121',
name: 'Major General II',
needed: 16110000,
next:
{ nr: 122,
imgLarge: 'bf4/ranks/r122.png',
img: 'r122',
name: 'Major General III',
needed: 16750000,
curr: 16720600,
relNeeded: 640000,
relCurr: 610600,
relProg: 95.40625 } },
score: 16724643,
timePlayed: 1476950,
uId: '2832665149467333131',
uName: 'm4jes',
uGava: '721951facb53ed5632e196932fb6c72e',
udCreate: 1319759388000,
privacy: 'friends',
blPlayer: 'http://battlelog.battlefield.com/bf4/soldier/m4jes/stats/363609002/pc/',
blUser: 'http://battlelog.battlefield.com/bf4/user/m4jes/',
editable: false,
viewable: true,
adminable: false,
linked: false },}
from the above response I have to get the output as :
{
game: 'bf4',
plat: 'pc',
name: 'm4jes',
tag: 'BPt',
score: 16724643,
timePlayed: 1476950
}
By which method I can get the required out in Javascript
First of all the URL is not returning a JSON response but a JS object literal. The difference is explained here.
You have to get the string from the url. You can use the jQuery method get():
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
var jqxhr = $.get( "https://api.bf4stats.com/api/playerInfo?plat=pc&name=m4jes&output=js", function() {
//Insert the rest of the code here
});
</script>
Then, jqxhr.responseText is the string which correspond to the object we want. With eval, we transform the string into an object:
pd = eval(jqxhr.responseText);
So here we have an object literal with all the pairs name/value. You can access the values you want by using the dot notation. If you want to get the name of the game for example, you can write this:
pd.player.game
So this leads to :
var myNewObject = {
game: pd.player.game,
plat: pd.player.plat,
name: pd.player.name,
tag: pd.player.tag,
score: pd.player.score,
timePlayed: pd.player.timePlayed,
}
Then, you have to transform this JS object literal into a JSON by using the JSON.stringify() method:
console.log(JSON.stringify(myNewObject, null, '\t'));
It returns what you want:
{
"game": "bf4",
"plat": "pc",
"name": "m4jes",
"tag": "BPt",
"score": 16724643,
"timePlayed": 1476950
}
So here is the full code:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
var jqxhr = $.get( "https://api.bf4stats.com/api/playerInfo?plat=pc&name=m4jes&output=js", function() {
pd = eval(jqxhr.responseText);
var myNewObject = {
game: pd.player.game,
plat: pd.player.plat,
name: pd.player.name,
tag: pd.player.tag,
score: pd.player.score,
timePlayed: pd.player.timePlayed,
}
console.log(JSON.stringify(myNewObject, null, '\t'));
});
</script>

Extracting Javascript Variable Object Data in Python and Beautiful Soup Web Scraping

I can currently scrape Javascript data from a post request I sent using requests then Soup. But I only want to scrape the product plu, sku, description and brand. I am struggling to find a way in which I can just print the data I need rather then the whole script. This is the text that is printed after I extract the script using soup. I will be scraping more than one product from multiple post requests, so the chunk idea is not really suitable.
<script type="text/javascript">
var dataObject = {
platform: 'desktop',
pageType: 'basket',
orderID: '',
pageName: 'Basket',
orderTotal: '92.99',
orderCurrency: 'GBP',
currency: 'GBP',
custEmail: '',
custId: '',
items: [
{
plu: '282013',
sku: '653460',
category: 'Footwear',
description: 'Mayfly Lite Pinnacle Women's',
colour: '',
brand: 'Nike',
unitPrice: '90',
quantity: '1',
totalPrice: '90',
sale: 'false'
} ]
};
As you can see it is far too much information.
How about this:
You assign the captured text to a new multiline string variable called "chunk"
Make a list of keys you are looking for
Loop over each line to check if the line has a term that you want, and then print out that term:
chunk = '''
<script type="text/javascript">
var dataObject = {
.........blah blah.......
plu: '282013',
sku: '653460',
category: 'Footwear',
description: 'Mayfly Lite Pinnacle Women's',
colour: '',
brand: 'Nike',
..... blah .......
};'''
keys = ['plu', 'sku', 'description', 'brand']
for line in chunk.splitlines():
if line.split(':')[0].strip() in keys:
print line.strip()
Result:
plu: '282013',
sku: '653460',
description: 'Mayfly Lite Pinnacle Women's',
brand: 'Nike',
You could obviously clean up the result using similar applications of split, strip, replace, etc.

Categories