Jump to content

How to download file using Script?


oemript
 Share

Recommended Posts

  • Developers
2 minutes ago, oemript said:

Do you have any suggestions?

It is common courtesy in our forums to be patient and wait at least 24 hours before bumping a thread.
... and honestly get very bored hearing this broken record without any effort from you at all!

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Referring to following Reference coding, I would like to know on what is the following script language.

_eTTE : function(id, type, name, fn)
function(result)  

For Javascript, function go() {} is defined like that, the above example of function is different from Javascript format.

Does anyone have any suggestions on what script language it is?
Thanks, to everyone very much for any suggestions (^v^)

Reference: view-source:https://www.hkex.com.hk/lhkexw/js/equity.js

//export to excel future
        that.$equity_future.find(".ete").on('click',function(){
            that._exportFutures();
        });

//export futures
    _exportFutures: function() {
        var that=this;
        
        var span=that.$hsirow.find(".interval").attr("data-id");
        var interval=that.$hsirow.find(".hsichart").attr("data-id");
        var ric=that.$equity_future.find("table#equity_future").attr("data-id");
        that.$pageobj.loaddata("getchartdata2", "getchartdata2",
        {
            "span": span,
            "int": interval,
            "ric": ric,
            "token": LabCI.getToken()
        },
        function(result) {
//          console.log(result.data.datalist);
            var html='';
            var flag=that.$hsirow.find(".hsichart .period.selected").html();
            if(flag == '1 D' || flag == '5 D'){
                html+='<tr>'+
                    '<th class="">Time</th>'+
                    '<th class="">Last Traded Price</th>'+
                    '<th class="">Volume</th>'+
                    '<th class="">Open Interest</th>' + 
                '</tr>';
                html+=that._exportFuturesHtml(result.data.datalist,0);
            }else{
                html+='<tr>'+
                    '<th class="">Time</th>'+
                    '<th class="">Settlement Price</th>'+
                    '<th class="">Volume</th>'+
                    '<th class="">Open Interest</th>' + 
                '</tr>';
                html+=that._exportFuturesHtml(result.data.datalist,1);
            }
            
            that.$equity_future.find("#equity_future_export").html(html);
            
            //export
            that._eTTE('equity_future_export','xlsx',''+that.product+'_Futures');
         //  (1)'equity_future_export', (2)'xlsx',(3)''+that.product+'_Futures'); 
         //  there is only 3 parameters instead of 4, would it be correct?
        },
        0,
        {
            datatype: "jsonp"
        });
    },
    _s2ab : function(s){
        if(typeof ArrayBuffer !== 'undefined') {
            var buf = new ArrayBuffer(s.length);
            var view = new Uint8Array(buf);
            for (var i=0; i!=s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
            return buf;
        }else{
            var buf = new Array(s.length);
            for (var i=0; i!=s.length; ++i) buf[i] = s.charCodeAt(i) & 0xFF;
            return buf;
        }
    },
_eTTE : function(id, type, name, fn){
        // id = equity_future_export
        // type = xlsx
        // name = where is "'+that.product+'_Futures" defined? There is no _Futures function here.
        // fn = where is "fn" defined? there is only 3 parameter when calling eTTE function? so no fn?
    	var that=this;
        var wb = XLSX.utils.table_to_book(document.getElementById(id), {sheet:"Sheet JS"});
        // what is wb as returned result?
        var wbout = XLSX.write(wb, {bookType:type, bookSST:true, type: 'binary'});
        // what is wbout as returned result?
        var fname = fn || name + '.' + type;
        // what is fname as returned result? fn or ???.xlsx
        try {
            saveAs(new Blob([that._s2ab(wbout)],{type:"application/octet-stream"}), fname);
        } catch(e) { if(typeof console != 'undefined') console.log(e, wbout); }
        return wbout;
    },
Edited by oemript
Link to comment
Share on other sites

  • Developers
28 minutes ago, oemript said:

Does anyone have any suggestions on what script language it is?

You seriously think we can answer that after posting this snippet?
... and yes... I do have my arrows aimed at you and it will not take much longer before this thread is closed.

Jos 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I don't post only this snippet, the whole scripting is already shown on #9.

I re-post the whole coding back to #22 for more description.

I need to understand line by line first, in order to learn the requirement to download the file.

Do you have any suggestions?

I sincerely want to solve this problem, and hope someone give me a warm hand
Thanks, to everyone very much for any suggestions (^v^)

 

 

 

Edited by oemript
Link to comment
Share on other sites

1 hour ago, oemript said:

Thanks, to everyone very much for any suggestions

By any chance, did you try automation using the _IE* functions, to select in the page the object whose id is "ete" and to click on it ?
All this javascript stuff is a pretty nice maze ...

Link to comment
Share on other sites

22 minutes ago, mikell said:

By any chance, did you try automation using the _IE* functions, to select in the page the object whose id is "ete" and to click on it ?
All this javascript stuff is a pretty nice maze ...

view-source:https://www.hkex.com.hk/lhkexw/js/equity.js

Based on "export to excel future", the id "ete" would redirect to _exportFutures() as shown below, that is what I find, would it be correct?

The next step is to digest line by line to understand the download process, and the highlight area is what I don't understand on what is doing during the download process.

Furthermore, the structure of defining function seems not matching following Javascript structure

Different Structure : _eTTE : function(id, type, name, fn)
Different Structure : function(result)  

Javascript Structure : function go() {} is defined like that, the above example of function is different from Javascript format.

The first question is to know on whether following script is Javascript or not before understanding each line by line.

Do you have any suggestions?
Thanks, to everyone very much for any suggestions (^v^)

 

//export to excel future
        that.$equity_future.find(".ete").on('click',function(){
            that._exportFutures();
        });

//export futures
    _exportFutures: function() {
        var that=this;
        
        var span=that.$hsirow.find(".interval").attr("data-id");
        var interval=that.$hsirow.find(".hsichart").attr("data-id");
        var ric=that.$equity_future.find("table#equity_future").attr("data-id");
        that.$pageobj.loaddata("getchartdata2", "getchartdata2",
        {
            "span": span,
            "int": interval,
            "ric": ric,
            "token": LabCI.getToken()
        },
        function(result) {
//          console.log(result.data.datalist);
            var html='';
            var flag=that.$hsirow.find(".hsichart .period.selected").html();
            if(flag == '1 D' || flag == '5 D'){
                html+='<tr>'+
                    '<th class="">Time</th>'+
                    '<th class="">Last Traded Price</th>'+
                    '<th class="">Volume</th>'+
                    '<th class="">Open Interest</th>' + 
                '</tr>';
                html+=that._exportFuturesHtml(result.data.datalist,0);
            }else{
                html+='<tr>'+
                    '<th class="">Time</th>'+
                    '<th class="">Settlement Price</th>'+
                    '<th class="">Volume</th>'+
                    '<th class="">Open Interest</th>' + 
                '</tr>';
                html+=that._exportFuturesHtml(result.data.datalist,1);
            }
            
            that.$equity_future.find("#equity_future_export").html(html);
            
            //export
            that._eTTE('equity_future_export','xlsx',''+that.product+'_Futures');
         //  (1)'equity_future_export', (2)'xlsx',(3)''+that.product+'_Futures'); 
         //  there is only 3 parameters instead of 4, would it be correct?
        },
        0,
        {
            datatype: "jsonp"
        });
    },
    _s2ab : function(s){
        if(typeof ArrayBuffer !== 'undefined') {
            var buf = new ArrayBuffer(s.length);
            var view = new Uint8Array(buf);
            for (var i=0; i!=s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
            return buf;
        }else{
            var buf = new Array(s.length);
            for (var i=0; i!=s.length; ++i) buf[i] = s.charCodeAt(i) & 0xFF;
            return buf;
        }
    },
_eTTE : function(id, type, name, fn){
        // id = equity_future_export
        // type = xlsx
        // name = where is "'+that.product+'_Futures" defined? There is no _Futures function here.
        // fn = where is "fn" defined? there is only 3 parameter when calling eTTE function? so no fn?
    	var that=this;
        var wb = XLSX.utils.table_to_book(document.getElementById(id), {sheet:"Sheet JS"});
        // what is wb as returned result?
        var wbout = XLSX.write(wb, {bookType:type, bookSST:true, type: 'binary'});
        // what is wbout as returned result?
        var fname = fn || name + '.' + type;
        // what is fname as returned result? fn or ???.xlsx
        try {
            saveAs(new Blob([that._s2ab(wbout)],{type:"application/octet-stream"}), fname);
        } catch(e) { if(typeof console != 'undefined') console.log(e, wbout); }
        return wbout;
    },
Link to comment
Share on other sites

  • Moderators

oemript,

This is an AutoIt forum. If you have a question about AutoIt code then please open a new thread, but asking us to translate this other code into AutoIt (which is presumably what you want, although as you are far from clear about anything at all I am not sure) is just not going to happen. Thread locked.

M23

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

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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