I saved data on workbook on following code
export const storeSettingsToWorkbook = async (settingsType: Settings, storeData:
WorkbookModel) => {
return Excel.run(async (context) => {
const originalXml = createXmlObject(storeData);
const customXmlPart = context.workbook.customXmlParts.add(originalXml);
customXmlPart.load("id");
await context.sync();
// Store the XML part's ID in a setting
const settings = context.workbook.settings;
settings.add(settingsTitles[settingsType], customXmlPart.id);
await context.sync();
})
}
when i get data -it works normally.But when i want to get this data form another "add-in" on Excel- I cannot get this data
const {settings} = context.workbook;
const sheet = context.workbook.worksheets.getActiveWorksheet().load("items");
const xmlPartIDSetting = settings.getItemOrNullObject(settingsTitles[settingsType]).load("value");
await context.sync();
if (xmlPartIDSetting.value) {
const customXmlPart = context.workbook.customXmlParts.getItem(xmlPartIDSetting.value);
const xmlBlob = customXmlPart.getXml();
await context.sync()
const parsedObject = parseFromXmlString(xmlBlob.value);
const normalizedData = normalizeParsedData(parsedObject);
Any ideas?
Thanks for reaching us.
This is by design. Each addin has its own setting and cannot share with each other.
You can use 'context.workbook.properties.custom' as a workaround.
You can also use 'context.workbook.worksheets.getActiveWorksheet().customProperties', but the two add-ins are required to be on the same worksheet.
Related
I am using web3js to get transaction details
my code:
const transactionHash = this._req.query.transactionHash;
const transaction = await this._web3.eth.getTransactionReceipt(transactionHash);
const logs = await transaction.logs;
const log = await logs.find(i => i.transactionHash === transactionHash);
const topics = await log.topics;
const test = await this._web3.eth.abi.decodeParameter('bytes32', topics[0]);
const from = await this._web3.eth.abi.decodeParameter('address', topics[1]);
const to = await this._web3.eth.abi.decodeParameter('address', topics[2]);
const value = await this._web3.eth.abi.decodeParameter('uint256', log.data);
const amount = await this._web3.utils.fromWei(value);
But I still haven't got the token name of the transaction
Give me some suggestions, thanks
To get the token symbol, you need to call the token contract's function symbol().
Since the Transfer event was emitted by the token contract, you have its address in the log.address property. Then you just need to call the symbol() function:
const abiJson = [
{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"}
];
const contract = new web3.eth.Contract(abiJson, log.address);
const symbol = await contract.methods.symbol().call();
I'm trying to fetch the contents of page 4 of a PDF file using 'pdfjs-dist'.
I've tried to replace the 'pdfjs-dist' module with 'const pdfjs = require("pdfjs/es5/build/pdf")' but with no success.
What could be problem?
Thanks in advance!
const pdfjs = require('pdfjs-dist'); // Fetch PDF
async function getContent(src) {
const doc = await pdfjs.getDocument(src).promise // note the use of the property promise
const page = await doc.getPage(4)
return await page.getTextContent()
}
console.log(getContent('pdfs/Quantum.pdf'))
It's too late to reply to this questions but let me add the solution that worked for me for those who will wish to implement the some issue.
This is the code that will work fine
// Install the latest version of pdf.js via npm i pdfjs-dist
const pdfjsLib = require("pdfjs-dist/legacy/build/pdf.js");
let pdf_path = "{RELATIVE_PATH_TO_YOUR_FILE}/sample.pdf";
async function getContent(src: any){
const doc = await pdfjsLib.getDocument(src).promise;
const page = await doc.getPage(1);
const strings: any = await page.getTextContent();
let ITEMS_STRINGS = strings.items.map((item: any) => item.str);
let PDF_STRINGS: string = ITEMS_STRINGS.join(" ");
return PDF_STRINGS;
}
console.log(await getContent(`${pdf_path}`));
This will work fine
I'm trying to scrape three fields from different companies listed in a webpage. The idea here is to make use of this webpage, parse the inner page links of different companies from the landing page and finally scrape title,phone and email from the detail pages. The script that I've created can perform this without any issue.
However, I wish to scrape content from next pages (Next) as well. As I'm very new to node, I would appreciate if somebody could help me implement the logic of grabbing next pages within the script below.
const puppeteer = require("puppeteer");
const base = "https://www.timesbusinessdirectory.com";
const url = "https://www.timesbusinessdirectory.com/company-listings";
(async () => {
const browser = await puppeteer.launch({headless:false});
const [page] = await browser.pages();
await page.goto(url,{waitUntil: 'networkidle2'});
page.waitForSelector(".company-listing");
const sections = await page.$$(".company-listing");
let data = [];
for (const section of sections) {
const itemName = await section.$eval("h3 > a", el => el.getAttribute("href"));
data.push(itemName);
}
let itmdata = [];
for (const link of data) {
const newlink = base.concat(link);
await page.goto(newlink,{waitUntil: 'networkidle2'});
page.waitForSelector(".company-details");
const result = await page.$$(".company-details");
for (const itmres of result) {
const company = await itmres.$eval("h3", el => el.textContent);
const phone = await itmres.$eval("#valuephone a[href]", el => el.textContent);
const email = await itmres.$eval("a[onclick^='showCompanyEmail']", el => el.getAttribute("onclick"));
console.log({
title: company,
tel : phone.trim(),
emailId : email.split("('")[1].split("',")[0]
});
}
}
await browser.close();
})();
How can I implement the logic of traversing next pages within the script?
EDIT:
I was trying to use the next page link within the script iteratively defining a while loop. This time the script however doesn't seem to respond at all. Perhaps I've done something wrong along the lines.
In your current code, you declare new url variable in each iteration. Instead of this, you need to declare the outer url variable as let and redefine it:
let url = "https://www.timesbusinessdirectory.com/company-listings";
// ...
url = base.concat(nextPageLink);
i try to activate Revit Levels and 2D Minimap extension in autodesk forge viewer, but can not get AEC Model Data. I got this worning`
i tried to get AEC data with this code
const url = window.location.search;
console.log(url);
const svf_path = `${url.replace("?", "/storage/").replace(/%20/g, " ")}`;
Autodesk.Viewing.endpoint.getItemApi = (endpoint, derivativeUrn, api) => {
return svf_path;
};
Autodesk.Viewing.Initializer(options, async () => {
const paths = svf_path.split("/");
const [dest, svf_dir] = [paths[2], paths[3]];
const url = `/api/viewer/dest/${dest}/svf/${svf_dir}/manifest`;
const response = await fetch(url);
const manifest = await response.json();
const init_div = document.getElementById("init_div");
viewer = new Autodesk.Viewing.GuiViewer3D(init_div, config3d);
const viewerDocument = new Autodesk.Viewing.Document(manifest);
const viewable = viewerDocument.getRoot().getDefaultGeometry();
viewer.start();
await viewerDocument.downloadAecModelData();
viewer.loadDocumentNode(viewerDocument, viewable)
.then(function (result) {
Autodesk.Viewing.Document.getAecModelData(viewable);
})
});
wats wrong in my code?
The warning comes from the BubbleNode.prototype.getAecModelData method. You are not calling it in your code but it's possible that it's being called by the LevelsExtension itself. Try configuring the extension so that it doesn't detect the AEC data automatically by passing in { autoDetectAecModelData: false } as the extension options.
Btw. to debug the issue on your side, you can also try getting the non-minified version of viewer3D.js, put a breakpoint to where the warning is being logged, and see the call stack when the breakpoint is hit.
I have a json file that is generated dynamically by taking the values of a page using a crawler, json is created as follows:
{
"temperatura":"31°C",
"sensacao":"RealFeel® 36°",
"chuva":"0 mm",
"vento":"NNO11km/h",
"momentoAtualizacao":"Dia",
"Cidade":"carazinho",
"Site":"Accuweather"
}
{
"temperatura":"29 º",
"sensacao":"29º ST",
"vento":"11 Km/h",
"umidade":"51% UR",
"pressao":"1013 hPa",
"Cidade":"carazinho",
"Site":"Tempo Agora"
}
The problem with this generated file is missing [] to join all the files inside an array, and commas to separate the files.
The final json should look like this:
[{
"temperatura":"31°C",
"sensacao":"RealFeel® 36°",
"chuva":"0 mm",
"vento":"NNO11km/h",
"momentoAtualizacao":"Dia",
"Cidade":"carazinho",
"Site":"Accuweather"
},
{
"temperatura":"29 º",
"sensacao":"29º ST",
"vento":"11 Km/h",
"umidade":"51% UR",
"pressao":"1013 hPa",
"Cidade":"carazinho",
"Site":"Tempo Agora"
}]
I am currently using this code to generate json.
const climatempo = async (config) => {
const browser = await puppeteer.launch()
const page = await browser.newPage()
const override = Object.assign(page.viewport(), {width: 1920, heigth:1024});
await page.setViewport(override);
await page.goto(config.cidades[cidade],{waitUntil: 'load',timeout:'60000'})
if(siteEscolhido == "accu"){
const elementTemp = await page.$(config.regras.elementTemp)
const temperatura = await page.evaluate(elementTemp => elementTemp.textContent, elementTemp)
const sensacaoElement= await page.$(config.regras.sensacaoElement)
const sensacao = await page.evaluate(sensacaoElement => sensacaoElement.textContent, sensacaoElement)
const chuvaElement = await page.$(config.regras.chuvaElement)
const chuva = await page.evaluate(chuvaElement => chuvaElement.textContent, chuvaElement)
const ventoElement = await page.$(config.regras.ventoElement)
const vento = await page.evaluate(ventoElement => ventoElement.textContent, ventoElement)
const atualizadoA = await page.$(config.regras.atualizadoA)
const momentoAtualizacao = await page.evaluate(atualizadoA => atualizadoA.textContent, atualizadoA)
var dado = {
temperatura:temperatura,
sensacao:sensacao,
chuva:chuva,
vento:vento,
momentoAtualizacao:momentoAtualizacao,
Cidade:cidade,
Site:"Accuweather"
}
//dados.push(dado)
var x = JSON.stringify(dado)
fs.appendFile('climatempo.json',x,function(err){
if(err) throw err
})
console.log("Temperatura:" + temperatura)
console.log(sensacao)
console.log("Vento:" + vento)
console.log("chuva:" + chuva)
console.log(momentoAtualizacao)
await browser.close()
If anyone has any idea how to solve my problem, please let me know!
Grateful, Carlos
I would suggest doing it a little differently
I will try to explain in pseudo code since i dont understand your variable names
read json file
array = JSON.parse(fileContents)
array.push(newItem)
newContents = JSON.stringify(array)
file WRITE (not append) newContents
I recommend reading the file, pushing onto an array captured from that file, and then writing the file back to disk.
Assuming the file has content already in the form of an array:
let fileDado = JSON.parse(fs.readFileSync('climatempo.json'));
fileDado.push(dado);
fs.writeFileSync('climatempo.json', JSON.stringify(fileDado));