Skip to content

Instantly share code, notes, and snippets.

@e96031413
e96031413 / ppt2jpg.py
Created February 2, 2020 05:53
A script can save ppt as jpgs and combine them into a single image
import os
import win32com.client
from PIL import Image
ppt_path = input('請輸入PPT檔案絕對路徑:')
long_sign = input('是否產生長圖(Y/N):')
def ppt2jpg():
output_path = ppt_path
@e96031413
e96031413 / natural_sorting.py
Last active February 2, 2020 06:49
處理natural sorting排列順序問題 - 例如:原本應該是:1,2,12,15,電腦會變成:1,12,15,2
# original from https://stackoverflow.com/a/5967539
# 使用sort()方法時需要注意資料型態必須為list
import re
def atoi(text):
return int(text) if text.isdigit() else text
def natural_keys(text):
'''
@e96031413
e96031413 / Youtube_download_StreamLink.py
Last active February 4, 2020 13:52
A script to download stream video from YouTube with highest quality
@e96031413
e96031413 / 大數據時代一定要會的資料蒐集術筆記
Created February 9, 2020 01:41
大數據時代一定要會的資料蒐集術筆記
**1 - 爬蟲時若使用Chrome瀏覽器的XPath抓取套件,出現tbody要自行刪除**
**2 - Google試算表的ImportXML函數抓取資料**
=importxml(URL, XPath_query)
#URL為目標頁面
#XPath_query為透過XPath套件抓取的路徑
#以 &儲存格位置來代表數值變數,如&B1
@e96031413
e96031413 / upload_to_google_drive.py
Last active February 12, 2020 12:05
用Python上傳檔案到Google Drive
# 程式碼來自https://shareboxnow.com/python-google-drive-1/、https://shareboxnow.com/python-google-drive-2/,本人僅作紀錄使用
# 我的Medium部落格介紹:https://medium.com/@yanweiliu/upload-your-file-to-google-drive-with-python-28f7e5a7ed8b
from __future__ import print_function
import os
import io
import time
from googleapiclient.discovery import build
from googleapiclient.http import MediaFileUpload, MediaIoBaseDownload
from httplib2 import Http
@e96031413
e96031413 / google_trends_csv_png.py
Created February 11, 2020 12:21
將Google Trends的資料輸出成CSV檔案,並進行時間序列繪圖
@e96031413
e96031413 / multi_gmail.py
Created February 17, 2020 00:07
Create multiple gmail account at one time
def dot_trick(username):
emails = list()
username_length = len(username)
combinations = pow(2, username_length - 1)
padding = "{0:0" + str(username_length - 1) + "b}"
for i in range(0, combinations):
bin = padding.format(i)
full_email = ""
for j in range(0, username_length - 1):
@e96031413
e96031413 / get_geo_info.py
Created February 17, 2020 01:40
Get your Country, City, Lat, Log with Python (require requests only)
import requests
res = requests.get('https://ipinfo.io/')
data = res.json()
#print(data)
location = data['loc'].split(',')
city=data['city']
country=data['country']
lat=float(location[0])
log=float(location[1])
@e96031413
e96031413 / multi_threading_download.py
Created February 19, 2020 07:25
a multi threading python program which can be reused.
# Assume that you have collected file links with web crawler or any other method.
# We will use requests, wget, concurrent.futures to download our file
import requests
import wget
import concurrent.futures
with open('download_link.txt','r') as f:
url_list = [str(line) for line in f.readlines()]
@e96031413
e96031413 / python_list_note.py
Last active February 26, 2020 12:30
A short note on Python List
# Python list usage
list1.append() # 加到最後面
list1.insert(0,var) # 加到指定位置
list1.extend(list2) # 將list2合併到list1
list1.remove("C") # 移除list1中的"C"
list1.pop(0) # 刪除第0個項目
list1.pop() # 刪除最後1個項目
list1.clear() # 清空list1
list1.count() # 計算有多少項目