天天看點

一個ABAP程式,能夠批量下載下傳有道雲筆記裡包含的圖檔

很多朋友反映源碼不全,我已經把所有源碼上傳到我的

github

上了。

源代碼:

REPORT zactivate.

PARAMETERS: purl TYPE char32 OBLIGATORY LOWER CASE,

           subfold TYPE string OBLIGATORY LOWER CASE.

DATA: lv_content TYPE string,

     lt_node    TYPE zcl_jerry_tool=>tt_sorted_node,

     lv_number  TYPE int4,

     lv_size    TYPE int4,

     lv_total_size TYPE int8,

     lv_folder  TYPE string,

     lv_from    TYPE char32,

     lv_offset  TYPE int4,

     lv_index   TYPE int4 VALUE 1,

     lt_pic     TYPE string_table.

CONSTANTS: picture_name TYPE string value 'clipboard'.

CONSTANTS: folder  TYPE string VALUE 'C:\Users\i042416\Pictures\pic\',

          postfix TYPE string VALUE '>

INITIALIZATION.

 GET PARAMETER ID 'ZNOTE_ID' FIELD lv_from.

 IF lv_from IS NOT INITIAL.

   purl = lv_from.

 ENDIF.

START-OF-SELECTION.

 DATA: lv_url TYPE string.

 lv_url = 'http://note.youdao.com/yws/public/note/' && purl && '?keyfrom=public'.

 SET PARAMETER ID 'ZNOTE_ID' FIELD purl.

 DATA(lv_post_len) = strlen( postfix ).

 lv_content = zcl_crm_cm_tool=>get_text_by_url( lv_url ).

 CALL METHOD zcl_jerry_tool=>parse_json_to_internal_table

   EXPORTING

     iv_json        = lv_content

   IMPORTING

     et_node        = lt_node

     ev_node_number = lv_number.

 ASSERT lv_number = 1.

 READ TABLE lt_node ASSIGNING FIELD-SYMBOL() WITH KEY attribute = 'tl'.</div><div data-lake-id="4d0d5bb9b3155c692d83b6621aef9e74">  ASSERT sy-subrc = 0.</div><div data-lake-id="def043c47170d88a3c1b53d67babaa75">  READ TABLE lt_node ASSIGNING FIELD-SYMBOL(<node>) WITH KEY attribute = 'content'.</div><div data-lake-id="64a310fc27a17ac28602f43eb76ecdac">  ASSERT sy-subrc = 0.</div><div data-lake-id="234b3e2d8ca81c1896d59bf1e2549dfb">  SPLIT <node>-value AT space INTO TABLE DATA(lt_result).</div><div data-lake-id="6a288eb2cfca1be1c420ed7fd0697fa3">  LOOP AT lt_result ASSIGNING FIELD-SYMBOL(<entry>) WHERE table_line CS 'src='.</div><div data-lake-id="adf7b665bbfd203aa660f5f43752cf1f">    lv_number = strlen( <entry> ) - 5. "src="</div><div data-lake-id="9af0ef5aa7971fccdf591857ad676a10">    DATA(url) = <entry>+5(lv_number).</div><div data-lake-id="3d5dcb847f7b64b5cbe7987737ae8c13">    FIND FIRST OCCURRENCE OF `"` IN url match OFFSET lv_offset.</div><div data-lake-id="658780f56b5c7333f31944d16ce04e33">    IF sy-subrc = 0.</div><div data-lake-id="af534d8682d8d4d9955b8c67d0dc8f3f">       url = url+0(lv_offset).</div><div data-lake-id="6229d5439969a6d72a8719fda318bd35">       APPEND url TO lt_pic.</div><div data-lake-id="d7f5d9bd57a5e4d2fb0e41cd47d0f001">    ENDIF.</div><div data-lake-id="a78970aaa95df4bf131c625f9da5aeb0">  ENDLOOP.</div><div data-lake-id="8b172e1aaeeb5c2a4458e25b280cec2c">  WRITE: / 'ok'.</div><div data-lake-id="c5876231309481e82436ded615f272a1">  DATA(lv_total) = lines( lt_pic ).</div><div data-lake-id="d8ec8302af8d6f8a69db77a3d612c2c8">  LOOP AT lt_pic ASSIGNING FIELD-SYMBOL(<pic>).</div><div data-lake-id="be4827e022e83fcb5f79d029d34d8d26">    lv_folder = folder && subfold && '\'.</div><div data-lake-id="21cefdc5b1737d107adfeff161137a2a">    DATA(lv_name) = lv_folder && picture_name && lv_index && '.png'.</div><div data-lake-id="be0e3a9838b64c6929069e529f94ca41">    DATA(lv_text) = 'Downloading file: ' && lv_name.</div><div data-lake-id="b157121bc9dbce099d85344fffacc5d1">    DATA(lv_process) = lv_index * 100.</div><div data-lake-id="697e5ad02794223e30070dd6b6701760">    DATA(lv_percent) = lv_process / lv_total.</div><div data-lake-id="4dac570c44d5cdbe11d893d4f1e24bf6">    CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'</div><div data-lake-id="ba6c5a07737f43bfd75f2573ecae7bbb">      EXPORTING</div><div data-lake-id="d3a25dbd730f08dcbf359a615edfeaff">        percentage = lv_index * 100 / lv_total</div><div data-lake-id="b0b0dd6c39e347f62bbd852b5abbfea8">        text       = lv_text.</div><div data-lake-id="46caf84655b76822b2421fc70b4d76e8">    DATA(binary) = zcl_crm_cm_tool=>get_data_by_url( <pic> ).</div><div data-lake-id="7e6fe7b495411f1e1f3465dca40d1a99">    zcl_crm_cm_tool=>download_locally( iv_local_path = lv_name iv_binary = binary ).</div><div data-lake-id="e76b4ab71525ada0aa924c1a77f647d5">    lv_total_size = lv_total_size + xstrlen( binary ).</div><div data-lake-id="cf85c150d5ca9ad498a27b9ddd4ad0e3">    ADD 1 TO lv_index.</div><div data-lake-id="3a1708f37f15a07478e8d4cc8937c452">  ENDLOOP.</div><div data-lake-id="15300d0aabb0306371e557bcdf504d3a">  WRITE: / 'totally ', lv_total, ' pictures downloaded successfully!' COLOR COL_NEGATIVE.</div><div data-lake-id="58868f672c91adc368cc1f01dcd92867">  DATA: ls_note TYPE crmd_prod_note.</div><div data-lake-id="4176a6208e090373e35d93d48424b2d5">  CALL FUNCTION 'GUID_CREATE'</div><div data-lake-id="7a5d54d866230b3d4d86e67560fdf312">    IMPORTING</div><div data-lake-id="5dbbeb5ebe2dc8010bf4e1e8d48e2855">      ev_guid_16 = ls_note-note_guid.</div><div data-lake-id="e5d1c5b069f08007701e8ca4242fe05e">  ls_note-note_title = <title>-value.</div><div data-lake-id="a99f53409738ad6f485ab706425aa671">  ls_note-pic_size = lv_total.</div><div data-lake-id="71445a8be4be3e372f8da38bc26130c1">  ls_note-download_date = sy-datum.</div><div data-lake-id="695cb372d16baeba11ddd21d0b34a4c9">  ls_note-download_time = sy-timlo.</div><div data-lake-id="7d7dd5b07da1bae931171bb72c5861d1">  ls_note-total_size = lv_total_size / 1024.</div><div data-lake-id="123e3baf7cbc376500b96bea5ae6d30d">  INSERT crmd_prod_note FROM ls_note.</div><div data-lake-id="eb7616dcaef0a1bc0dc3aafa86b47c9d"><br /></div>

繼續閱讀