Beispiel #1
0
    def handle_file(self, file_name):
        """ Handle a file
            :param file_name: The filename to process
            :return: None
        """
        dir_name = os.path.dirname(file_name.path)
        basename = os.path.basename(file_name.path)
        path = CC_BASE + self.ROOT_PATH + "/" + os.path.abspath(dir_name)
        path = path.replace('//', '/')

        if not os.path.exists(path):
            os.makedirs(path)

        open_file = open(os.path.join(path, basename + HTML.FILE_EXT), "w")

        source_data = File.read_file(self.script_base + file_name.path)

        last_pos = dir_name.rfind("/")

        html_link = HTML.get_link(CC_BASE, "root", "") + \
            HTML.get_link(path, dir_name[last_pos + 1:], basename)

        open_file.write(HTML.get_header(html_link, HTML.SRC_PREFIX))

        processing_line = 1
        previous_line_is_continued = False

        for line in source_data.splitlines():
            line = line.decode("utf-8")
            line = line.replace("&", "&")
            line = line.replace(">", ">")
            line = line.replace("<", "&lt;")
            line = line.replace('"', '&quot;')

            line_covered = processing_line in file_name.lines and \
                Code.line_is_code(line) or \
                processing_line > 1 and \
                previous_line_is_continued

            if line_covered:
                span_class = "covered"
            elif Code.line_is_code(line):
                span_class = "not_covered"
            else:
                span_class = "not_code"

            line_to_save = HTML.get_html(
                HTML.LINE_SOURCE) % (processing_line, span_class, line)

            open_file.write(line_to_save)

            previous_line_is_continued = True if line.endswith("\\") else False
            processing_line = processing_line + 1

        open_file.write(
            HTML.get_html(HTML.SRC_SUFFIX) + HTML.get_footer(
                file_name.total_lines, file_name.covered_lines, False))
Beispiel #2
0
    def getKline(period, symbol , var_time_hour_period ,  count = 200):
        now_datetime = datetime.now()
        hours_before = now_datetime + timedelta(hours=-count)

        bitmex_hour =  hours_before.strftime('%Y-%m-%dT%H:%M:%S.%fZ')

        #print now_datetime , hours_before , bitmex_hour
        url = "https://www.bitmex.com/api/v1/trade/bucketed?binSize=%s&partial=false&symbol=%s&count=%s&reverse=false&startTime=%s" % ( period , symbol , str(count), bitmex_hour )

        #print url

        data = HTML.get_html(url)
        #print data 
        #data = gzip_uncompress(data)
        #print data 

        if len(data) > 0:
            data = json.loads(data)

            #print data[-1]
            while len(data) > 0 and (getHour(data[-1]["timestamp"]) % var_time_hour_period) != 0:
                data = data[:-1]

            #print data 
            #ret = [ (x["close"] , x["timestamp"] , getHour(x["timestamp"])) for x in data]
            #print ret
            ret = [ x["close"] for x in data]
            # print "ret_data:" , data , len(data)
            return ret
        else:
            return []