示例#1
0
 def json(self, active=True):
     return {
         "deck_id":
         self.pk,
         "trump":
         self.trump,
         "hands": [
             hand.json(active=active)
             for hand in self.hands.filter(active=active)
         ],
         "next_move":
         self.next_move,
         "total_moves":
         self.total_moves,
         "total_team01":
         self.total_team01,
         "total_team02":
         self.total_team02,
         "label":
         self.label,
         "active":
         self.active,
         "timestamp":
         dt_to_timestamp(self.timestamp),
     }
示例#2
0
 def list_json(self):
     return {
         "room_id": self.pk,
         "timestamp": dt_to_timestamp(self.timestamp),
         "setting": self.owner.game_setting.json(),
         "started": self.started,
     }
示例#3
0
 def json(self, active=True):
     return {
         "hand_id": self.pk,
         "cards":
         [card.json() for card in self.cards.filter(active=active)],
         "active": self.active,
         "timestamp": dt_to_timestamp(self.timestamp),
     }
示例#4
0
 def json(self):
     return {
         "id": self.pk,
         "timestamp": dt_to_timestamp(self.timestamp),
         "sending": self.sending,
         "receiving": self.receiving,  # Halyk bank course
         "data_and_time": self.data_and_time,
     }
示例#5
0
 def json(self, active=True):
     return {
         "move_id": self.pk,
         "user_id": self.user_id,
         "card_id": self.card_id,
         "first_move": self.first_move,
         "active": self.active,
         "timestamp": dt_to_timestamp(self.timestamp),
     }
示例#6
0
 def json(self):
     return {
         "card_id": self.pk,
         "name": self.name,
         "value": self.value,
         "worth": self.worth,
         "image_url": get_url(path=self.image_url),
         "trump_priority": self.trump_priority,
         "active": self.active,
         "timestamp": dt_to_timestamp(self.timestamp),
     }
示例#7
0
 def json(self, user=None):
     return {
         "setting_id": self.pk,
         "user_id": self.owner_id,
         "on_save": self.on_save,
         "on_save_display": self.get_on_save_display(),
         "on_full": self.on_full,
         "on_full_display": self.get_on_full_display(),
         "ace_allowed": self.ace_allowed,
         "on_eggs": self.on_eggs,
         "on_eggs_display": self.get_on_eggs_display(),
         "timestamp": dt_to_timestamp(self.timestamp),
     }
示例#8
0
 def json(self):
     return {
         "room_id":
         self.pk,
         "owner_id":
         self.owner_id,
         "user01_id":
         self.user01_id,
         "user01_ready":
         self.user01_ready,
         "user02_id":
         self.user02_id,
         "user02_ready":
         self.user02_ready,
         "user03_id":
         self.user03_id,
         "user03_ready":
         self.user03_ready,
         "user04_id":
         self.user04_id,
         "user04_ready":
         self.user04_ready,
         "all_ready":
         self.all_ready,
         "has_jack_of_clubs":
         self.has_jack_of_clubs,
         "trump_is_hidden":
         self.trump_is_hidden,
         "full":
         self.full,
         "total_team01":
         self.total_team01,
         "total_team02":
         self.total_team02,
         "active":
         self.active,
         "timestamp":
         dt_to_timestamp(self.timestamp),
         "setting":
         self.owner.game_setting.json(),
         "started":
         self.started,
         "current_label":
         self.current_label,
         "last_deck":
         self.decks.filter(active=True,
                           label=self.current_label).last().json()
         if self.decks.filter(
             active=True, label=self.current_label).count() > 0 else None,
     }
示例#9
0
def converter_v2(request):
    """
        return result of exchanges
        but not parsing at every call
    """
    now = datetime.datetime.now()
    delta = datetime.timedelta(hours=9)
    now = now + delta

    five_minutes = datetime.timedelta(minutes=5)
    last_object = Exchange.objects.last()
    last_object_time = last_object.timestamp

    from utils.time_utils import dt_to_timestamp
    if dt_to_timestamp(
        (now - five_minutes)) < dt_to_timestamp(last_object_time):
        return last_object.json()
# Otherwise return the NEW PARSED RESULT
    new_now = datetime.datetime.now() + datetime.timedelta(hours=9)
    year = str(new_now.year)
    month = '{:02d}'.format(new_now.month)
    day = '{:02d}'.format(new_now.day)

    import requests
    payload = {
        'BAS_DT': year + month + day,
        'NAT_CODE': 'USD',
        'DIS': 1,
        'INQ_DIS': 'USD',
    }

    url = 'https://spib.wooribank.com/spd/jcc?withyou=ENENG0432&__ID=c010895'

    response = requests.post(
        url=url,
        data=payload,
        headers={'Content-Type': 'application/x-www-form-urlencoded'})

    result = response.text

    l = result.index("<dd>") + len("<dd>")
    current_year = result[l:(l + 4)]
    current_month = result[(l + 5):(l + 7)]
    current_day = result[(l + 8):(l + 10)]

    payload = {
        'BAS_DT': current_year + current_month + current_day,
        'NAT_CODE': 'USD',
        'DIS': 1,
        'INQ_DIS': 'USD',
    }

    response = requests.post(
        url=url,
        data=payload,
        headers={'Content-Type': 'application/x-www-form-urlencoded'})

    while response.text.find(
            "Currently, there is no notification. Please try again late.") > 0:
        current_year, current_month, current_day = previous_date_fn(
            current_year, current_month, current_day)

        data = {
            'BAS_DT': current_year + current_month + current_day,
            'NAT_CODE': 'USD',
            'DIS': 1,
            'INQ_DIS': 'USD',
        }

        response = requests.post(
            url=url,
            data=data,
            headers={'Content-Type': 'application/x-www-form-urlencoded'})

    result = response.text

    body = result[(result.index("<tbody>") +
                   len("<tbody>")):result.index("</tbody>")]

    row = body[(body.index("<tr>") + len("<tr>")):(body.index("</tr>"))]

    while row.find(",") > 0:
        row = row[:row.find(",")] + row[row.find(",") + 1:]

    row = row[row.find("</td>") + len("</td>"):]
    row = row[row.find("<td>") + len("<td>"):]

    j = 0
    while row[j] not in doubles:
        j = j + 1
    current_time = row[j:j + 8]
    row = row[(j + 8):]
    row = row[row.index("<td>") + len("<td>"):]

    j = 0
    while row[j] not in doubles:
        j = j + 1
    k = j
    while row[k] in doubles:
        k = k + 1

    ############################################################################################
    url = "https://ifin.kz/bank/halykbank/currency-rate/astana"
    response = requests.get(
        url=url,
        params=None,
        headers={'Content-Type': 'application/x-www-form-urlencoded'})

    result = response.text

    body = result[(result.index("tbl-td rate-value")):(
        result.index("tbl-td rate-value") + 500)]
    body = body[body.index(">"):]

    kj = 0
    while kj < len(body) and body[kj] not in kazakh_doubles:
        kj = kj + 1
    kk = kj
    while kk < len(body) and body[kk] in kazakh_doubles:
        kk = kk + 1
    body_copy = body
    for iii in range(kj, kk):
        if body_copy[iii] == ',':
            body_copy[iii] = "."

    receiving = float(body[kj:kk])

    ############################################################################################

    sending = float(row[j:k])
    last_exchange = Exchange.objects.last()
    last_exchange.sending = sending
    # last_exchange.receiving = receiving
    last_exchange.data_and_time = current_day + "." + current_month + "." + current_year + " " + current_time
    last_exchange.timestamp = new_now
    last_exchange.receiving = receiving
    last_exchange.save()

    return last_exchange.json()