At my wit's end

NOTE: If you need to post code (e.g. LoliCode or C#), please wrap it with triple backquotes like you see below

"result": 0,
	"total": 15,
	"items": [
		{
			"fileName": "1.rar",
			"fileid": 23,
		},
		{
			"fileName": "2.rar",
			"fileid": 24,
		},
		{
			"fileName": "3.rar",
			"fileid": 25,
		},
		{
			"fileName": "4.rar",
			"fileid": 26,
		}
		 ]

I have that data parsed. I want it to show like:
1.rar[23], 2.rar[24], 3.rar[25], 4.rar[26]

Really need your help. Thank you very much.

Parse the fileName fields to a list using json parsing (recursive) (e.g. call it filenames)
Parse the fileid fields to a list using json parsing (recursive) (e.g. call it fileids)
Use the Constant List block to make an empty list (e.g. call it files)
Now you have 2 lists of the same length and you can loop and fill the new list like this

for (int i = 0; i < filenames.Count; i++)
{
  files.Add($"{filenames[i]}[{fileids[i]}]");
}

If you want I can edit the Zip block to define a custom format for the output list, so you dont have to write the C# loop manually but you can easily use a block instead. If you want me to do that, please open an issue on github (it’s not hard to implement so I can do it tomorrow).

NOTE: Instead of using json parsing you can also use LR, it works too.

2 Likes

Man, you don’t owe us anything. You’re already doing God’s work. Yet you reply faster than any paid customer rep. I’m very grateful for your existence.

1 Like

No I said that cause I legit think it’s a good feature to add :slight_smile:
I will create the issue myself, no worries. Have a good one.

2 Likes

I’m sorry but I don’t know how to open an issue on Github. Is there any way to donate to you though? I’m making a “program” for the company I’m working in that will save us a lot of time and could possibly promote me. I want to donate to your hard work as a sign of appreciation please.

Just a quick update:
After parsing them through JSON, I’m getting this:

Parse (QueryJsonTokenRecursive)
Parsed 0 values:

I guess I’m making progress. Instead of JSON Parsing, I ended up with LR and it’s producing the results I need.

I was also able to add them to Constant Lists. I’m just confused at the last part.

for (int i = 0; i < filenames.Count; i++)
{
  files.Add($"{filenames[i]}[{fileids[i]}]");
}

In what type of block do I put this?

Click on “LoliCode” (below Stacker, in the menu) and paste the snippet after the constant list block (in a new line below it).
No need to donate, but if you want to buy me a coffee you can find my crypto wallets on the github page ^^ GitHub - openbullet/OpenBullet2: OpenBullet reinvented

I guess it’s working. But it doesn’t seem to show me the filename[fileid] thing. It just shows


Set constant value

BOT ENDED AFTER 2683 ms WITH STATUS: SUCCESS

This is what I have so far:

BLOCK:Parse
  input = @data.SOURCE
  leftDelim = "name\": \""
  rightDelim = "\""
  jToken = $"items.[*].name"
  RECURSIVE
  MODE:Json
  => VAR @filenames
ENDBLOCK

BLOCK:Parse
  input = @data.SOURCE
  leftDelim = "id\": "
  rightDelim = ","
  jToken = $"items.[*].id"
  RECURSIVE
  MODE:Json
  => VAR @fileids
ENDBLOCK

BLOCK:ConstantList
  value = []
  => VAR @files
ENDBLOCK

for (int i = 0; i < filenames.Count; i++)
{
  files.Add($"{filenames[i]}[{fileids[i]}]");
}

I was hoping it would print filename1[fileid1],filename2[fileid2],…

Would you happen to have a Monero wallet? I just exchanged all of my remaining ETH to Monero.

It doesn’t print them but you can see them if you click on the blue button that says “show variables”. Then you will see that there is a variable called files with everything you need inside it. If you really want to log it to the debugger log you can add this after the for loop

LOG files.AsString()

Yeah sure, but again, don’t feel compelled to donate, I try to help everybody on here.

446VrztKcwjiBGJhky7jUhXs1249Uq1569Aztha3j7QNAqqyqdqjLzoC9MVsSt26ywA97RpVsifejedbtcfQWK5X74SPCxD

That worked beautifully.

One last thing I’m hoping to accomplish is to use the Compute & Round function. I was able to use it on the previous Openbullet but not here.

I’m dealing with a filesize problem. Since the raw data I get is by bytes and I need to make it to MB. The way I did this on previous Openbullet was

(<parsedVariable>)*0.0001

and then use the Round Function. I can’t seem to do it in Openbullet2.

If I do

filesize*0.0001

I get

CompilationErrorException
[IDLE] (52,44): error CS1929: 'double' does not contain a definition for 'AsString' and the best extension method overload 'BoolExtensions.AsString(bool)' requires a receiver of type 'bool'

Have you tried the block called “Readable Size”?
It will take the number of bytes and convert it to a readable size, for example 1000000 becomes 1 MB (you can tell it how many decimal places you want).

Otherwise please post some code to replicate your issue because I don’t seem to understand very well. The compute block should work the same as OB1, you need dark green background to use interpolated mode

As far as I understand, you were most likely using the dark blue background, which is only for variables (you shouldn’t write anything else in it, just the name of the variable).

BLOCK:Parse
  input = @data.SOURCE
  leftDelim = "name\": \""
  rightDelim = "\""
  jToken = $"items.[*].name"
  RECURSIVE
  MODE:Json
  => VAR @filenames
ENDBLOCK

BLOCK:Parse
  input = @data.SOURCE
  leftDelim = "size\": "
  rightDelim = ","
  jToken = $"items.[*].size"
  RECURSIVE
  MODE:Json
  => VAR @filesize
ENDBLOCK

BLOCK:Compute
  input = $"<filesize> * 0.000001"
  => VAR @filesizes
ENDBLOCK

BLOCK:ConstantList
  value = []
  => VAR @files
ENDBLOCK

for (int i = 0; i < filenames.Count; i++)
{
  files.Add($"{filenames[i]}[{filesizes[i]}MB]");
}

This is what I have. When I try to run this, I’m getting this error.

[IDLE] (62,33): error CS0021: Cannot apply indexing with [] to an expression of type 'float'

Oh yeah I understand now, you’re parsing a list of strings (recursively) but you’re trying to compute all of them at the same time.
This will not work. You have to compute for each single one. I will give you a snippet you can use (replace the compute block with this).

BLOCK:ConstantList
  value = []
  => VAR @sizes
ENDBLOCK

for (int i = 0; i < filesize.Count; i++)
{
BLOCK:Compute
  input = $"<filesize[i]> * 0.000001"
  => VAR @size
ENDBLOCK

  sizes.Add(size);
}

It should work, let me know if you have any more issues.
By the way, version 0.1.18 is up with the custom formats in the zip block, so now you don’t have to use the old snippet that I gave you a few posts ago (empty list + for loop), you can just do this

BLOCK:ZipLists
  list1 = @filenames
  list2 = @fileids
  format = "[0][[1]]"
  => VAR @files
ENDBLOCK

Cheers

1 Like
BLOCK:Parse
  input = @data.SOURCE
  leftDelim = "name\": \""
  rightDelim = "\""
  jToken = $"items.[*].name"
  RECURSIVE
  MODE:Json
  => VAR @filenames
ENDBLOCK

BLOCK:Parse
  input = @data.SOURCE
  leftDelim = "size\": "
  rightDelim = ","
  jToken = $"items.[*].size"
  RECURSIVE
  MODE:Json
  => VAR @filesize
ENDBLOCK

BLOCK:ConstantList
  value = []
  => VAR @files
ENDBLOCK

BLOCK:ConstantList
  value = []
  => VAR @sizes
ENDBLOCK

for (int i = 0; i < filesize.Count; i++)
{
BLOCK:Compute
  input = $"<filesize[i]> * 0.000001"
  => VAR @size
ENDBLOCK

  sizes.Add(size);
}

for (int i = 0; i < filenames.Count; i++)
{
  files.Add($"{filenames[i]}[{filesizes[i]}MB]");
}

Ah yeah my bad ^^ was missing a cast. Please change the following line

sizes.Add(size);

to this

sizes.Add(size.AsString());