Jump to content

Recommended Posts

Posted (edited)

Today I want to present my current project.

This is UDF for   crowdin.net website API

In fact, not yet finished but functional.

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7
#Tidy_Parameters=/sort_funcs /reel

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>


_Crowdin_Example_1()

Func _Crowdin_Example_1()
    Local $sACCOUNT_API_KEY = '...'
    Local $sPROJECT_API_KEY = '...'
    Local $sPROJECT_identifier = '...'
    Local $output = ''


    _Crowdin_Project_Identifier($sPROJECT_identifier)
    _Crowdin_Project_ApiKey($sPROJECT_API_KEY)
    _Crowdin_AccountKey($sACCOUNT_API_KEY)


    $output = _Crowdin_DirectoryCreate('Directory for testing CrowdinAPI')
    MsgBox(0, '_Crowdin_DirectoryCreate', $output)
    Exit

    $output = _Crowdin_GetProjectInfo()
    MsgBox(0, '_Crowdin_GetProjectInfo', $output)

    $output = _Crowdin_GetSupportedLanguages()
    MsgBox(0, '_Crowdin_GetSupportedLanguages', $output)

    $output = _Crowdin_TranslationExport()
    MsgBox(0, '_Crowdin_TranslationExport', $output)

    $output = _Crowdin_TranslationStatus()
    MsgBox(0, '_Crowdin_TranslationStatus', $output)

    $output = _Crowdin_TranslationDownload('all', @ScriptDir & '\Crowdin_test_DownloadTranslations.zip')

    $output = _Crowdin_GetProjects('mLipok')
    MsgBox(0, '_Crowdin_GetProjects', $output)

    $output = _Crowdin_DirectoryCreate('Directory for testing CrowdinAPI')
    MsgBox(0, '_Crowdin_DirectoryCreate', $output)


;~  $output =
;~  MsgBox(0, '', $output)

EndFunc   ;==>_Crowdin_Example_1

#Region CrowdinAPI - Functions

; #FUNCTION# ====================================================================================================================
; Name ..........: _Crowdin_GetProjectInfo
; Description ...: Get Crowdin Project details.
; Syntax ........: _Crowdin_GetProjectInfo()
; Parameters ....:
; Return values .: None
; Author ........: mLipok
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _Crowdin_GetProjectInfo()
    Local $sURL = 'https://api.crowdin.com/api/project/' & _Crowdin_Project_Identifier() & '/info?key=' & _Crowdin_Project_ApiKey()
    ConsoleWrite('! ' & $sURL & @CRLF)
    Local $oXmlHttp = ObjCreate("Microsoft.XMLHTTP")
    $oXmlHttp.Open('POST', $sURL, False)
    $oXmlHttp.Send()
    Local $output = $oXmlHttp.ResponseText
    $oXmlHttp = ''
    Return $output

EndFunc   ;==>_Crowdin_GetProjectInfo

; #FUNCTION# ====================================================================================================================
; Name ..........: _Crowdin_GetSupportedLanguages
; Description ...:
; Syntax ........: _Crowdin_GetSupportedLanguages()
; Parameters ....:
; Return values .: None
; Author ........: mLipok
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _Crowdin_GetSupportedLanguages()
    Local $sURL = 'https://api.crowdin.com/api/supported-languages'
    ConsoleWrite('! ' & $sURL & @CRLF)
    Local $oXmlHttp = ObjCreate("Microsoft.XMLHTTP")
    $oXmlHttp.Open('GET', $sURL, False)
    $oXmlHttp.Send()
    Local $output = $oXmlHttp.ResponseText
    $oXmlHttp = ''
    Return $output

EndFunc   ;==>_Crowdin_GetSupportedLanguages

; #FUNCTION# ====================================================================================================================
; Name ..........: _Crowdin_TranslationExport
; Description ...:
; Syntax ........: _Crowdin_TranslationExport()
; Parameters ....:
; Return values .: None
; Author ........: mLipok
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _Crowdin_TranslationExport()
    Local $sURL = 'https://api.crowdin.com/api/project/' & _Crowdin_Project_Identifier() & '/export?key=' & _Crowdin_Project_ApiKey()
    ConsoleWrite('! ' & $sURL & @CRLF)
    Local $oXmlHttp = ObjCreate("Microsoft.XMLHTTP")
    $oXmlHttp.Open('GET', $sURL, False)
    $oXmlHttp.Send()
    Local $output = $oXmlHttp.ResponseText
    $oXmlHttp = ''
    Return $output

