一些可以幫助你完成日常工作自動化的接口
有時我們需要 API 來快速完成工作或提高工作效率。在本文將分享 10 個 API 來自動化你的日常問題。
自動上傳視頻到 YouTube
有不少自媒體會做視頻,有了這個,就可以把做好的視頻批量上傳了。
接口獲取地址:https://developers.google.com/youtube/v3
代碼:
# 獲取 API: https://developers.google.com/youtube/v3
#安裝 pip install simple-youtube-api
from simple_youtube_api.Channel import *
from simple_youtube_api.LocalVideo import *
from simple_youtube_api.YouTube import *
# 上傳視頻
ch = Channel()
ch.login("client.json", "credentials.storage")
myvid = LocalVideo("test.mp4")
myvid.set_title("Test Video")
myvid.set_description("This is a test video")
myvid.set_category("Education")
myvid.set_tags(["test", "python"])
myvid.set_privacy_status("public")
myvid.set_default_language("en")
myvid.set_playlist("Uploads")
vid = ch.upload_video(myvid)
print(vid.id)
# 檢索視頻
yt = YouTube()
yt.login()
# 根據(jù)名字檢索視頻
vid = yt.search("Python")
for v in vid:
print(v.title, v.id)
# 根據(jù) id 檢索視頻
vid = yt.search_by_video_id("video ID")
print(vid.fetch)
# 獲取評論
print(vid.fetch_comment_threads())
下載 Unsplash 圖片
Unsplash 是獲取高分辨率照片的最受歡迎的網(wǎng)站之一。這個很棒的 API 可以讓你用幾行代碼輕松下載 Unsplash 照片。
下面的代碼分為兩部分,首先我從 Unsplash 獲取圖像并下載 URL,然后使用 requests 模塊下載它們。
# 獲取 API: https://unsplash.com/developers
import requests
apikey = "Your Api Key"
query = "Laptop"
api_url = f"https://api.unsplash.com/search/photos?query={query}&per_page=30&page=1&client_id={apikey}"
r = requests.get(api_url)
r = r.json()
# 獲取下載鏈接
for down in r['results']:
print(down['links']['download'])
# 接下來就可以下載圖片了
獲取電影信息
此 API 可以獲取你最喜歡的電影和節(jié)目數(shù)據(jù)。它與 TMDB 電影數(shù)據(jù)庫連接起來,為你提供免費使用的 API。你可以獲取電影和電視節(jié)目的標(biāo)題、收視率、情節(jié)等等。
# Get your API : developers.themoviedb.org
# pip install tmdbsimple
import tmdbsimple as imdb
imdb.API_KEY = 'YOUR_API_KEY'
# search movies by Name
m = imdb.search.movie(query='Jurassic Park')
response = m.info()
# get movie title
print(m.title)
# get movie budget
print(m.budget)
# get movie rating
print(m.rating)
# get movie reviews
print(m.reviews())
# get similar movies
print(m.similar_movies())
# get runtime
print(m.runtime)
# Search movie By ID
m = imdb.Movies(135397)
m = m.info()
# Search TV Shows
tvshow = imdb.search.tv(query='Game of Thrones')
response = tvshow.info()
print(tvshow.name)
print(tvshow.overview)
獲取 NASA 的最新照片
這個絕妙的 API 將幫助你獲取美國宇航局的最新照片新聞。你可以獲取每日行星報告和照片,你還可以探索不同的行星和星系并查看他們的新聞。
假設(shè)你正在開發(fā)一個提供每日美國國家航空航天局新聞和最新照片的應(yīng)用程序,那么這個免費的 API 對你來說將是一個方便的工具。
# 獲取 Api: https://api.nasa.gov/
# pip install nasapy
import requests
import nasapy
api_key = "Your Api Key"
nasa = nasapy.Nasa(key = api_key)
# Get Astronomy Picture of the Day
pic = nasa.picture_of_the_day()
print(pic)
# Get Mars Weather
mars = nasa.mars_weather()
print(mars)
# Search for Images and Audio from nasa
search = nasa.media_search(query="satellite", media_type="image")
print(search)
上傳和分享文件
想要在 PC 或手機之間共享文件,然后使用 Dropbox Free API,讓你上傳和下載 Dropbox 存儲的文件和文件夾。
# 獲取 API: https://www.dropbox.com/developers/
# pip install dropbox
import dropbox
dbx = dropbox.Dropbox('Your Api Key')
# upload
with open('test.txt', 'rb') as f:
dbx.files_upload(f.read(), '/test.txt')
# download
dbx.files_download_to_file('test.txt', '/test.txt')