-1

Please read the question carefully first.

I have tried so many commands to retrieve one variable from the server [TSE] (https://old.tsetmc.com/Loader.aspx?ParTree=15131F) (It serves Stock Exchange information). This page is a JavaScript playground that uses Filters and the filters are available in the cache to view by pressing the F12, entering the console, pasting the command

JSON.parse( localStorage.MarketWatchSettings)['Filters']

, accepting the consequences and viewing the codes but the page has a text field that allows you to write the codes as soon as you get in.

Webpage preview

The variable is *(l18)* and represents the company name. As you know this kinda server is not open to users and it can only deliver the information you want.

The question is clearly: how can I allocate a number to the company name that is available in a list that I prepared to be able to make a link from that very server opening with [text](http://www.tsetmc.com/InstInfo) and contiuning with a set of number such as [text](http://www.tsetmc.com/InstInfo/25244329144808274) for the biggest company named "Fars"?

The list is so long and I shortened it to a preview for you:

const StockCodes = {
آبادا: [37661500521100963],
آپ: [55254206302462116],
آسيا: [51106317433079213],
};

We need to match the (l18) string (that is retrieved live) to the keys in constant above and use the value (number) in front of it. Later then umber is used to complete the link http://www.tsetmc.com/InstInfo and make a new link such as http://www.tsetmc.com/InstInfo/37661500521100963.

I tried some solutions and here's three of them:

1.*Constant itself*:

var Names = StockCodes.(l18)
var url = String.fromCodePoint(StockCodes);
var finalLink = "http://www.tsetmc.com/InstInfo/"+url
console.log(finalLink)

2. *Includes*:

 var Names = StockCodes.(l18)
 if (StockCodes.includes((l18)))
 {var finalLink ="http://www.tsetmc.com/InstInfo/"+Names}
console.log(finalLink)

3. *Match*:

let resultofsearch = StockCodes.match((l18));
var TSEPage = TSEPageCode(StockCodes.resultofsearch)
var finalLink = "http://www.tsetmc.com/InstInfo/"+TSEPage
console.log(finalLink)

The

(l18)

represents a name (the company name) in words (letters and sometimes letters with numbers but opening with letters) and sometimes has white space too.

A big problem with the strings like this is the parentheses. You cannot use them after the dots to call rows. The other question that is raises under this question is How can I solve this problem when the server dictates that the string starts and ends with the parentheses such as `"(tmin)"` for lowest price?

We cant use: "...StockCodes.(l18)" within the code (it pushes an error:

TypeError:StockCodes.row is undefined

All of the codes in one place:

var companyname = (l18) && (l18) = "آبادا"
const StockCodes = {
آبادا: [37661500521100963],
آپ: [55254206302462116],
آسيا: [51106317433079213],
};

var Names = StockCodes.(l18)
var url = String.fromCodePoint(StockCodes);
var finalLink = "http://www.tsetmc.com/InstInfo/"+url
console.log(finalLink)

var Names = StockCodes.(l18)
 if (StockCodes.includes((l18)))
 {var finalLink ="http://www.tsetmc.com/InstInfo/"+Names}
console.log(finalLink)

let resultofsearch = StockCodes.match((l18));
var TSEPage = TSEPageCode(StockCodes.resultofsearch)
var finalLink = "http://www.tsetmc.com/InstInfo/"+TSEPage
console.log(finalLink)
mohsen
  • 1
  • 4
  • Please provide sample value for `StockCodes` and `stockcodes` (they are not the same, or did you mistype them?) and `l18` in JavaScript format (not copy/paste from console). – trincot Jul 30 '23 at 20:13
  • Corrected. Thanks for reminding :) – mohsen Jul 31 '23 at 08:20
  • It's (l18) and l18 is incorrect. You can use the following code to filter the companies using their names to آبادا only: '''if ((l18) = "آبادا") {(cfield0) = "name: " + (l18) + "EPS: " + (eps) + "at: " + let today = new Date().toLocaleDateString('fa-IR')}''' and the (cfield0) is a column you make customly – mohsen Jul 31 '23 at 08:26
  • I think you misunderstand syntax. The parentheses are just like you would have in `((1+2)*3)`, they are not part of a variable name. The variable names you have there are `l18`, `eps`, `cfield0`, ...etc. – trincot Jul 31 '23 at 08:29
  • In this case they are a part of variable name cause they're gonna be retrieved from the server and will be translated to its own language consisting of commands of which we have no information. – mohsen Jul 31 '23 at 08:32
  • I think the page can fix everything if you open it. Though it's not in English maybe the translation button will work: https://old.tsetmc.com/Loader.aspx?ParTree=15131F – mohsen Jul 31 '23 at 08:34
  • So then the code you just put in your previous comment makes no sense, right? – trincot Jul 31 '23 at 08:36
  • Also, 8 hours ago an answer was posted. It would be good if you would provide some feedback below that answer. – trincot Jul 31 '23 at 08:40
  • No dear @trincot it makes sense and it's a sample. As you see the parentheses are not under your power and you have to use `(l18)` as company name (`l18` will give an error as undefined because it IS undefined until you change it to `(l18)`). Anyway forget about the other code `(cfield0)`. It will extend the discussion. – mohsen Jul 31 '23 at 09:11
  • You are saying "(l18)" is a string. So that makes the code snippet above clearly wrong, since there you are trying to work with variables `l18` and `eps`, which don't exist as far as I understand what you are saying. Just wanted to point that out. Also, my question for you to provide the input in literal JavaScript syntax is still open... This question is ambiguous and could be easily clarified if you would just provide the input literally in JavaScript syntax, and the corresponding expected output in JavaScript syntax. – trincot Jul 31 '23 at 09:14
  • Please edit your question. This is hardly readable. Still, this does not include where `l18` comes from. Please include initialisation of whatever input you get about company names. `StockCodes.(l18)` is invalid syntax. – trincot Jul 31 '23 at 09:46
  • Okay if you want the code in one snippet https://jsfiddle.net/mj1u03zf/2/ – mohsen Jul 31 '23 at 09:59
  • We are allowed to use JavaScript in a text field to call everything that is prepared beforehand like `(l18)` to filter the companies by symbol name and so many other inputs like `(tmin)` for loest price, `(tmax)` for highest price, `(mv)` for market value, `(pc)` for close price and a lot of other inputs that allows you to use and push the save button of the filter to enable it. You can see that almost all of them have parentheses! The link is in Persian and I don't know if you can use the browsers translate button maintaining the JavaScript. https://old.tsetmc.com/Loader.aspx?ParTree=15131F – mohsen Jul 31 '23 at 10:07
  • The snippet on https://jsfiddle.net/mj1u03zf/2/ doesn't run: it raises a syntax error. Please make sure you provide input in **valid** JavaScript syntax. – trincot Jul 31 '23 at 10:23
  • After your latest edit, I wonder why you haven't provided the input in valid JavaScript syntax, so that your problem is *reproducible*. I give up. – trincot Jul 31 '23 at 11:24
  • Here! If you wanted the snippet. But I assure you there's no way it works here – mohsen Jul 31 '23 at 11:39
  • If you cannot provide the input in valid JavaScript, then this is a question that will not be answered. You cannot expect *us* to magically know what your input really is. It is a basic requirement that you provide the input in JavaScript, without syntax errors. – trincot Jul 31 '23 at 11:46
  • There's no other choice! Either you should be able to view the webpage or I should make an iframe that delivers it to you which is also not applicable. It's live server based information and there's no other way. – mohsen Jul 31 '23 at 12:11
  • Surely there is. Just create sample data for the purpose of the question. There is no need to be on the live site. – trincot Jul 31 '23 at 12:18
  • Okay. I'll try without the website but what to do with the parentheses!? Let's see what I can do. – mohsen Jul 31 '23 at 12:40
  • What about this?: https://stackoverflow.com/questions/1885557/simplest-code-for-array-intersection-in-javascript?noredirect=1&lq=1 Is it gonna help? – mohsen Jul 31 '23 at 12:57
  • Using `const filteredArray = StockCodes.filter(value => (l18));` – mohsen Jul 31 '23 at 13:02
  • `(l18)[(l18).length-1]=='x'` This code shows the names that the last letter is 'x'. Does this help? What is (l180)? is it a string? If true, can we use strings as constants, like: string[...]? Is that correct? – mohsen Aug 13 '23 at 15:42

1 Answers1

0

It's not clear what is the l18 - the number or the word? either way I have presented the ways you can get one by the other.

Only other problem, is javascript has a limit for integer size, so for example 55254206302462116 is too big so you should use strings instead.

const StockCodes = {
  آبادا: ["37661500521100963"],
  آپ: ["55254206302462116"],
  آسيا: ["51106317433079213"],
};

var l18 = "آبادا"
var code = StockCodes[l18][0]
console.log(code)

// other way around
var l18 = "55254206302462116"
var StockCodesInv = Object.entries(StockCodes).reduce(function(agg, [key, value]) {
  agg["" + value[0]] = key;
  return agg;
}, {});
var company = StockCodesInv[l18]
console.log(company)
IT goldman
  • 14,885
  • 2
  • 14
  • 28
  • Dear @it-goldman, this code is great but it doesn't answer the question! As I answered @trincot above, the parentheses are a part of variables. We simply need to match the `(l18)` to `StockCodes` constant and find the company name in its keys and match the key's value (which is a number) to put the values next to a text (a ulr: http://www.tsetmc.com/InstInfo/) to make the link. So there sould be at least one "if" in the code like `if ((l18)) {var urlNumber = StockCodes.(l18)}; var url = "http://www.tsetmc.com/InstInfo/" + urlNumber; console.log(url)` – mohsen Jul 31 '23 at 09:00
  • The first way you sent does it return the first value from آبادا row (using`[0]`)? It looks like but THE BIG PROBLEM are the parentheses now. It pushes an error stating that "TypeError: StockCodes[row.l18] is undefined" as soon as I change it to (l18) (which has to be!) and l18 alone doesn't work already :(. AS a matter of fact the line `var l18 = "آبادا"` you used is not really needed because `(l18)` is already one of the company names (one of StockCodes' row keys). The problem stands with the parentheses even if you redeclare `(l18)` using another 'var' or 'const' and pushes a similar error! – mohsen Jul 31 '23 at 09:37
  • @moshsen, please just provide in your question a piece of code that can be run, that initialises the input as it would be in your case, so that we actually know what input you are currently referring to without ambiguity. – trincot Jul 31 '23 at 09:43
  • As I mentioned first in the question body, the website is a live platform and i cannot provide you the code in Stackoveflow.com. The strings are provided in that very website: https://old.tsetmc.com/Loader.aspx?ParTree=15131F – mohsen Jul 31 '23 at 10:22
  • I cannot open that website (it doesn't respond to a ping for me). But anyhow, a question should be self-contained. – trincot Jul 31 '23 at 10:26
  • First you're commenting under an answer which is not relevant to our discussions though I'm thankful for your cooperation. Second It makes no sense voting negative when you have no access. Third, the question is answered very well and the problem is we have found the new issue: parentheses in strings! Imagine how can I raise a new question in this kinda situation and make a new newspaper!? Forth, some other friend would have reached the webpage and solve the issue. Fifth, have I left anything unanswered? – mohsen Jul 31 '23 at 10:46