├── Chorus.wav ├── requirements.txt ├── README.md ├── weather_report.py ├── text_audio.py ├── LICENSE ├── audio_text.py ├── currency_converter.py ├── sort_downloads.py └── automate_email.py /Chorus.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/youssefHosni/Task-Automation-with-Python-ChatGPT/HEAD/Chorus.wav -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/youssefHosni/Task-Automation-with-Python-ChatGPT/HEAD/requirements.txt -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Task-Automation-with-Python-ChatGPT 2 | Automate boring tasks using Python scripts generated using ChatGPT 3 | -------------------------------------------------------------------------------- /weather_report.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import requests 3 | resp = requests.get(f'https://wttr.in/{sys.argv[1].replace(" ", "+")}') 4 | print(resp.text) 5 | -------------------------------------------------------------------------------- /text_audio.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from gtts import gTTS 3 | 4 | def convert_text_to_audio(text, output_file): 5 | # Create a gTTS object with the text and desired language 6 | tts = gTTS(text=text, lang='en') 7 | 8 | # Save the audio to a file 9 | tts.save(output_file) 10 | print(f"Audio file saved as {output_file}") 11 | 12 | if __name__ == "__main__": 13 | if len(sys.argv) < 3: 14 | print("Usage: python script.py ") 15 | sys.exit(1) 16 | 17 | text_file_path = sys.argv[1] 18 | output_audio_file = sys.argv[2] 19 | 20 | # Read the text from the file 21 | with open(text_file_path, 'r') as file: 22 | text = file.read() 23 | 24 | # Convert text to audio 25 | convert_text_to_audio(text, output_audio_file) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Youssef Hosni 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /audio_text.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import speech_recognition as sr 3 | 4 | def convert_audio_to_text(audio_file): 5 | # Initialize the recognizer 6 | r = sr.Recognizer() 7 | 8 | # Load the audio file 9 | with sr.AudioFile(audio_file) as source: 10 | # Read the audio data from the file 11 | audio_data = r.record(source) 12 | 13 | try: 14 | # Use the recognizer to convert audio to text 15 | text = r.recognize_google(audio_data) 16 | return text 17 | except sr.UnknownValueError: 18 | print("Speech recognition could not understand audio") 19 | except sr.RequestError as e: 20 | print(f"Could not request results from the speech recognition service; {e}") 21 | 22 | return None 23 | 24 | if __name__ == "__main__": 25 | if len(sys.argv) < 2: 26 | print("Usage: python script.py ") 27 | sys.exit(1) 28 | 29 | audio_file_path = sys.argv[1] 30 | 31 | # Convert audio to text 32 | result = convert_audio_to_text(audio_file_path) 33 | 34 | if result: 35 | # Print the converted text 36 | print(result) 37 | -------------------------------------------------------------------------------- /currency_converter.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | from forex_python.converter import CurrencyRates, CurrencyCodes 3 | 4 | # Initialize the currency rates and codes objects 5 | c = CurrencyRates() 6 | codes = CurrencyCodes() 7 | 8 | # Set up the argument parser 9 | parser = argparse.ArgumentParser(description="Convert currencies using forex-python") 10 | parser.add_argument("amount", type=float, help="The amount to convert") 11 | parser.add_argument("from_currency", type=str, help="The currency you're converting from (e.g. USD)", metavar="from") 12 | parser.add_argument("to_currency", type=str, help="The currency you're converting to (e.g. EUR)", metavar="to") 13 | 14 | # Parse the arguments 15 | args = parser.parse_args() 16 | 17 | # Get the amount and currencies from the arguments 18 | amount = args.amount 19 | from_currency = args.from_currency.upper() 20 | to_currency = args.to_currency.upper() 21 | 22 | # Get the currency symbols for display purposes 23 | from_symbol = codes.get_symbol(from_currency) 24 | to_symbol = codes.get_symbol(to_currency) 25 | 26 | # Convert the currencies 27 | result = c.convert(from_currency, to_currency, amount) 28 | 29 | # Print the result 30 | print(f"{from_symbol}{amount:.2f} {from_currency} is equal to {to_symbol}{result:.2f} {to_currency}") 31 | -------------------------------------------------------------------------------- /sort_downloads.py: -------------------------------------------------------------------------------- 1 | 2 | import sys 3 | import os 4 | import time 5 | from watchdog.observers import Observer 6 | from watchdog.events import FileSystemEventHandler 7 | 8 | folder_to_monitor = sys.argv[1] 9 | 10 | file_folder_mapping = { 11 | ".png": "images", 12 | ".jpg": "images", 13 | ".jpeg": "images", 14 | ".gif": "images", 15 | ".pdf": "pdfs", 16 | ".mp4": "videos", 17 | ".mp3": "audio", 18 | ".zip": "bundles", 19 | } 20 | 21 | class DownloadedFileHandler(FileSystemEventHandler): 22 | def on_created(self, event): 23 | if any(event.src_path.endswith(x) for x in file_folder_mapping): 24 | parent = os.path.join( 25 | os.path.dirname(os.path.abspath(event.src_path)), 26 | file_folder_mapping.get(f".{event.src_path.split('.')[-1]}"), 27 | ) 28 | if not os.path.exists(parent): 29 | os.makedirs(parent) 30 | os.rename( 31 | event.src_path, os.path.join(parent, os.path.basename(event.src_path)) 32 | ) 33 | event_handler = DownloadedFileHandler() 34 | 35 | observer = Observer() 36 | observer.schedule(event_handler, folder_to_monitor, recursive=True) 37 | print("Monitoring started") 38 | observer.start() 39 | try: 40 | while True: 41 | time.sleep(10) 42 | except KeyboardInterrupt: 43 | observer.stop() 44 | observer.join() -------------------------------------------------------------------------------- /automate_email.py: -------------------------------------------------------------------------------- 1 | import smtplib 2 | from email.mime.multipart import MIMEMultipart 3 | from email.mime.text import MIMEText 4 | 5 | def send_email(sender_email, sender_password, recipient_emails, subject, message): 6 | # Set up the SMTP server details 7 | smtp_server = 'smtp.gmail.com' 8 | smtp_port = 587 9 | 10 | # Create a multipart message 11 | msg = MIMEMultipart() 12 | msg['From'] = sender_email 13 | msg['To'] = ', '.join(recipient_emails) 14 | msg['Subject'] = subject 15 | 16 | # Attach the message as plain text 17 | msg.attach(MIMEText(message, 'plain')) 18 | 19 | try: 20 | # Connect to the SMTP server 21 | server = smtplib.SMTP(smtp_server, smtp_port) 22 | server.starttls() 23 | 24 | # Log in to the sender's email account 25 | server.login(sender_email, sender_password) 26 | 27 | # Send the email 28 | server.send_message(msg) 29 | print('Email sent successfully') 30 | 31 | except smtplib.SMTPException as e: 32 | print(f'Error: Unable to send email. {str(e)}') 33 | 34 | finally: 35 | # Disconnect from the SMTP server 36 | server.quit() 37 | 38 | # Provide the email details 39 | sender_email = 'your_email@gmail.com' 40 | sender_password = 'your_password' 41 | recipient_emails = ['recipient1@example.com', 'recipient2@example.com'] 42 | subject = 'Automated Email' 43 | message = 'This is an automated email sent using Python.' 44 | 45 | # Send the email 46 | send_email(sender_email, sender_password, recipient_emails, subject, message) --------------------------------------------------------------------------------