forked from kannibalox/PtpUploader
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Notifier.py
41 lines (31 loc) · 1.18 KB
/
Notifier.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import configparser
import os
import sys
from .MyGlobals import MyGlobals
from .Ptp import Ptp
from .Settings import Settings
def LoadNotifierSettings():
configParser = configparser.ConfigParser()
configParser.optionxform = str # Make option names case sensitive.
# Load Notifier.ini from the same directory where PtpUploader is.
settingsDirectory, moduleFilename = os.path.split( __file__ ) # __file__ contains the full path of the current running module
settingsPath = os.path.join( settingsDirectory, "Notifier.ini" )
fp = open( settingsPath, "r" )
configParser.readfp( fp )
fp.close()
return configParser.get( "Settings", "UserId" )
def Notify(releaseName, uploadedTorrentUrl):
logger = MyGlobals.Logger
userId = LoadNotifierSettings()
userId = userId.strip()
if not userId.isdigit():
return
Ptp.Login()
subject = "[PtpUploader] %s" % releaseName
message = "This is an automatic notification about a new [url=%s]upload[/url]." % uploadedTorrentUrl
Ptp.SendPrivateMessage( userId, subject, message )
if __name__ == "__main__":
Settings.LoadSettings()
MyGlobals.InitializeGlobals( Settings.WorkingPath )
if len( sys.argv ) == 3:
Notify( sys.argv[ 1 ], sys.argv[ 2 ] )