2022. 12. 4.

Using paginator in boto3


How to convert codes for using paginator

### no paginations code
  1. for region in regions:
  2.     resource = boto3.client('resourcegroupstaggingapi', region_name=region)
  3.     res = resource.get_resources(ResourceTypeFilters=resource_type_filters)
  4.     list_items(res)

    

### using paginator code
  1. for region in regions:
  2.     resource = boto3.client('resourcegroupstaggingapi', region_name=region)
  3.     paginator = resource.get_paginator('get_resources')  # parameter is 'method name' which is LINE3 of above code 
  4.     response_iterator = paginator.paginate(ResourceTypeFilters=resource_type_filters) #Passing parameter is same with   LINE3 in above code
  5.     for page in response_iterator:
  6.         list_items(page)

2022. 10. 16.

migration evernote to notion ( by python program :enex2notion)

I 've been used  evernote for a long time. but  I changed to notion recently. 

I tried to export data from  evernote to notion. The guide which is proposed by notion team is not good.  But I found 'enex2notion' tool  by googling. It it very effective for me although  some installation step is not simple for me.

I shared it for another users.  

My pc is mac. 

ref: https://github.com/vzhd1701/enex2notion

Step 

1. install enex2notion
  -  you can refer on above ref site. Don't give it up , this app is compensate for your install try.

2. export notebooks from evernote app.

2.5  get  auth_v2 key from your browser
  -  open notion with web browser and login 
  -  find cookie ( token_v2)  in browser. You need  token to upload to notion 




3 run enex2notion with notebook file (*.enex)
 - program will upload  pages one by one  ( Upload speed is not fast.)
 - some pages are fail to uploading. ( You must copy these pages by manual )
 - You can check progress on your notion app.

 enex2notion --token <TOKEN from 2.5 step> "mynotebook.enex"  ## do not include letter "<", ">"
4. Check pages which are uploaded. 

2022. 8. 13.

OrderedDict. ( in Python)

func: Dictionary remembers added order of items.

Ref : https://docs.python.org/3/library/collections.html


Usecase  sample : convert number to roman numerals.


import string
from collections import OrderedDict

def to_roman(num):
maps = OrderedDict([('M', 1000), ('CM', 900), ('D', 500),
('CD', 400), ('C', 100), ('XC', 90), ('L', 50), ('XL', 40),
('X', 10), ('IX', 9), ('V', 5), ('IV', 4), ('I', 1)])
res = ''
for k, v in maps.items():
while num >= v:
print(f' {num}, {v}')
res += k
num -= v
return res

print(1988)
print(to_roman(1988))

### output #####
1988 1988, 1000 988, 900 88, 50 38, 10 28, 10 18, 10 8, 5 3, 1 2, 1 1, 1 MCMLXXXVIII



2022. 7. 3.

Loading xml data in excel vba by using XML Object(MSXML2.DOMDocument)

### in excel file ( xlsm , macro excel , enable macro) 


' Declare xml object

  set xmlObj = CreateObject("MSXML2.DOMDocument.6.0")

 ' set loading option with non async

 xmlObj.Async = False

' validate off

xmlObj.validateOnParse = False

' reading file from sample.xml 

xmlObj.Load "sample.xml"

' select all "mynode" from root node recursively ( ref. xml path grammar in detail)

' root node에서 mynode 모두 선택하기 추가적인 부분은 xml path 문법을 참고

Set nodeList = xmlObj.SelectNodes("//mynode")

for index to nodeList.Length -1 

    set myNode = nodeList(index)

    ' do somthing 

    aa = myNode.text

next index