@@ -70,26 +70,41 @@ except urllib2.HTTPError, e:
7070** Script:**
7171
7272``` python
73- import clr
73+ import clr;
74+ import System;
7475import urllib2
7576import urllib
76-
77- clr.AddReference(" TCAdmin.GameHosting.SDK" )
78- from TCAdmin.GameHosting.SDK .Objects import Service
79-
80- WHMCS_URL = " https://your-whmcs-site.com/includes/api.php"
77+
78+ WHMCS_URL = ' https://your-whmcs-site.com/includes/api.php'
8179WHMCS_API_IDENTIFIER = " xxxxxxx"
8280WHMCS_API_SECRET = " yyyyyyy"
83-
84- AllServices = Service.GetServices()
85-
81+ WHMCS_API_ACCESS_KEY = " "
82+
83+ clr.AddReference(" TCAdmin.GameHosting.SDK" )
84+ from System import String
85+ from TCAdmin.GameHosting.SDK .Objects import Service, Server, Game
86+
87+ # Check if run as a scheduled task. We check if ThisTaskStep.WriteLog is callable. If it is, set WriteLog = ThisTaskStep.WriteLog. If it is not, set WriteLog = WriteLog.
88+ try :
89+ ThisTaskStep.WriteLog
90+ except NameError :
91+ WriteLog1 = Script.WriteToConsole
92+ else :
93+ WriteLog1 = ThisTaskStep.WriteLog
94+
95+ def WriteLog (msg ):
96+ WriteLog1(" [{0} ] {1} " .format(ThisService.ServiceId, msg))
97+
98+ AllServices = list (filter (lambda s : s.BillingId != " " , Service.GetServices()))
99+
86100for ThisService in AllServices:
87- Script.WriteToConsole(" Updating " + ThisService.ConnectionInfo)
88- query = urllib.urlencode({' action' : ' UpdateClientProduct' , ' username' : WHMCS_API_IDENTIFIER , ' password' : WHMCS_API_SECRET , ' serviceid' : ThisService.BillingId, ' domain' : ThisService.ConnectionInfo, ' responsetype' : ' json' })
89101 try :
90- urllib2.urlopen(WHMCS_URL , data = query)
102+ query = urllib.urlencode({' action' : ' UpdateClientProduct' , ' username' : WHMCS_API_IDENTIFIER , ' password' : WHMCS_API_SECRET , ' accesskey' : WHMCS_API_ACCESS_KEY , ' serviceid' : ThisService.BillingId, ' domain' : ThisService.ConnectionInfo, ' responsetype' : ' json' })
103+ response = urllib2.urlopen(WHMCS_URL , data = query)
104+ content = response.read()
105+ Script.WriteToConsole(content)
91106 except urllib2.HTTPError, e:
92- Script.WriteToConsole( " Error updating " + ThisService.ConnectionInfo + " : " + str (e.code) + " " + e.reason )
107+ WriteLog(e.ToString() )
93108```
94109
95110:::note
0 commit comments