EndFunc   ;==>_Crowdin_TranslationExport


; #FUNCTION# ====================================================================================================================
; Name ..........: _Crowdin_TranslationStatus
; Description ...: Track your Crowdin project translation progress by language. Default response format is XML.
; Syntax ........: _Crowdin_TranslationStatus()
; Parameters ....:
; Return values .: None
; Author ........: mLipok
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........: https://crowdin.com/page/api/status
; Example .......: No
; ===============================================================================================================================
Func _Crowdin_TranslationStatus()
    Local $sURL = 'https://api.crowdin.com/api/project/' & _Crowdin_Project_Identifier() & '/status?key=' & _Crowdin_Project_ApiKey()
    ConsoleWrite('! ' & $sURL & @CRLF)
    Local $oXmlHttp = ObjCreate("Microsoft.XMLHTTP")
    $oXmlHttp.Open('POST', $sURL, False)
    $oXmlHttp.Send()
    Local $output = $oXmlHttp.ResponseText
    $oXmlHttp = ''
    Return $output

EndFunc   ;==>_Crowdin_TranslationExport


; #FUNCTION# ====================================================================================================================
; Name ..........: _Crowdin_TranslationDownload
; Description ...: Download ZIP file with translations. You can choose the language of translation you need or download all of them at once.
; Syntax ........: _Crowdin_TranslationDownload([$sPackage = 'all'[, $sZIP_FileFullPath = '']])
; Parameters ....: $sPackage            - [optional] a string value. Default is 'all'.
;                  $sZIP_FileFullPath   - [optional] a string value. Default is ''.
; Return values .: None
; Author ........: mLipok
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........: https://crowdin.com/page/api/download
; Example .......: No
; ===============================================================================================================================
Func _Crowdin_TranslationDownload($sPackage = 'all', $sZIP_FileFullPath = '')
    ; GET https://api.crowdin.com/api/project/{project-identifier}/download/{package}.zip?key={project-key}
    Local $sURL = 'https://api.crowdin.com/api/project/' & _Crowdin_Project_Identifier() & '/download/' & $sPackage & '.zip?key=' & _Crowdin_Project_ApiKey()
    ConsoleWrite('! ' & $sURL & @CRLF)
    Local $oXmlHttp = ObjCreate("Microsoft.XMLHTTP")
    $oXmlHttp.Open('GET', $sURL, False)
    $oXmlHttp.Send()
    Local $output = $oXmlHttp.ResponseBody
;~  Local $type = $oXmlHttp.ResponseType
;~  MsgBox(0, VarGetType($type) & '='&$type&'=' , VarGetType($output))
;~  MsgBox(0, '', BinaryLen($output))

    If $sZIP_FileFullPath <> '' Then
        Local $hFile = FileOpen($sZIP_FileFullPath, $FO_OVERWRITE + $FO_BINARY)
        FileWrite($hFile, $output)
        FileClose($hFile)
    EndIf

    $oXmlHttp = ''
    Return $output

EndFunc   ;==>_Crowdin_TranslationDownload

; #FUNCTION# ====================================================================================================================
; Name ..........: _Crowdin_GetProjects
; Description ...: Get Crowdin Project details.
; Syntax ........: _Crowdin_GetProjects($sLoginName)
; Parameters ....: $sLoginName              - A string value. Your Crowdin Account login name.
; Return values .: None
; Author ........: mLipok
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........: https://crowdin.com/page/api/get-projects
; Example .......: No
; ===============================================================================================================================
Func _Crowdin_GetProjects($sLoginName)
    ; https://api.crowdin.com/api/account/get-projects?account-key={account-key}
    Local $sURL = 'https://api.crowdin.com/api/account/get-projects?account-key=' & _Crowdin_AccountKey() & '&login=' & $sLoginName
    ConsoleWrite('! ' & $sURL & @CRLF)
    Local $oXmlHttp = ObjCreate("Microsoft.XMLHTTP")
    $oXmlHttp.Open('POST', $sURL, False)
    $oXmlHttp.Send('')
    Local $output = $oXmlHttp.ResponseText
    $oXmlHttp = ''
    Return $output
