Skip to content

Instantly share code, notes, and snippets.

@e96031413
e96031413 / img2pdf.py
Created December 29, 2019 07:16
Merge all your jpg files into a single PDF
import img2pdf
import os
current_path = os.getcwd()
with open("output.pdf", "wb") as f:
f.write(img2pdf.convert([i for i in os.listdir(current_path) if i.endswith(".jpg")]))
@e96031413
e96031413 / html2pdf.py
Created January 1, 2020 14:36
how to convert html files into a single pdf
import glob,os
import pdfkit #pip install pdfkit
path = r"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe"
config = pdfkit.configuration(wkhtmltopdf=path)
newList=[]
for filename in glob.iglob(os.path.join('*.html')):
newList.append(filename)
@e96031413
e96031413 / googleSearch.py
Created January 4, 2020 11:48
Using urllib, requests, bs4 to scrape the search result
#originally from https://github.com/getlinksc/scrape_google
import urllib
import requests
from bs4 import BeautifulSoup
# desktop user-agent
USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:65.0) Gecko/20100101 Firefox/65.0"
# mobile user-agent
MOBILE_USER_AGENT = "Mozilla/5.0 (Linux; Android 7.0; SM-G930V Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.125 Mobile Safari/537.36"
@e96031413
e96031413 / googletrans.py
Created January 5, 2020 06:43
Use Python to Google Translate
#Translate Any Language to English
from googletrans import Translator
translator = Translator()
print(translator.translate('星期日').text)
#on Sunday
#Translate English to Chinese
from googletrans import Translator
translator = Translator()
print(translator.translate('Sunday', dest='zh-tw').text)
@e96031413
e96031413 / speedtest.py
Created January 6, 2020 01:07
Test your Internet Speed on Command Line
#just open your command line and type
pip install speedtest-cli
#and then test your speed with the command below
speedtest
@e96031413
e96031413 / firebase_tutorial.py
Last active January 23, 2024 14:30
使用Python操作Firebase資料庫(CRUD)
'''
Firebase是可以即時讀取的資料庫,主要以JSON格式為主。除了透過程式操作外,也能在Firebase的網頁界面上進行資料操作(上傳、讀取、修改、刪除)
'''
###程式1###
#引入模組
from firebase import firebase
import time
@e96031413
e96031413 / playMusic.py
Created January 12, 2020 06:34
How to play music with python?
#Method(1)Using system default player
import os
os.system('test.mp3')
#Method(2)Using pygame
import pygame
pygame.mixer.init()
pygame.mixer.music.set_volume(1.0)
@e96031413
e96031413 / arguments.py
Created January 12, 2020 07:01
Use "Fire" module to input arguments
'''
python3 "file.py" -arg arg
'''
#install fire
pip install fire
#Main code
import fire
@e96031413
e96031413 / globUsage.py
Created January 12, 2020 07:11
The official example of glob
>>> import glob
>>> glob.glob('./[0-9].*')
['./1.gif', './2.txt']
>>> glob.glob('*.gif')
['1.gif', 'card.gif']
>>> glob.glob('?.gif')
['1.gif']
>>> glob.glob('**/*.txt', recursive=True)
['2.txt', 'sub/3.txt']
>>> glob.glob('./**/', recursive=True)
@e96031413
e96031413 / tqdmProgressBar.py
Created January 12, 2020 07:26
The quick example of tqdm
#Install
pip install tqdm
#Usage
from tqdm import tqdm
for i in tqdm(range(10000)):
print(i)