This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#just open your command line and type | |
pip install speedtest-cli | |
#and then test your speed with the command below | |
speedtest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
python3 "file.py" -arg arg | |
''' | |
#install fire | |
pip install fire | |
#Main code | |
import fire |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Install | |
pip install tqdm | |
#Usage | |
from tqdm import tqdm | |
for i in tqdm(range(10000)): | |
print(i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
original from https://clay-atlas.com/blog/2019/08/16/python-screening-tutorial/ | |
''' | |
from PIL import ImageGrab | |
import numpy as np | |
import cv2 | |
image = ImageGrab.grab() | |
width, height = image.size |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Simple Cython Usage | |
''' | |
''' Step0:Install Cython ''' | |
sudo pip3 install cython | |
''' Step0:Install Cython ''' | |
''' Step1:Create "a.py" ''' | |
import sys |