I download a lot of linux ISOs torrents from the internet. I have made my own little python script that will send a notification to my iPhone about the details of the torrent that has finished downloading. Sends me the name, label and size of the torrent.
I use a python library called Pushbullet.py to send the notifications to my phone.
import os , sys, string, time, random
from datetime import datetime
from os import linesep
from pushbullet import Pushbullet
#Random Sys.Argv replacements
names = ['ubuntu-16.04.1-desktop-amd64.iso', 'Kali-Linux', 'Linux-Mind', 'dog', 'Arch-Linux']
labels = ['Movie', 'TV Show', 'Music', 'Program' ,'Game', 'eBook']
sizes = ['5000000000', '2000000000', '777758998000']
name_rand = (random.choice(names))
label_rand = (random.choice(labels))
sizes_rand = (random.choice(sizes))
#System arguments passed from qBittorrent to this script. This usually should be sys.argv[1-3] but changed for this case.
torrent_name = name_rand
torrent_category = label_rand
torrent_size = sizes_rand
qbittorrent_byte = Decimal(torrent_size)
mebibyte_divisor = Decimal(1048576)
mebibyte_value = qbittorrent_byte / mebibyte_divisor
mebibyte_string = str(round(mebibyte_value,2))
#Pushbullet Config
pb = Pushbullet("API-KEY")
iPhone = pb.devices[0]
t = time.localtime()
date_run = time.asctime(t)
#Pushbullet message templates
pb_title = torrent_category + " Download Completed"
pb_message = "Torrent: " + torrent_name + "\n" + "Size: " + mebibyte_string + " MB" + "\n" + "Label: " + torrent_category + "\n" + "Run on: " + date_run
pb_debug = date_run + "\n" + "Torrent: " + torrent_name + "\n" + "Size: " + mebibyte_string + " MB" + "\n" + "Label: " + torrent_category
def Send_Push():
push = iPhone.push_note(pb_title, pb_message)
print "PUSH sent successfully"
def write_file():
file = open("debug.txt", "a")
pb_message_debug = date_run + "\n" + "Torrent: " + torrent_name + "\n" + "Size: " + mebibyte_string + " MB" + "\n" + "Label: " + torrent_category
file.write(pb_message_debug + "\n")
file.close()
Send_Push()
write_file()
This script can be used to send test messages to my phone. When I save this file to the desktop and run it using CMD, it sends the message to my phone and even write the debug.txt file as it is supposed to.
But when I try to configure qBittorrent to run the script whenever a download has finished, it sends the message to my phone, but does not append to the debug.txt file.
Whenever I try to run the script using the CMD, it totally works. Sends the message to my phone and appends to debug.txt
It is my theory that qBittorrent is why I am getting IO Error 13 Permission Denied..
Help a guy out? Open to any changes..
The problem most probably is that you are specifying the path of the debug.txt file relatively. The following line will create a file in the current working directory named debug.txt
.
file = open("debug.txt", "a")
If your torrent app runs the script using a working directory that you don't have write access to by default (e.g. your programs folder), you will get a permission denied error.
Try to change the path to something absolute (a location where you have write access, e.g. your home folder):
file = open(r"C:\users\your_username_here\debug.txt", "a")
This should fix the issue.