EndFunc   ;==>_Crowdin_GetProjects


; #FUNCTION# ====================================================================================================================
; Name ..........: _Crowdin_DirectoryCreate
; Description ...: Add directory to Crowdin project.
; Syntax ........: _Crowdin_DirectoryCreate($sDirectoryName)
; Parameters ....: $sDirectoryName      - A string value.
; Return values .: None
; Author ........: Your mLipok
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........: https://crowdin.com/page/api/add-directory
; Example .......: No
; ===============================================================================================================================
Func _Crowdin_DirectoryCreate($sDirectoryName)
    ; https://api.crowdin.com/api/project/{project-identifier}/add-directory?key={project-key}
    Local $sURL = 'https://api.crowdin.com/api/project/' & _Crowdin_Project_Identifier() & '/add-directory?key=' & _Crowdin_Project_ApiKey() & '&name=' & $sDirectoryName
    ConsoleWrite('! ' & $sURL & @CRLF)
    Local $oXmlHttp = ObjCreate("Microsoft.XMLHTTP")
    $oXmlHttp.Open('POST', $sURL, False)
    $oXmlHttp.Send('')
    Local $output = $oXmlHttp.ResponseText
    $oXmlHttp = ''
    Return $output
EndFunc   ;==>_Crowdin_GetProjects

#EndRegion CrowdinAPI - Functions

#Region CrowdinAPI - SETUP
; #FUNCTION# ====================================================================================================================
; Name ..........: _Crowdin_Project_ApiKey
; Description ...:
; Syntax ........: _Crowdin_Project_ApiKey([$vApiKey = Default])
; Parameters ....: $vApiKey             - [optional] a variant value. Default is Default.
; Return values .: None
; Author ........: mLipok
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........: https://crowdin.com/page/api/authentication
; Example .......: No
; ===============================================================================================================================
Func _Crowdin_Project_ApiKey($vApiKey = Default)
    Local Static $sPROJECT_API_KEY = ''
    If $vApiKey = Default Then
        Return $sPROJECT_API_KEY
    Else
        $sPROJECT_API_KEY = $vApiKey
        Return $sPROJECT_API_KEY
    EndIf

EndFunc   ;==>_Crowdin_Project_ApiKey

; #FUNCTION# ====================================================================================================================
; Name ..........: _Crowdin_Project_Identifier
; Description ...:
; Syntax ........: _Crowdin_Project_Identifier([$vIdentifier = Default])
; Parameters ....: $vIdentifier         - [optional] a variant value. Default is Default.
; Return values .: None
; Author ........: mLipok
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........: https://crowdin.com/page/api/authentication
; Example .......: No
; ===============================================================================================================================
Func _Crowdin_Project_Identifier($vIdentifier = Default)
    Local Static $sPROJECT_identifier = ''
    If $vIdentifier = Default Then
        Return $sPROJECT_identifier
    Else
        $sPROJECT_identifier = $vIdentifier
        Return $sPROJECT_identifier
    EndIf

EndFunc   ;==>_Crowdin_Project_Identifier

; #FUNCTION# ====================================================================================================================
; Name ..........: _Crowdin_AccountKey
; Description ...:
; Syntax ........: _Crowdin_AccountKey([$vAccountKey = Default])
; Parameters ....: $vAccountKey         - [optional] A variant value. Default is Default.
; Return values .: None
; Author ........: mLipok
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........: https://crowdin.com/settings#user-profile-api-key
; Example .......: No
; ===============================================================================================================================
Func _Crowdin_AccountKey($vAccountKey = Default)
    Local Static $sACCOUNT_API_KEY = ''
    If $vAccountKey = Default Then
        Return $sACCOUNT_API_KEY
    Else
        $sACCOUNT_API_KEY = $vAccountKey
        Return $sACCOUNT_API_KEY
    EndIf
