'''
一、文字转语音api,树莓派天气闹钟
爬取实时天气数据转换为语音,设置树莓派计划任务
'''
from aip import AipSpeech
import requests
import re
from bs4 import BeautifulSoup
import time
from datetime import datetime
import os
''' '''
def getHtmlText(url,code='utf-8'):
try:
r = requests.get(url)
r.raise_for_status()
r.encoding = code
return r.text
except:
return ''
def makeSoup(html):
wstr = ''
if html == '':
return '嘤嘤嘤~今天我也不知道海淀天气了'
else:
soup = BeautifulSoup(html,'html.parser')
soup1 = soup.find_all('li',attrs = {'class':'on'})[1]
str1 = re.findall(r'>(.*)</',str(soup1))
b = ''
try:
slist = re.findall(r'^(.*)</span>(.*)<i>(.*)$',str1[4])
for x in range(len(slist[0])):
b += slist[0][x]
except:
b = str1[4]
if '/' in b:
b = b.replace('/','-')
str1[4] = '海淀的温度是'+b
str1[6] = ',风力是'+str1[6]
donser= str1[6]
if "&lt" in donser:
donser=donser.replace("&lt"," ")
str1[6]=donser
for i in str1:
print(i[:])
if i != '':
if i[0]=='&':
# print("###")
print("")
wstr = wstr +i
if '雨' in wstr:
wstr += ',出门别忘记带雨伞,嘤嘤嘤!'
#print(wstr)
return wstr
'''
用百度的AIP
把文字变成mp3文件
'''
def stringToMp3(strings_txt):
week=str(datetime.now().weekday()+1)
if week=="":
week="日"
month=str(datetime.now().strftime('%m'))
if month[0]=='':
month=month[1:]
strings_txt = 'Surprise 兄dei,起床啦~嘤嘤嘤~起床啊~啊~啊~啊~嘤嘤嘤~起床啦~要迟到啦!今天是星期'+ week + "," + str(month) +"月~"+ strings_txt
print(strings_txt)
APPID = ''
APIKey = 'iKX6hukjx9vRPo4VT6x3POKw'
SecretKey = 'pI0VoAXi11YXDtmxyXe2rffUQWvgNgGy' aipSpeech = AipSpeech(APPID,APIKey,SecretKey)
result = aipSpeech.synthesis(strings_txt,'zh','',\
{'vol':8,
'per':4,
'spd':5})
if not isinstance(result,dict):
with open('tep.mp3','wb') as f:
f.write(result) '''
MAIN
'''
def main():
url = 'http://www.weather.com.cn/weather/101010200.shtml'
html=getHtmlText(url)
stringToMp3(makeSoup(html))
os.system('mpg321 tep.mp3')
os.system('mpg321 tep.mp3')
#os.system('rm -rf tep.mp3') if __name__ == '__main__':
main()

crontab -e 设置计划任务        8 22 * * * python3 /home/pi/weather.py          #分 时 日 月 周

点击  https://files.cnblogs.com/files/dzzy/tep.zip 查看效果

 
'''
二、百度api图片转文字
'''

# -*- coding: UTF-8 -*-  

from aip import AipOcr

APP_ID = ''
API_KEY = 'QGGvDG2yYiVFvujo6rlX4SvD'
SECRET_KEY = 'PcEAUvFO0z0TyiCdhwrbG97iVBdyb3Pk' aipOcr=AipOcr(APP_ID, API_KEY, SECRET_KEY) filePath = "shit.jpg" def get_file_content(filePath):
with open(filePath, 'rb') as fp:
return fp.read() options = {
'detect_direction': 'true',
'language_type': 'CHN_ENG',
} result = aipOcr.webImage(get_file_content(filePath),options) # url调用
# result = apiOcr.webImage('http://www.?????.com/????.jpg') print(result)

结果: [{'words': '秘密'}, {'words': 'su seven'}, {'words': '我有很多秘密我一个人细数'}, {'words': '从欢笑到哭泣'}], 'words_result_num': 4}

