from classes import API
from utils import Utils


class Update:
    def getTasks(self):
        ut = Utils()
        temp = ut.requestString("user::::pass::::uhash",
                                self.api.getUsername() + "::::" + self.api.getPassword() + "::::" + "userHash_not_needed",
                                "vh_tasks.php")
        return temp

    def SpywareInfo(self):
        ut = Utils()
        arr = ut.requestArray("user::::pass::::uhash:::::",
                              self.api.getUsername() + "::::" + self.api.getPassword() + "::::" + "UserHash_not_needed" + ":::::",
                              "vh_spywareInfo.php")
        return arr

    def removeSpyware(self):
        ut = Utils()
        arr = ut.requestArray("user::::pass::::uhash:::::",
                              self.api.getUsername() + "::::" + self.api.getPassword() + "::::" + "UserHash_not_needed" + ":::::",
                              "vh_removeSpyware.php")
        return arr

    def getTaskAmount(self):
        ut = Utils()
        temp = self.getTasks()
        return len(temp.split("taskid")) - 1

    def getTaskIDs(self):
        temp = self.getTasks()
        tasks = temp.split('"taskid":"')[1:]
        n = []
        for i1 in tasks:
            n.append(i1.split('"')[0])
        return n

    def startTask(self, type):
        ut = Utils()
        temp = ut.requestString("user::::pass::::uhash::::utype",
                                self.api.getUsername() + "::::" + self.api.getPassword() + "::::" + "userHash_not_needed" + "::::" + type,
                                "vh_addUpdate.php")
        if "result" in temp:
            return temp.split('result":"')[1].split('"')[0]
        return "2"

    def botnetInfo(self):
        ut = Utils()
        temp = ut.requestString("user::::pass::::uhash",
                                self.api.getUsername() + "::::" + self.api.getPassword() + "::::" + "userHash_not_needed",
                                "vh_botnetInfo.php")
        return temp

    def upgradeBotnet(self, ID):
        ut = Utils()
        temp = ut.requestString("user::::pass::::uhash::::bID",
                                self.api.getUsername() + "::::" + self.api.getPassword() + "::::" + "userHash_not_needed" + "::::" + ID,
                                "vh_upgradeBotnet.php")
        return temp

    def finishTask(self, taskID):
        ut = Utils()
        temp = ut.requestString("user::::pass::::uhash::::taskid",
                                self.api.getUsername() + "::::" + self.api.getPassword() + "::::" + "userHash_not_needed" + "::::" + taskID,
                                "vh_finishTask.php")
        if "4" in temp:
            return True
        else:
            return False

    def finishAll(self):
        ut = Utils()
        temp = ut.requestString("user::::pass::::uhash",
                                self.api.getUsername() + "::::" + self.api.getPassword() + "::::" + "userHash_not_needed",
                                "vh_finishAll.php")
        if "0" in temp:
            return True
        else:
            return False

    def useBooster(self):
        ut = Utils()
        temp = ut.requestString("user::::pass::::uhash::::boost",
                                self.api.getUsername() + "::::" + self.api.getPassword() + "::::" + "userHash_not_needed" + "::::" + "1",
                                "vh_tasks.php")
        return temp

    def __init__(self, api):
        self.api = api

@@ -57,16 +57,34 @@
 Update:%0A
+%0A    ut= Utils()%0A%0A
     def 
@@ -99,37 +99,16 @@
 (self):%0A
-        ut = Utils()%0A
         
@@ -105,32 +105,37 @@
 :%0A        temp =
+self.
  ut.requestStrin
@@ -380,37 +380,16 @@
 (self):%0A
-        ut = Utils()%0A
         
@@ -386,32 +386,37 @@
 :%0A        arr = 
+self.
 ut.requestArray(
@@ -677,37 +677,16 @@
 (self):%0A
-        ut = Utils()%0A
         
@@ -691,16 +691,21 @@
   arr = 
+self.
 ut.reque
@@ -976,37 +976,16 @@
 (self):%0A
-        ut = Utils()%0A
         
@@ -1283,37 +1283,16 @@
  type):%0A
-        ut = Utils()%0A
         
@@ -1289,32 +1289,37 @@
 :%0A        temp =
+self.
  ut.requestStrin
@@ -1680,37 +1680,16 @@
 (self):%0A
-        ut = Utils()%0A
         
@@ -1686,32 +1686,37 @@
 :%0A        temp =
+self.
  ut.requestStrin
@@ -1972,37 +1972,16 @@
 f, ID):%0A
-        ut = Utils()%0A
         
@@ -1978,32 +1978,37 @@
 :%0A        temp =
+self.
  ut.requestStrin
@@ -2289,37 +2289,16 @@
 askID):%0A
-        ut = Utils()%0A
         
@@ -2295,32 +2295,37 @@
 :%0A        temp =
+self.
  ut.requestStrin
@@ -2668,37 +2668,16 @@
 (self):%0A
-        ut = Utils()%0A
         
@@ -2674,32 +2674,37 @@
 :%0A        temp =
+self.
  ut.requestStrin
@@ -3023,29 +3023,8 @@
 f):%0A
-        ut = Utils()%0A
     
@@ -3033,16 +3033,21 @@
   temp =
+self.
  ut.requ

remove ut = Utils from each function def and place in class variable.