from celery.task import Task
from celery.utils.log import get_task_logger
import requests


logger = get_task_logger(__name__)


class Hotsocket_Login(Task):

    """
    Task to get the username and password varified then produce a token
    """
    name = "gopherairtime.recharges.tasks.hotsocket_login"

    def run(self, **kwargs):
        """
        Returns the token
        """
        l = self.get_logger(**kwargs)
        l.info("Logging into hotsocket")
        auth = {'username': 'trial_acc_1212', 'password': 'tr14l_l1k3m00n',
                'as_json': True}
        r = requests.post("http://api.hotsocket.co.za:8080/test/login",data=auth)
        result = r.json()
        return result["response"]["token"]

hotsocket_login = Hotsocket_Login()

@@ -1,20 +1,70 @@
+import requests%0A%0Afrom django.conf import settings%0A
 from celery.task imp
@@ -117,32 +117,44 @@
 _logger%0A
-import requests%0A
+%0Afrom .models import Account
 %0A%0Alogger
@@ -660,52 +660,79 @@
 st(%22
-http://api.hotsocket.co.za:8080/test/login%22,
+%25s/login%22 %25 settings.HOTSOCKET_API_ENDPOINT,%0A                          
 data
@@ -776,14 +776,15 @@
     
-return
+token =
  res
@@ -807,16 +807,117 @@
 %22token%22%5D
+%0A        account = Account()%0A        account.token = token%0A        account.save()%0A        return True
 %0A%0Ahotsoc

Refactor the task for getting token to store it in DB