From a27872741523b616f611c9bbe8c61cee57af1608 Mon Sep 17 00:00:00 2001 From: Aditya <2005akjha@gmail.com> Date: Mon, 27 May 2024 17:25:21 +0530 Subject: [PATCH] Added calculator and newsreader --- Calculatenumbers.py | 48 ++++++++++++++++ __pycache__/Calculatenumbers.cpython-312.pyc | Bin 0 -> 2359 bytes __pycache__/newsread.cpython-312.pyc | Bin 0 -> 3070 bytes daisy_main.py | 12 ++++ newsread.py | 55 +++++++++++++++++++ 5 files changed, 115 insertions(+) create mode 100644 Calculatenumbers.py create mode 100644 __pycache__/Calculatenumbers.cpython-312.pyc create mode 100644 __pycache__/newsread.cpython-312.pyc create mode 100644 newsread.py diff --git a/Calculatenumbers.py b/Calculatenumbers.py new file mode 100644 index 0000000..1219a75 --- /dev/null +++ b/Calculatenumbers.py @@ -0,0 +1,48 @@ +import wolframalpha +import pyttsx3 +import speech_recognition + +# Initialize the text-to-speech engine +engine = pyttsx3.init("sapi5") +voices = engine.getProperty("voices") +for voice in voices: + if "zira" in voice.name.lower(): + engine.setProperty("voice", voice.id) + break +engine.setProperty("rate", 170) + +def speak(audio): + engine.say(audio) + engine.runAndWait() + +def WolfRamAlpha(query): + apikey = "HEVXUJ-T9P3G7YK76" + requester = wolframalpha.Client(apikey) + response = requester.query(query) + try: + answer = next(response.results).text + # print(answer) + speak(answer) + return answer + except StopIteration: + speak("I'm sorry, I don't have an answer to that question") + return None + +def Calc(query): + Term = str(query) + Term = Term.replace("plus", "+") + Term = Term.replace("minus", "-") + Term = Term.replace("multiply", "*") + Term = Term.replace("divide", "/") + Term = Term.replace("Daisy", "") + + Final = str(Term) + try: + result = WolfRamAlpha(Final) + if result: + print(result) + # speak(result) + except Exception as e: + print(f"Error: {e}") + speak("I'm sorry, I don't have an answer to that question") + diff --git a/__pycache__/Calculatenumbers.cpython-312.pyc b/__pycache__/Calculatenumbers.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1d7a7cab51289172ad54d3e8f36d2a6e65ca09f3 GIT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@Ow<~$_+!; zq%lg<^t4J{TE#@DaSnAUZ6&oi;_;0M7BztM{;}mbV!3?wI9?+)e}T{x6V4c>mSo~? zE-*}949$l1_CNrAXLcQJe`lP2f}xTZVZ*gRjv{^($J;V_DbMrLvL9f ztpwg~=<;fBCD7Nv6lx~8x(Cax9}w;bLn~0a2>~Z0|wMBf-EpkoO3j75$a^A zTcD}?HvnpimLg0@rlBCQfZf0_pP_q>_k!Yi@>fLNPrX+tcI2T{TF)fOM-=`Dz*iZZ zd>h0jhcSMP+8?9PV{~9sL@gbK{dc-=bQk9<{zG|j-5;*{50?E0OXC&)QP7q4EyUqa zer#P*iqX4WKXg?ihs%+}l}PWOQt!GPs>)quxvO+)b?le%pU2nafk(2kDZ!LY8DXi4 f+RCV{c(OFOhI+PmAMV_e19;zdS1XQV@3{X1i$VFU literal 0 HcmV?d00001 diff --git a/__pycache__/newsread.cpython-312.pyc b/__pycache__/newsread.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..94fa4509ccdb055f06194632d44e6c35549734b9 GIT binary patch literal 3070 zcmc&$-A@!(6u&b&yEFR<%R*_9*dbO^B8c)KVo*biEn=(2)S6I?9d|D5EX&OH&Rul3 zyK$SeDWoRi6PvV6>{HYFH}o&)3kVJCl?Rgg;v0%d6Q6qSEVGNHHH4SmWX`?!+;i@4 z&hMT(XMPWd0|?sZPcBdVrXchupSaDtHP~zv5L!Sw(uEWntMtN{;LOD_QAAiw`dp`4 zuZs`BkGC-iOUYnmyj|*^s)Y~xhS9Y_u$6TQ%gOrfc9n55wo~_DOErUR;f@L@O*?IL zFYNcmPW=P1q7#sSOhH2b;qBAqnx(FMjmAQ{A7nTyvDz_!-4gH}(AQljHlw2ga_8%>eT%v^SmhJ&inx>CmH1RMo zX0Y0+eyo{BT1%-{OqdhfpjmZPGtwC{K8)=tYNf}AHN(yhof|jtO`Bj%Ka$P@Cuyur zkviBt1drVUqKMX{z_+7cjn2{)sS(DjQqz*u^oP{E39Bg1h1(z-D+Dc8vQN-O-J?so zSBDePl^^5+qE$k5|2BfE1nL1-n|uvb1tE`;vI|@5^MdPL5c8rP+J+W%S2)eo@A~}P zEy!1ILDIQtu5G0+cxc$wBqQ#q*5|7?q#$j>57qGVk{*5w917mN7jDoc82R!(J>ux( znonM?`Ov6~uw4sYb&i)(Ti5IJ%J=BUY7CHmHFl%!js<_-|2l^ChN*WEA|hw&&SiT~P@M@#q7-DUeI{;YOiHq+4D(PNF4Ck0;~N>9 zui1yd>pae$>gnqqnCQ9DeN5|(_x8m52ae;uzP^E;e%ycJX!pd4oVjNxY*I|9W|-43 z+BM$fp79{?6iw_JD6wZCJ8obzj(3f;_mJ$gMdp?mDWy^EZi2 zOtjQ)k=kXZxM|D6uVfYTRSuoWTW7+270Otk77>%T0CV=$gb`1u{L-lIjZkk|nUt<( zt&Ey7rm#va74{@&)X!YZ4)qnx4!#bF)}d};!oWGE4z-5ap>APb%gy``pz29ASAWi& z(Ncz9jWnl@V1iW*9^0Dck)|tDKs=Q%22(Ubjd%*`u$LM%1(h#DQn{uNETT?Z;AfZ< zmO5iV9Rq;Qt2>zE1*~GpIR*~1*zPi|Yw$iyG_7{OQ`4B&Fw+^zyeaD@Cd@O5DN_jk zB7<#e6aG)eiXfQJ7?**>U}MYP^{dqYGmqhh(?%W|v$ z5~j_=B8;EaDRsW$hc6nDH?SDE{Q@EHkhm6#ZXgspFG6Jwe5lgff{l$VH=hVOosNZgeF+%n13rZL&?SlBfS zCK|ev5DwwLAP2)aj+e^dw54ZK_%!JSFaED$e*M;;+kJX@B-^Gypa_gYq?ZA;O%<>-Nj@&RCa zRcTpLT1x%*&;C5})5wa_`A7+G$l$V}AVFS54NItD{&=Zp1-<=T6oof8l>Z literal 0 HcmV?d00001 diff --git a/daisy_main.py b/daisy_main.py index 43ba7b5..8ae8057 100644 --- a/daisy_main.py +++ b/daisy_main.py @@ -9,6 +9,8 @@ import keyboard import random import webbrowser +import wolframalpha + engine = pyttsx3.init("sapi5") voices = engine.getProperty("voices") @@ -147,6 +149,16 @@ def convert_to_datetime(alarm_time_str): elif "wikipedia" in query: from SearchNow import searchWikipedia searchWikipedia(query) + elif "news" in query: + from newsread import latest_news + latest_news() + elif "calculate" in query: + from Calculatenumbers import WolfRamAlpha + from Calculatenumbers import Calc + query = query.replace("calculate", "") + query = query.replace("Daisy", "") + Calc(query) + elif "temperature" in query: search = "temperature here is " url=f"https://www.google.com/search?q={search}" diff --git a/newsread.py b/newsread.py new file mode 100644 index 0000000..606b1a1 --- /dev/null +++ b/newsread.py @@ -0,0 +1,55 @@ +import requests +import json +import pyttsx3 + +engine = pyttsx3.init("sapi5") +voices = engine.getProperty("voices") +for voice in voices: + if "zira" in voice.name.lower(): + engine.setProperty("voice", voice.id) + break +engine.setProperty("rate", 170) +def speak(text): + engine.say(text) + engine.runAndWait() + +def latest_news(): + apidict = { + "business": "https://newsapi.org/v2/top-headlines?country=in&category=business&apiKey=3529f3b21a4c43c796e555937e7802f8", + "entertainment": "https://newsapi.org/v2/top-headlines?country=in&category=entertainment&apiKey=3529f3b21a4c43c796e555937e7802f8", + "health": "https://newsapi.org/v2/top-headlines?country=in&category=health&apiKey=3529f3b21a4c43c796e555937e7802f8", + "science": "https://newsapi.org/v2/top-headlines?country=in&category=science&apiKey=3529f3b21a4c43c796e555937e7802f8", + "sports": "https://newsapi.org/v2/top-headlines?country=in&category=sports&apiKey=3529f3b21a4c43c796e555937e7802f8", + "technology": "https://newsapi.org/v2/top-headlines?country=in&category=technology&apiKey=3529f3b21a4c43c796e555937e7802f8", + "general": "https://newsapi.org/v2/top-headlines?country=in&category=general&apiKey=3529f3b21a4c43c796e555937e7802f8" + } + + speak("Which news category would you like to hear? [business, entertainment, health, science, sports, technology, general]") + field = input("Which news category would you like to hear? [business, entertainment, health, science, sports, technology, general] : ").lower() + + url = apidict.get(field) + if not url: + speak("Invalid category") + return + + news = requests.get(url).text + news_dict = json.loads(news) + speak("Here are some top news headlines") + arts = news_dict["articles"] + for article in arts: + title = article["title"] + speak(title) + print(title) + news_url = article["url"] + print(f"For more info visit: {news_url}") + + a = input("Would you like to read more news? [yes/no] : ") + if a.lower() == "no": + break + else: + continue + speak("That's all for now") + + + +