Skip to content

Instantly share code, notes, and snippets.

Avatar

e96031413

View GitHub Profile
@e96031413
e96031413 / img2pdf.py
Created Dec 29, 2019
Merge all your jpg files into a single PDF
View img2pdf.py
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 Jan 1, 2020
how to convert html files into a single pdf
View html2pdf.py
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 Jan 4, 2020
Using urllib, requests, bs4 to scrape the search result
View googleSearch.py
#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 Jan 5, 2020
Use Python to Google Translate
View googletrans.py
#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 Jan 6, 2020
Test your Internet Speed on Command Line
View speedtest.py
#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 Feb 28, 2021
使用Python操作Firebase資料庫(CRUD)
View firebase_tutorial.py
'''
Firebase是可以即時讀取的資料庫,主要以JSON格式為主。除了透過程式操作外,也能在Firebase的網頁界面上進行資料操作(上傳、讀取、修改、刪除)
'''
###程式1###
#引入模組
from firebase import firebase
import time
@e96031413
e96031413 / playMusic.py
Created Jan 12, 2020
How to play music with python?
View playMusic.py
#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 Jan 12, 2020
Use "Fire" module to input arguments
View arguments.py
'''
python3 "file.py" -arg arg
'''
#install fire
pip install fire
#Main code
import fire
@e96031413
e96031413 / globUsage.py
Created Jan 12, 2020
The official example of glob
View globUsage.py
>>> 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 Jan 12, 2020
The quick example of tqdm
View tqdmProgressBar.py
#Install
pip install tqdm
#Usage
from tqdm import tqdm
for i in tqdm(range(10000)):
print(i)