EndFunc   ;==>_Crowdin_AccountKey
#EndRegion CrowdinAPI - SETUP

CrowdinAPI_v0.1.au3

 

have fun, 

mLipok

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

  • 10 months later...
Posted (edited)

I'm trying to finish this UDF.

I have problem with this function:

https://crowdin.com/page/api/add-file

Here is my current implementation:

; #FUNCTION# ====================================================================================================================
; Name ..........: _Crowdin_FileAdd
; Description ...: Add new file to Crowdin project that should be translated.
; Syntax ........: _Crowdin_FileAdd($sFileName[, $sTyp = 'auto'])
; Parameters ....: $sFileName           - a string value.
;                  $sTyp                - [optional] a string value. Default is 'auto'.
; Return values .: Response in XML format. For more info go to the followed link
; Author ........: mLipok
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........: https://crowdin.com/page/api/add-file
; Example .......: No
; ===============================================================================================================================
Func _Crowdin_FileAdd($sFileName, $sTyp = 'auto')
;~  Local $sURL = 'https://api.crowdin.com/api/project/' & _Crowdin_Project_Identifier() & '/add-file?key=' & _Crowdin_Project_ApiKey() & '&type=' & $sTyp & '&files[' & $sFileName & ']>"' & @ScriptDir & '\' & $sFileName & ''
;~  Local $sURL = 'https://api.crowdin.com/api/project/' & _Crowdin_Project_Identifier() & '/add-file?key=' & _Crowdin_Project_ApiKey() & '&type=' & $sTyp & '&files[' & @ScriptDir & '\' & $sFileName & ']=' & '%original_file_name%'
;~  Local $sURL = 'https://api.crowdin.com/api/project/' & _Crowdin_Project_Identifier() & '/add-file?key=' & _Crowdin_Project_ApiKey() & '&type=' & $sTyp & '&files[' & $sFileName & ']=' & $sFileName
;~  Local $sURL = 'https://api.crowdin.com/api/project/' & _Crowdin_Project_Identifier() & '/add-file?key=' & _Crowdin_Project_ApiKey() & '&type=' & $sTyp & '&files[' & $sFileName & ']'
;~  Local $sURL = 'https://api.crowdin.com/api/project/' & _Crowdin_Project_Identifier() & '/add-file?key=' & _Crowdin_Project_ApiKey() & '&files[' & $sFileName & ']'
    Local $sURL = 'https://api.crowdin.com/api/project/' & _Crowdin_Project_Identifier() & '/add-file?key=' & _Crowdin_Project_ApiKey() & '&type=' & $sTyp
    ConsoleWrite('! ' & $sURL & @CRLF)
    Local $sOutput = __Crowdin_POST($sURL, 'files[' & 'Plik1' & ']=@' & $sFileName)
    Return $sOutput

EndFunc   ;==>_Crowdin_FileAdd

 

For example I use it like in this following example :

$sOutput = _Crowdin_FileAdd(@ScriptDir & '\example.csv', 'csv')
    ClipPut($sOutput)
    MsgBox(0, '_Crowdin_FileAdd', $sOutput)

 And this function:

Func __Crowdin_POST($sURL, $sSendString = '')
    Local $oXmlHttp = ObjCreate($g__sClassName)
    ConsoleWrite("> $sURL: " & $sURL & @CRLF)
    ConsoleWrite("> $sSendString:" & $sSendString & @CRLF)
    $oXmlHttp.Open('POST', $sURL, False)
    $oXmlHttp.Send($sSendString)
    Local $sOutput = $oXmlHttp.ResponseText

    ; Clean Up
    $oXmlHttp = ''
    Return $sOutput

EndFunc   ;==>__Crowdin_POST

generates this Console Output:

Quote

$sURL: https://api.crowdin.com/api/project/testingapi/add-file?key=2dc8c1f4........6d629&type=csv
$sSendString:files[Plik1]=@Z:\Crowdin_API\example.csv

 

but I'm getting this following message from the API:

<?xml version="1.0" encoding="ISO-8859-1"?>
<error>
  <code>4</code>
  <message>No files specified in request</message>
</error>

Can somebody help to show me what I'm doing wrong ?

 


EDIT:  Basicly:
I have problem with implementing this:

