建议收藏,22个Python迷你项目(附源码)_python做的简单项目

alarm_hour=alarm_time[0:2]
alarm_minute=alarm_time[3:5]
alarm_seconds=alarm_time[6:8]
alarm_period = alarm_time[9:11].upper()
print(“Setting up alarm…”)
while True:
now = datetime.now()
current_hour = now.strftime(“%I”)
current_minute = now.strftime(“%M”)
current_seconds = now.strftime(“%S”)
current_period = now.strftime(“%p”)
if(alarm_periodcurrent_period):
if(alarm_hour
current_hour):
if(alarm_minutecurrent_minute):
if(alarm_seconds
current_seconds):
print(“Wake Up!”)
playsound(‘audio.mp3’) ## download the alarm sound from link
break


⑬ 有声读物  
 目的:编写一个Python脚本,用于将Pdf文件转换为有声读物。


提示:借助pyttsx3库将文本转换为语音。


安装:pyttsx3,PyPDF2  
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/a92254ae94034ebb8ce8bc2f3f2427fc.png)  
 ⑭ 天气应用  
 目的:编写一个Python脚本,接收城市名称并使用爬虫获取该城市的天气信息。


提示:你可以使用Beautifulsoup和requests库直接从谷歌主页爬取数据。


安装:requests,BeautifulSoup



from bs4 import BeautifulSoup
import requests
headers = {‘User-Agent’: ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3’}

def weather(city):
city=city.replace(" “,”+")
res = requests.get(f’https://www.google.com/search?q={city}&oq={city}&aqs=chrome.0.35i39l2j0l4j46j69i60.6128j1j7&sourceid=chrome&ie=UTF-8’,headers=headers)
print(“Searching in google…\n”)
soup = BeautifulSoup(res.text,‘html.parser’)
location = soup.select(‘#wob_loc’)[0].getText().strip()
time = soup.select(‘#wob_dts’)[0].getText().strip()
info = soup.select(‘#wob_dc’)[0].getText().strip()
weather = soup.select(‘#wob_tm’)[0].getText().strip()
print(location)
print(time)
print(info)
print(weather+“°C”)

print(“enter the city name”)
city=input()
city=city+" weather"
weather(city)


⑮ 人脸检测  
 目的:编写一个Python脚本,可以检测图像中的人脸,并将所有的人脸保存在一个文件夹中。


提示:可以使用haar级联分类器对人脸进行检测。它返回的人脸坐标信息,可以保存在一个文件中。


安装:OpenCV。


下载:haarcascade\_frontalface\_default.xml



import cv2

Load the cascade

face_cascade = cv2.CascadeClassifier(‘haarcascade_frontalface_default.xml’)

  • 21
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值