I am trying to modify Exif data of a jpg using piexifjs module. it works well but for the most important and basic Tags like Title, Comment, Author... It doesn't work at all.
var piexif = require("piexifjs");
var fs = require("fs");
var filename1 = "image.jpg";
var filename2 = "out.jpg";
var jpeg = fs.readFileSync(filename1);
var data = jpeg.toString("binary");
var zeroth = {};
zeroth[piexif.ImageIFD.XPTitle] = "Birds";
var exifObj = {"0th":zeroth};
var exifbytes = piexif.dump(exifObj);
var newData = piexif.insert(exifbytes, data);
var newJpeg = Buffer.from(newData, "binary");
fs.writeFileSync(filename2, newJpeg);
when I run it it throws Error: 'pack' error. Got invalid type argument.
I search the internet and in Metadata reference tables it says they are of type Byte https://www.exiv2.org/tags.html. so when I make it zeroth[piexif.ImageIFD.XPTitle] = 4; or some number it runs, but without changing the title.
so how can I make it work? what does it mean when their type is Byte? how can
I found the answer here. You need:
zeroth[piexif.ImageIFD.XPTitle] = [...Buffer.from('Birds', 'ucs2')];
zeroth[piexif.ImageIFD.XPComment] = [...Buffer.from('Tweet tweet', 'ucs2')];
zeroth[piexif.ImageIFD.XPAuthor] = [...Buffer.from('Ornithologist', 'ucs2')];
Result:
Pretty new to all this but have a simple script to pull API info and put into google sheets. I want to pull the top 20 coins but I'm unsure of how to do it as a ??'function'?? to limit the amount of code required presently especially since only 'XXX' is basically changing. Thanks in advance
var urlBTC='https://api.binance.com/api/v3/klines?symbol=BTCUSDT&interval=1d&limit=2';
var responseBTC = UrlFetchApp.fetch(urlBTC,{'muteHttpExceptions': true});
var jsonBTC = responseBTC.getContentText();
var parseBTC = JSON.parse(jsonBTC);
sheetBTC.getRange(3,3).setValue(parseBTC[0][6]);
var sheetETH = sh.getSheetByName("ETH");
var urlETH='https://api.binance.com/api/v3/klines?symbol=ETHUSDT&interval=1d&limit=2';
var responseETH = UrlFetchApp.fetch(urlETH,{'muteHttpExceptions': true});
var jsonETH = responseETH.getContentText();
var parseETH = JSON.parse(jsonETH);
sheetETH.getRange(3,3).setValue(parseETH[0][6]);
}```
var coins = ['ETHUSDT','BTCUSDT']
function getCoin(){
coins.forEach(coin => {
let url = 'https://api.binance.com/api/v3/klines?symbol='+ coin
+ '&interval=1d&limit=2'
//do the other stuff
})
}
Hope this helps set you off in the right direction.
Basically we store the symbols as an array loop through and create a url for that, in the 'do something' put in your other code for handling the req. watch out for rate limits
I am trying to get data from a JSON file and use Javascript Code to put it into Google Spreadsheet, I did good with some part of the data but I'm stuck with the other part, where I want to match the User Id and put all the data with it on a same row,
JSON Data:
"m":{"414":{"a":{"0":{"c":38,"p":12812.4},
"4":{"c":35,"p":10559.94},"2":{"c":43,"p":35811.63},
"6":{"c":48,"p":45530}},"d":{"0":{"c":55,"p":5477.06225},
"4":{"c":694,"p":106649.473},"2":{"c":1844,"p":716733.50775000011},
"6":{"c":605,"p":324152.5875}},"i":{"0":{"c":0,"p":0},
"4":{"c":0,"p":0},"2":{"c":0,"p":0},"6":{"c":542,"p":19893.93}}},
"404":{"a":{"0":{"c":15,"p":916.182},"4":{"c":50,"p":12357},
"2":{"c":530,"p":390825.27},"6":{"c":58,"p":4841.55}},
"d":{"0":{"c":10,"p":3145.8},"4":{"c":770,"p":141876.12},
"2":{"c":4854,"p":2173966.6125000003},
"6":{"c":1973,"p":1145077.425}},"i":{"0":{"c":0,"p":0},
"4":{"c":0,"p":0},"2":{"c":0,"p":0},"6":{"c":594,"p":25444.41}}}},
Javascript:
var testUF = [];
var Uid = Object.getOwnPropertyNames(doc1.m);
for (var lp2 = 0; lp2 < Uid.length; lp2++) {
var Ua1 = doc1.m[lp2].a["0"].p;
var Ua2 = doc1.m[lp2].a["4"].p;
var Ua3 = doc1.m[lp2].a["2"].p;
var Ua4 = doc1.m[lp2].a["6"].p;
var Ud1 = doc1.m[lp2].d["0"].p;
var Ud2 = doc1.m[lp2].d["4"].p;
var Ud3 = doc1.m[lp2].d["2"].p;
var Ud4 = doc1.m[lp2].d["6"].p;
var Ui4 = doc1.m[lp2].i["6"].p;
testUF.push([Uid,Ua1,Ua2,Ua3,Ua4,Ud1,Ud2,Ud3,Ud4,Ui4]);}
I am getting the Array on the Uid while Debugging, but all the other Variables don't get the data it stays Undefined. I want all the other variables to match with the Uid's and stay in the same row. I did the JSON parsing and everything.
I am asking for the first time on stackoverflow, please forgive me if I couldn't state everything properly. Thank you for the help. :)
You're not using the array index for Uid properly.
Change:
var Ua1 = doc1.m[lp2].a["0"].p;
To:
var Ua1 = doc1.m[Uid[lp2]].a["0"].p;
Here is my fiddle: jsfiddle.net/XR8EZ
I cannot get the save data to load after clicking the load button. Can anyone help me here?
Sorry for the length =D
The load routine is wrong.
You save all your datas (stringifyed) with setItem('serializedObj').
Then you retrieve value with "retrievedItem = localStorage.getItem('serializedObj');" but not save the value of "JSON.parse(retrievedItem);".
Then you try to retrieve values directly by localStorage.getItem(imgName);
You retrive and save data parded:
dataparsed = JSON.parse(retrievedItem);
Then you must use this value for retrieving values:
//Reconstruct the original image array
for (i=0;i<totalState.length;i++) {
var thisParseImgVal = dataparsed.imgName;
totalImage[i] = JSON.parse(thisParseImgVal);
}
You have to correct you save/load code, I suggest you to save you data as array:
var imgVal = JSON.stringify(totalImage);
var shpVal = JSON.stringify(totalShape);
var hLval = JSON.stringify(totalHighlight);
var str = {imgName:imgVal,shpName:shpVal,hLname:hLval}; //Store
So you must read it as:
totalImage[i] = JSON.parse(thisParseImgVal[i]);
Google wasn't my friend on this one... maybe I wasn't searching for the right terms.
I have a javascript array randomTagLine[0], randomTagLine[1], etc. How do I get the total number of variables in the array? For instance, I can physically see there are 23, but I need to pull that out via JS code...
Thanks in advance..
EDIT
Example of code:
var randomTagline = new Array();
randomTagline[0] = "TEXT0";
randomTagline[1] = "TEXT1";
randomTagline[2] = "TEXT2";
//...
randomTagline[23] = "TEXT23";
var randomTaglineLength = randomTagLine.length;
var randomTaglineNum = randomXToY(0,randomTaglineLength,0);
alert(randomTaglineNum + " " + randomTaglineLength);
It's :
var length = randomTagLine.length;