Completed
Push — master ( 72b331...d4b7d2 )
by Steffen
02:14
created

kuon.watcher.adapters.bitskins.parser.sold_history   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 19
dl 0
loc 34
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A SoldHistoryParser.parse() 0 20 3
1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3
4
import json
5
6
from kuon.api_response import APIResponse
7
from kuon.watcher.adapters.models.sold_history import SoldHistory
8
from kuon.watcher.adapters.models.sold_item import SoldItem
9
10
11
class SoldHistoryParser:
12
    """Parser class to parse the response of the sold history to the unified format"""
13
14
    @staticmethod
15
    def parse(results):
16
        """Parse the sold history model
17
18
        :param results:
19
        :return:
20
        """
21
        response = SoldHistory(success=results['status'] == 'success')
22
        for item in results['data']['sales']:
23
            wear = item['wear_value']
24
            if wear is None:
25
                wear = -1.0
26
27
            sold_item = SoldItem(
28
                price=int(float(item['price']) * 100),
29
                wear_value=float(wear),
30
                sold_at=int(item['sold_at'])
31
            )
32
            response.add_sale(sold_item)
33
        return APIResponse(json.dumps(response.__dict__))
34