Reekod Posted March 12, 2018 Share Posted March 12, 2018 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 expandcollapse popup#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 Link to comment Share on other sites More sharing options...
xCROv Posted March 12, 2018 Share Posted March 12, 2018 StringSplit ( "string", "delimiters" [, flag = 0] ) ? Link to comment Share on other sites More sharing options...
Reekod Posted March 12, 2018 Author Share Posted March 12, 2018 (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 March 12, 2018 by Reekod Link to comment Share on other sites More sharing options...
Zedna Posted March 12, 2018 Share Posted March 12, 2018 Example in helpfile: https://www.autoitscript.com/autoit3/docs/functions/StringSplit.htm Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Reekod Posted March 12, 2018 Author Share Posted March 12, 2018 oh great i didnt think about $aDays[0] it's wonderfull thx a lot Link to comment Share on other sites More sharing options...
Reekod Posted March 12, 2018 Author Share Posted March 12, 2018 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 Link to comment Share on other sites More sharing options...
BrewManNH Posted March 12, 2018 Share Posted March 12, 2018 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 GudeHow 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 Link to comment Share on other sites More sharing options...
Danp2 Posted March 12, 2018 Share Posted March 12, 2018 Looks like it returns data in JSON format. There's a UDF for dealing with that. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Reekod Posted March 12, 2018 Author Share Posted March 12, 2018 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 Link to comment Share on other sites More sharing options...
Reekod Posted March 12, 2018 Author Share Posted March 12, 2018 Finally not so hard Thank you so much ! #include "json.au3" #include "BinaryCall.au3" Local $Json = BinaryToString(InetRead("https://min-api.cryptocompare.com/data/all/coinlist"), 4) Local $Obj = Json_Decode($Json) ConsoleWrite(Json_Encode($Obj, $JSON_PRETTY_PRINT)) Link to comment Share on other sites More sharing options...
Danp2 Posted March 12, 2018 Share Posted March 12, 2018 @Reekod Take a look at the Json_Dump function. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Reekod Posted March 12, 2018 Author Share Posted March 12, 2018 i will soon ! thx mate Link to comment Share on other sites More sharing options...
Reekod Posted March 12, 2018 Author Share Posted March 12, 2018 (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 March 12, 2018 by Reekod Link to comment Share on other sites More sharing options...
Danp2 Posted March 12, 2018 Share Posted March 12, 2018 Json_Dump with list all the keys and their values to the console. These keys can be used to retrieve specific Json nodes. Try this -- #Include "Json.au3" Local $Json = BinaryToString(InetRead("https://min-api.cryptocompare.com/data/all/coinlist"), 4) Json_Dump($Json) Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Reekod Posted March 12, 2018 Author Share Posted March 12, 2018 amazing ! Link to comment Share on other sites More sharing options...
xCROv Posted March 12, 2018 Share Posted March 12, 2018 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. Link to comment Share on other sites More sharing options...
Malkey Posted March 13, 2018 Share Posted March 13, 2018 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) Link to comment Share on other sites More sharing options...
Reekod Posted March 13, 2018 Author Share Posted March 13, 2018 @Danp2 @xCROv @Malkey Thank you guys ! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now