Jump to content

Recommended Posts

Posted

Hi there 

when I query this API the result is a single line of N characters.

my goal is to get a file with several lines and not only one,

can you help me to cut this line according to a particular condition (like a character of end of line for example) ? 

my actual code 

 

#include <GUIConstants.au3>
#include <file.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>

Local $test = 'https://min-api.cryptocompare.com/data/all/coinlist'
Local $1 = InetRead($test)
Local $iBytesRead = @extended
Local $Tempfile1 = "c:\temp\tempfile.csv"

Local $iFileExists = FileExists($Tempfile1)

If $iFileExists Then

    FileDelete($Tempfile1)

EndIf

FileWrite($Tempfile1, $1)

Local $tt = 0
Local $g = 0


start()

Func start()
    $g = $g + 1
    $count = _FileCountLines($Tempfile1)
    $File = FileOpen($Tempfile1, 0)
    While 1
        $line = FileReadLine($File)
        If @error = -1 Then ExitLoop
        s
        MsgBox(64, 'number of lines', $count, 0)
        MsgBox(64, 'line content', $line, 0)

        $tt = $tt + 1


    WEnd
EndFunc   ;==>start


Exit

 

Posted (edited)

Ok

my limits are now reached for the loop to code 

how to write the code to re write each splitted line in a new line with @CRLF like

Edited by Reekod
Posted

Unfortunaltly there is no logicial splitter is this long result line. 

very hard to split it to get an easy way to build a final coin list 

have a lot of work may be regex can help me to to split it to get  

"Data":{"  to start each line 

 

 

 

 

 

 

Posted

 

These might help

 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted

So great

but very too high level for my skill :(

gonna still try with my old fashion style and play with strings to split with my DATA on start of each line 

regards

 

 

 

Posted (edited)

@Danp2

i dont find anything or help with  Json_Dump function , do you think this func can help me ? 

i need to know how to

- list all my json entry ( like 42 )

- Get specific value of 42 entry like Name

 

    "Data": {
        "42": {
            "Id": "4321",
            "Url": "\/coins\/42\/overview",
            "ImageUrl": "\/media\/12318415\/42.png",
            "Name": "42",
            "Symbol": "42",
            "CoinName": "42 Coin",
            "FullName": "42 Coin (42)",
            "Algorithm": "Scrypt",
            "ProofType": "PoW\/PoS",
            "FullyPremined": "0",
            "TotalCoinSupply": "42",
            "PreMinedValue": "N\/A",
            "TotalCoinsFreeFloat": "N\/A",
            "SortOrder": "34",
            "Sponsored": false,
            "IsTrading": true
        },

Actually i write my file like this

#include <GUIConstants.au3>
#include <file.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>
#include "json.au3"
#include "BinaryCall.au3"

Local $Tempfile1 = "c:\temp\tempfile.csv"
FileDelete($Tempfile1)
Local $Json = BinaryToString(InetRead("https://min-api.cryptocompare.com/data/all/coinlist"), 4)
Local $Obj = Json_Decode($Json)
Local $result = Json_Encode($Obj, $JSON_PRETTY_PRINT)

start()

Func start()

    FileWrite($Tempfile1, $result)

EndFunc   ;==>start

Exit

 

Edited by Reekod
Posted

I know you have moved on to another UDF but the StringSplit() function is really dynamic in how it can be used and isn't limited to splitting by a single character.

 

Example:

 

StringSplit($YourString, "TotalCoinSupply", $STR_ENTIRESPLIT)

 

It's mainly just finding something to split it into useful data for you. 

 

Posted

Here are a couple of my guesses of what you actually need or want.

#include <Array.au3>

Local $sData = BinaryToString(InetRead('https://min-api.cryptocompare.com/data/all/coinlist'))

; Replace the colon before '{"Id"' with @CRLF.
ConsoleWrite(StringRegExpReplace($sData, ':({"Id")', @CRLF & "\1") & @CRLF) 

;or

; Make a 1D array out of all characters between double quotes.
Local $aArray = StringRegExp($sData, '(?i)"([^"]*)"', 3)
_ArrayDisplay($aArray)

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...