Skip to content

Instantly share code, notes, and snippets.

@lili668668
Last active September 5, 2017 03:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lili668668/d12e8a766b11eaf872e66317a0450dd9 to your computer and use it in GitHub Desktop.
Save lili668668/d12e8a766b11eaf872e66317a0450dd9 to your computer and use it in GitHub Desktop.
將 kktix 的 csv 裡的檔案連結加工,讓 Google sheet 可以直接觀看圖片,方便檢驗身分
import csv
import argparse
# 使用 Python3
# python3 add_image.py 檔案路徑
URL_ROW_NAME = "聯絡人 學生資格資料"
parser = argparse.ArgumentParser(description="Input the csv file path.")
parser.add_argument('file_path', metavar="file path", type=str, nargs=1, help="the kktix csv local file path")
args = parser.parse_args()
file_path = args.file_path[0]
with open(file_path, newline="", encoding="utf-8") as csvfile:
new_file_path = file_path.replace(".csv", "_new.csv")
with open(new_file_path, "w", newline="", encoding="utf-8") as new_csvfile:
reader = csv.DictReader(csvfile)
fieldnames = reader.fieldnames
writer = csv.DictWriter(new_csvfile, fieldnames=fieldnames)
writer.writeheader()
for row in reader:
row[URL_ROW_NAME] = '=image("' + row[URL_ROW_NAME] + '")'
writer.writerow(row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment