| 53 | return completion.choices[0].message.content |
| 54 | |
| 55 | def processCommand(c): |
| 56 | if "open google" in c.lower(): |
| 57 | webbrowser.open("https://google.com") |
| 58 | elif "open facebook" in c.lower(): |
| 59 | webbrowser.open("https://facebook.com") |
| 60 | elif "open youtube" in c.lower(): |
| 61 | webbrowser.open("https://youtube.com") |
| 62 | elif "open linkedin" in c.lower(): |
| 63 | webbrowser.open("https://linkedin.com") |
| 64 | elif c.lower().startswith("play"): |
| 65 | song = c.lower().split(" ")[1] |
| 66 | link = musicLibrary.music[song] |
| 67 | webbrowser.open(link) |
| 68 | |
| 69 | elif "news" in c.lower(): |
| 70 | r = requests.get(f"https://newsapi.org/v2/top-headlines?country=in&apiKey={newsapi}") |
| 71 | if r.status_code == 200: |
| 72 | # Parse the JSON response |
| 73 | data = r.json() |
| 74 | |
| 75 | # Extract the articles |
| 76 | articles = data.get('articles', []) |
| 77 | |
| 78 | # Print the headlines |
| 79 | for article in articles: |
| 80 | speak(article['title']) |
| 81 | |
| 82 | else: |
| 83 | # Let OpenAI handle the request |
| 84 | output = aiProcess(c) |
| 85 | speak(output) |
| 86 | |
| 87 | |
| 88 | |