https://crowdin.com/page/api/add-file

Name Value Description
filesrequired array Files array that should be added to Crowdin project. Array keys should contain file names with path in Crowdin project. 
Note! 20 files max are allowed to upload per one time file transfer.
Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Posted (edited)

Thanks @trancexx

Some searching and I found this:

 

http://lists.alioth.debian.org/pipermail/pkg-mozext-commits/2014-July/005861.html
https://github.com/EFForg/trackerlab/blob/master/buildtools/localeTools.py

def postFiles(files, url):
  boundary = '----------ThIs_Is_tHe_bouNdaRY_$'
  body = ''
  for file, data in files:
    body += '--%s\r\n' % boundary
    body += 'Content-Disposition: form-data; name="files[%s]"; filename="%s"\r\n' % (file, file)
    body += 'Content-Type: application/octet-stream\r\n'
    body += 'Content-Transfer-Encoding: binary\r\n'
    body += '\r\n' + data + '\r\n'
  body += '--%s--\r\n' % boundary

  body = body.encode('utf-8')
  request = urllib2.Request(url, StringIO(body))
  request.add_header('Content-Type', 'multipart/form-data; boundary=%s' % boundary)
  request.add_header('Content-Length', len(body))
  result = urllib2.urlopen(request).read()
  if result.find('<success') < 0:
    raise Exception('Server indicated that the operation was not successful\n' + result)

I think this is it, or something similar ....

So its time to practice - back to work on it.
See you later.

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Posted (edited)
3 hours ago, mLipok said:

body += '--%s\r\n' % boundary    
body += 'Content-Disposition: form-data; name="files[%s]"; filename="%s"\r\n' % (file, file)

I'm not familiar to python, so maybe somebody can confirm:  Whethter this %s is some kind of StringFormat() ?

 

EDIT:
now I'm looking for "application/octet-stream" , just here 

 

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Posted

I found the answer.

Thanks again @trancexx


Soon I'll update the entire UDF.

The following snippet showing preliminary solution to the problem.

Func __Crowdin_POST($sURL, $sSendString = '', $sFile = Default, $sCrowdinFileWithPath = Default, $sCrowdinName = Default)
    Local $oXmlHttp = ObjCreate($g__sClassName)
    $oXmlHttp.Open('POST', $sURL, False)

    If Not ($sFile = Default) And FileExists($sFile) Then
        Local $sBoundary = '----------ThIs_Is_tHe_bouNdaRY_$'
        Local $sBody = ''
        $sBody &= '--' & $sBoundary & @CRLF
        $sBody &= StringFormat('Content-Disposition: form-data; name="files[%s]"; filename="%s"', $sCrowdinFileWithPath, $sCrowdinName) & @CRLF
        $sBody &= 'Content-Type: application/octet-stream' & @CRLF
        $sBody &= 'Content-Transfer-Encoding: binary' & @CRLF
        Local $dBinary = FileRead($sFile)
        $sBody &= @CRLF & $dBinary & @CRLF
        $sBody &= '--' & $sBoundary & '--' & @CRLF

        $oXmlHttp.SetRequestHeader('Content-Type', 'multipart/form-data; boundary=' & $sBoundary)
        $oXmlHttp.SetRequestHeader('Content-Length', StringLen($sBody))
        $oXmlHttp.Send($sBody)
    Else
        $oXmlHttp.Send($sSendString)
    EndIf

    Local $sOutput = $oXmlHttp.ResponseText

    #cs
        Local $aOutput[$__g_iOutput_ENUMCOUNTER]
        $aOutput[$__g_iOutput_Status] = String($oXmlHttp.Status)
        $aOutput[$__g_iOutput_StatusText] = $oXmlHttp.StatusText
        $aOutput[$__g_iOutput_AllResponseHeaders] = $oXmlHttp.GetAllResponseHeaders()
        $aOutput[$__g_iOutput_ResponseText] = $oXmlHttp.ResponseText
        _ArrayDisplay($aOutput)

    #ce

    ; Clean Up
    $oXmlHttp = ''
    Return $sOutput

EndFunc    ;==>__Crowdin_POST

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

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
×
×
  • Create New...