python
2022-12-01
2022-05-09
2022-05-09
在一個檔案中,儲存了多個 json objects,用一般的 json.loads 會出現 error,需要找方式自行 parse 為 object
Sample code
`
from json import JSONDecoder, JSONDecodeError
import re
NOT_WHITESPACE = re.compile(r’[^\s]’)
def decode_stacked(document, pos=0, decoder=JSONDecoder()):
while True:
match = NOT_WHITESPACE.search(document, pos)
if not match:
return
pos = match.start()
try:
obj, pos = decoder.raw_decode(document, pos)
except JSONDecodeError:
# do something sensible if there's some error
raise
yield obj
s = “””
{“a”: 1}
[
1
,
2
]
“””
for obj in decode_stacked(s):
print(obj)
`
Reference
2022-05-09
要用 python 讀取儲存在 S3 中的 gzip 檔案資料
使用的過程中,boto3 有用 s3_client 也有用 s3 resource 取得 S3 object 的方式,需要找時間再研究這兩者的差異
code sample
def load_gzip(client, bucket, key):
response = client.get_object(Bucket=bucket, Key=key)
content = response['Body'].read()
with gzip.GzipFile(fileobj=io.BytesIO(content), mode='rb') as fh:
file_content = fh.read()
return file_content.decode("utf-8")
讀多個 S3 檔案的方式
Reference
- amazon web services - Reading contents of a gzip file from a AWS S3 in Python - Stack Overflow
- To use gzip file between python application and S3 directly for Python3
- How to store and retrieve gzip-compressed objects in AWS S3
- Reading a Specific File from an S3 bucket Using Python – SQLServerCentral
2022-04-06
2022-03-30
用這份文件,簡略記錄一下自己要捉取甲骨文資料,用到的一些 package & 參考文件
有關 word reference
- 使用Python 自動生成 Word 文件的教程_程式設計_程式人生
- Day20-Python 操作 docx 文件 - iT 邦幫忙::一起幫忙解決難題,拯救 IT 人的一天
- Quickstart — python-docx 0.8.11 documentation
有關 google drive api
- Introduction to Google Drive API | Google Developers
- Python Quickstart | Drive API | Google Developers
- Drive API | Google Developers
- 【Google API 教學】如何申請 OAuth 2.0 憑證? 使用Google Drive API 做示範給你看! - WP數位 依照這篇的方式,來申請 OAuth 需要的憑證資料
- 【Google API 教學】Google Drive API upload 使用 Python 上傳單一檔案 基本教學 - WP數位
- 【Google API 教學】Google Drive API upload 使用 Python 上傳到指定資料夾 基本教學 - WP數位
- 使用 PyDrive 來操作
有關 selenium reference
- 必學的Python Selenium套件自動化網頁截圖技巧
- python+selenium 自動填寫表單並提交 - 台部落
- [Python爬蟲教學]整合Python Selenium及BeautifulSoup實現動態網頁爬蟲
- 用python-webdriver實現自動填表的示例程式碼_程式設計_程式人生
- 動態網頁爬蟲第二道鎖 — Selenium教學:如何使用find_element(s)取得網頁元素(附Python 程式碼) | by 行銷資料科學 | Medium
selenium youtube 介紹
2021-12-09
2021-12-09
在針對不同的 telemetry-type 實作不同的 de-normalize & to_parquet 時,覺得這滿適合用 Factory Pattern 的,就花些時間來試試看囉
這樣做,覺得滿好的
Reference
- The Factory Method Pattern and Its Implementation in Python – Real Python 這篇很有用,我就是看這篇邊改邊實作的
- [Design Pattern] Factory Method 工廠方法 - iT 邦幫忙::一起幫忙解決難題,拯救 IT 人的一天 這篇較簡略,我反而不容易懂。不過,倒是看了這篇後,才覺得我也是可以用 Factory Pattern 的
- 什麼?又是/不只是 Design Patterns!? :: 第 11 屆 iThome 鐵人賽 找時間將這部分看一下,有個印象,才好深入
同場加映
- Python Tutorials – Real Python 有找到啥 keyword or 方式,想看看如何運用、實作可。嘗試,在這網站找找看
2021-12-08
在 debug python 的時候,總想知道有沒有 call 到某個 function,目前是有用 decorator 來用
進階的方式為使用 dataclass,這還要找時間來試試囉