REPORT zactivate.
PARAMETERS: purl TYPE char32 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_from TYPE char32,
lv_index TYPE int4 VALUE 1,
lt_pic TYPE string_table.
CONSTANTS: folder TYPE string VALUE 'C:\Users\i042416\Pictures\pic\clipboard',
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="e86e39cdb283ba1544d0b4872c6be3e0"> ASSERT sy-subrc = 0.</div><div data-lake-id="c6a5137fadf696328bd8952bd726e7ff"> READ TABLE lt_node ASSIGNING FIELD-SYMBOL(<node>) WITH KEY attribute = 'content'.</div><div data-lake-id="742b0e720a42559a1e814cc691853b20"> ASSERT sy-subrc = 0.</div><div data-lake-id="4a946af6b19d96fdbc98f654d266e2fa"> SPLIT <node>-value AT space INTO TABLE DATA(lt_result).</div><div data-lake-id="5c8c0126e74328a1510bb6d7a9a114a8"> LOOP AT lt_result ASSIGNING FIELD-SYMBOL(<entry>) WHERE table_line CS 'src='.</div><div data-lake-id="bdf0859bfe70aa1e98cc8d35b8c33417"> lv_number = strlen( <entry> ) - 6.</div><div data-lake-id="f65ed98c1cd1fba9ed0d68a4ae7dcd41"> DATA(url) = <entry>+5(lv_number).</div><div data-lake-id="53730d4fd01a7dd14633703dcdb0f049"> REPLACE ALL OCCURRENCES OF `"` IN url WITH space.</div><div data-lake-id="8b8ca6366375ac983a4dba4ad5d56687"> CONDENSE url.</div><div data-lake-id="5bab42ebf30772d0a7d1008976c23301"> DATA(lv_url_len) = strlen( url ) - lv_post_len.</div><div data-lake-id="96be11cc8c0b88ec4f90b3812022d323"> url = url+0(lv_url_len).</div><div data-lake-id="ee5eee02d77e1630ed16c59efae5cf63"> APPEND url TO lt_pic.</div><div data-lake-id="f9155e94d981fa82ddc48df10a447780"> ENDLOOP.</div><div data-lake-id="6e815f1313cdb75f84550baf4564c179"> WRITE: / 'ok'.</div><div data-lake-id="7dd2c337f0245f5dc26019a7c956ec5f"> DATA(lv_total) = lines( lt_pic ).</div><div data-lake-id="7277f284420ef32c0b7c55a3a60d419a"> LOOP AT lt_pic ASSIGNING FIELD-SYMBOL(<pic>).</div><div data-lake-id="6a879a8d8f7da445253cf1268c0f12ed"> DATA(lv_name) = folder && lv_index && '.png'.</div><div data-lake-id="5be160aec24044f16b42517ef48efc2d"> DATA(lv_text) = 'Downloading file: ' && lv_name.</div><div data-lake-id="57653fa4f31b4fc2ef10a06ba03521ae"> CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'</div><div data-lake-id="79dc0f7b335449272201edc623f6874c"> EXPORTING</div><div data-lake-id="865f0cd14939a74aa4b5c8b7011e9350"> percentage = lv_index * 100 / lv_total</div><div data-lake-id="a1c297f4f8322b592d9277bb6e9d4f85"> text = lv_text.</div><div data-lake-id="ac070de56a05f6b4e76a49cd926bd188"> DATA(binary) = zcl_crm_cm_tool=>get_data_by_url( <pic> ).</div><div data-lake-id="00ecaf64229205699cba35355e68d54f"> zcl_crm_cm_tool=>download_locally( iv_local_path = lv_name iv_binary = binary ).</div><div data-lake-id="6e50683f858f8081de93424ed44ac9df"> lv_total_size = lv_total_size + xstrlen( binary ).</div><div data-lake-id="7f97f1d55c188532d18e85fe9878013e"> ADD 1 TO lv_index.</div><div data-lake-id="187afcf4b53c56c72480912d506b875c"> ENDLOOP.</div><div data-lake-id="8e7d80365fab87bd69f310de25444f90"> WRITE: / 'totally ', lv_total, ' pictures downloaded successfully!' COLOR COL_NEGATIVE.</div><div data-lake-id="3d2bbeb75c8d00bd9badecb921d349c4"> DATA: ls_note TYPE crmd_prod_note.</div><div data-lake-id="d884b756550d4b94e1dc45ae63db2ba0"> CALL FUNCTION 'GUID_CREATE'</div><div data-lake-id="43fd82164ebea1abc6d64961b3fe732b"> IMPORTING</div><div data-lake-id="f48823d4da95ae23ead2c7b890d071fb"> ev_guid_16 = ls_note-note_guid.</div><div data-lake-id="d12b62ca3ffd28514ef4fbe683067a26"> ls_note-note_title = <title>-value.</div><div data-lake-id="480f67265a3563103bc78310d96ba59f"> ls_note-pic_size = lv_total.</div><div data-lake-id="513e1f9118d0769120ea74c66835e3d4"> ls_note-download_date = sy-datum.</div><div data-lake-id="eba4df0144e4b2d90ebba3abb221f78d"> ls_note-download_time = sy-timlo.</div><div data-lake-id="14d6785743ff4e65dab0127a1b00821d"> ls_note-total_size = lv_total_size.</div><div data-lake-id="6dd9130d776b42a746216155aecd61a0"> INSERT crmd_prod_note FROM ls_note.</div>