Tasks To Automate With Python

https://miro.medium.com/max/1000/0*C2wlrq7NwbWsA44M

Original Source Here

pip install mac-say

Then create a python file to perform the task.

import sysimport mac_saymac_say.say(["-f", sys.argv[1], "-v", "Alex"])

Then just point to a file of your choosing on the command line.

python audiobook.py fileofyourchoice.txt

It is typically a fast thing to check the weather, but it may also be a little satisfied if a button is applied. Only one dependency is required for this.

pip install requests

Just create a file for the script below once you have installed it.

import sysimport requestsresp = requests.get(f'https://wttr.in/{sys.argv[1].replace(" ", "+")}')
print(resp.text)

You are then willing to run or plan the next day. The next day.

python weather.py "Your City"

All we have to do is instal the library as follows. This one is a bit easier.

pip install --user currencyconverter

To conduct a conversion, you only have to type the following as shown in the sample execution, this installation should place currency_converter in our $PATH.

currency_converter 1 USD --to EUR

We will just listen to pdf files, images, audio and videos in this example, but it will be fairly extensible and adequate to get you out. I’ve gone with this one a bit overboard.

import os
import time
import sysfrom watchdog.observers import Observer
from watchdog.events import FileSystemEventHandlerfolder_to_monitor = sys.argv[1]file_folder_mapping = {
'.png':'images',
'.jpg':'images',
'.jpeg':'images',
'.gif':'images',
'.pdf':'pdfs',
'.mp4':'videos',
'.mp3':'audio',
'.zip':'bundles'
}class DownloadedFileHandler(FileSystemEventHandler):
def on_created(self, event):
if any(event.src_path.endswith(x) for x in file_folder_mapping):
parent = os.path.join(os.path.dirname(os.path.abspath(event.src_path)), file_folder_mapping.get(f".{event.src_path.split('.')[-1]}"))
if not os.path.exists(parent):
os.makedirs(parent)
os.rename(event.src_path, os.path.join(parent, os.path.basename(event.src_path)))event_handler = DownloadedFileHandler()
observer = Observer()
observer.schedule(event_handler, folder_to_monitor, recursive=True)
print("Monitoring started")
observer.start()
try:
while True:
time.sleep(10)except KeyboardInterrupt:
observer.stop()
observer.join()

Once you build the file for this purpose, all you have to do is execute it to start monitoring your download directory.

python downloads-watchdog.py "/your/downloads/folder"

Usually in the morning, until the coffee arrives you want to accomplish very little. This script is begun earlier this morning by opening all the browser tabs that you normally like to open every morning. As illustrated in the following example, save a script file with the URL of your choosing.

python -m webbrowser -t "https://www.google.com"
python -m webbrowser -t "https://imsanjams.tk/"
python -m webbrowser -t "https://imsanjams.medium.com/"

AI/ML

Trending AI/ML Article Identified & Digested via Granola by Ramsey Elbasheer; a Machine-Driven RSS Bot

%d bloggers like this: