Thursday, June 11, 2020

Using python to get file from Azure Blob Storage using shared key

Here is the code to get file from Azure Blob Storage:



import base64
import hmac
import hashlib
import datetime

import requests

storage_account='your account name'
file_path='the path of your file'
token='shared key of your account'
def _sign_string(key, string_to_sign):
        key = base64.b64decode(key.encode('utf-8'))
        string_to_sign = string_to_sign.encode('utf-8')
        signed_hmac_sha256 = hmac.HMAC(key, string_to_sign, hashlib.sha256)
        digest = signed_hmac_sha256.digest()
        encoded_digest = base64.b64encode(digest).decode('utf-8')
        return encoded_digest

now = datetime.datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT')
url ='https://{account}.blob.core.windows.net/{path}'.format(account=storage_account,path=file_path)
version = '2009-09-19'  ## you may change this based on the version you are using
headers = {'x-ms-version': version,'x-ms-date': now}

content = 'GET{spaces}x-ms-date:{now}\nx-ms-version:{version}\n/{account}/{path}'.form
at(spaces='\n'*12,now=now, version=version, account=storage_account, path=file_path)

headers['Authorization'] = 'SharedKey ' + storage_account + ':' + _sign_string(token,
content)

response = requests.get(url, headers=headers)
assert response.status_code == 200
file = open("oci_servers.csv", "w")
file.write(response.text)
file.close()
#print response.text

Wednesday, March 11, 2020

Report-- Show column only when download to csv

in the col condition, chose PL/SQL compression and put this:

:REQUEST LIKE 'FLOW_EXCEL_OUTPUT%'

Friday, February 28, 2020

APEX: text highlighter with Mark.js

Today I have a need to highlighter some of the key word(typed in search string) in the report and I find out this wonderful Mark.js library(you can find all the detail here https://markjs.io/)

Here is what I did for the Classic Report:

1. include the javascripts: include this url in the File URLS section of the page(Here I am using the JQuery model):

https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/jquery.mark.min.js

2. put following css in the CSS inline section of the page:

mark {
  padding: 0;
  background: #00ff19;
  color: black;  
}

3. create a after refresh DA and put following javascripts in the action:

$('.t-Report-cell').mark($v('Pxx_SEARCH'), {"separateWordSearch": false});

Pxx_SEARCH is my search item in my page

There are many options available(check detail in https://markjs.io/). You can set up by your choice.