百度 api 测试 & python的更多相关文章

  1. 百度人脸识别api及face++人脸识别api测试(python)

    一.百度人脸识别服务 1.官方网址:http://apistore.baidu.com/apiworks/servicedetail/464.html 2.提供的接口包括: 2.1 多人脸比对:请求多 ...

  2. 基于百度语音识别API的Python语音识别小程序

    一.功能概述 实现语音为文字,可以扩展到多种场景进行工作,这里只实现其基本的语言接收及转换功能. 在语言录入时,根据语言内容的多少与停顿时间,自动截取音频进行转换. 工作示例: 二.软件环境 操作系统 ...

  3. 使用python+pychram进行API测试(接口测试)初级STEP 1

    花了一天时间安装了解了下最基本的python+pychram进行API测试,下面这个可以指导自己以后入门:基本的开发级别还需要学习 1.python下载地址:https://www.python.or ...

  4. Python汉英/英汉翻译(百度API/有道API)

    一.百度API实现 Step1:申请API Key 以前用过BAE,已经有了Api Key,没有的可以去申请 Step2:挺简单,直接看实现的代码吧 ```python #coding:utf-8 i ...

  5. Python + 百度Api 通过地址关键字获得格式化的地址信息

    由于用户输入是千奇百怪的,除了格式语法不合要求之外的,即便是所谓的合法数据也是五花八门.尤其是地址,所有才由此文. 百度Api注册一个账号,创建一个应用后就会有一个`ak`的参数,就够了. Pytho ...

  6. python使用百度api翻译中英文

    python使用百度api翻译中英文 写程序取变量名的时候,常常需要翻译单词,或者将中文翻译成英语.有道词典,必应词典都很好,可是...命令行习惯了还是觉得用在cmd里面调出程序使用起来也许会更爽.于 ...

  7. Python爬虫之百度API调用

    调用百度API获取经纬度信息. import requests import json address = input('请输入地点:') par = {'address': address, 'ke ...

  8. API测试-接口测试基础(1)

    由于自己想学习API方面的测试,但是市面上搜不到相关的图书可以系统学习,网上的内容又零零散散,适合有点API开发基础的人去搜索.为了方面新手学习API测试,现在整理了他人的宝贵经验和自己的学习心得,尽 ...

  9. 使用metaweblog API实现通用博客发布 之 API测试

    使用metaweblog API实现通用博客发布 之 API测试 使用博客比较少,一则是文笔有限,怕写出的东西狗屁不通,有碍观瞻, 二则是懒,很讨厌要登录到网站上写东西,也没有那么多时间(借口).个人 ...

随机推荐

  1. CSU-2172 买一送一

    CSU-2172 买一送一 Description ICPCCamp 有 n 个商店,用 1, 2, -, n 编号.对于任意 i > 1,有从商店 \(p_i\) 到 i 的单向道路. 同时, ...

  2. Halcon11 Linux 下载

    Halcon11 Linux下载地址:http://www.211xun.com/download_page_3.html HALCON 11 是一套机器视觉图像处理库,由一千多个算子以及底层的数据管 ...

  3. 聊聊、Java 命令 第二篇

    第一篇类之间没有依赖关系,所以比较简单,这一篇来看看有依赖的类怎么编译和执行. (一)Java 运行 class 有依赖 Person 是一个接口,只有一个 getName 方法.Man 则实现了 P ...

  4. redhat linux 7.4关闭透明大页

    每一步: 在GRUB_CMDLINE_LINUX加入选项 transparent_hugepage=never echo 'GRUB_CMDLINE_LINUX="transparent_h ...

  5. OtherStream

    import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.DataInputStream; import ...

  6. C#,一种简单的方式实现滚动鼠标缩放图片,平移

    1.缩放 private void ImageShow_Load(object sender, EventArgs e) { pictureBox1.Load(@"E:\SQ1.jpg&qu ...

  7. swiper单屏滚动

    .swiper-slide { overflow: auto; } 1. 排除某些屏,不滚动 var startScroll, touchStart, touchCurrent; var aSlide ...

  8. vue单文件组件互相通讯

    在vue中,我们可以把一个页面各个部分单独封装起来,做成各种小组件,然后加载,这样的好处是代码维护起来比较容易,重复的代码多处调用! 在一个vue项目中,单文件组件以.vue形式文件命名 每个组件之间 ...

  9. Normalize.css用法

    1 Normalize.css用法 重置样式非常多,Normalize.css和reset是两个常用的重置 CSS 文件 http://necolas.github.io/normalize.css/ ...

  10. 粟粟的书架(bzoj 1926)

    Description 幸福幼儿园 B29 班的粟粟是一个聪明机灵.乖巧可爱的小朋友,她的爱好是画画和读书,尤其喜欢 Thomas H. Co rmen 的文章.粟粟家中有一个 R行C 列的巨型书架, ...