Exemple #1
0
def log(today, yesterday):
    verbose("-------------")
    verbose("time", parse_timestamp(today["time"]))
    verbose("20MA today:", today["20MA"], ", yesterday: ", yesterday["20MA"])
    verbose("bw today:", today["bw"], ", yesterday: ", yesterday["bw"])
    verbose("transaction today:", today["transaction_count"], ", yesterday:",
            yesterday["transaction_count"])
Exemple #2
0
def data_filter(data):
    if len(data) < 4:
        return False

    i = len(data) - 3
    result = True
    while i < len(data) - 1:
        today = data[i]
        yesterday = data[i - 1]

        log(today, yesterday)

        if today["bw"] < yesterday["bw"] and abs(today["bw"] -
                                                 yesterday["bw"]) > 0.01:
            result = False

        verbose("%b:", today["b"])
        if today["b"] > 0.5:
            result = False
        i += 1

    today = data[-1]
    yesterday = data[-2]
    log(today, yesterday)
    if today["b"] < 0.5:
        result = False
    # and abs(today["bw"] - yesterday["bw"]) > 0.005:
    if today["bw"] < yesterday["bw"]:
        result = False

    return result
Exemple #3
0
 def logClassVars(self):
     """ Log class variables to stdout. """
     attrs = ['dirPath', 'curDirName', 'curFileNames', 'curNfoName', 'videoTags',
         'subtitles', 'title', 'year', 'country', 'aka', 'trailerUrl', 'newDirName',
         'newFileNames', 'newFilePrefix']
     for attr in attrs:
         log.verbose("  self.%s = %s" % (attr, getattr(self, attr)))
Exemple #4
0
    def pull(self):
        from_file = True
        raw = None
        try:
            raw = self.read()
        except EnvironmentError:
            from_file = False
            verbose("fail to read", self.stock_code)

        if raw is not None:
            if not self.check_valid(raw):
                from_file = False

        if not from_file:
            raw = self.download()
            self.write(raw)

        price_raw = self.extract_price_raw(raw)
        transaction_raw = self.extract_transaction_raw(raw)

        price_data = json.loads(price_raw)
        transaction_data = json.loads(transaction_raw)
        self.parse(price_data, transaction_data)
Exemple #5
0
    def do_job(self):
        queue = self.queue
        lock = self.lock
        last_date = self.date
        filters = self.filters

        while queue.empty() != True:
            code = queue.get()
            try:
                if not self.alive:
                    continue
                data_source = HiStock(code, last_date)
                data_source.pull()
                data = data_source.result
                with lock:
                    verbose(
                        "---------------------------------------------------------------------"
                    )
                    verbose("start checking", code)
                    pass_upperbound = False
                    pass_mean = False
                    if "upperBound" in filters:
                        pass_upperbound = upperbound.data_filter(data)
                    if "mean" in filters:
                        pass_mean = mean.data_filter(data)
                    if not (pass_mean or pass_upperbound):
                        verbose("fail", code)
                    else:
                        passed_filters = []
                        if pass_mean:
                            passed_filters.append("mean")
                        if pass_upperbound:
                            passed_filters.append("upperbound")
                        warning = ""
                        if not transaction.data_filter(data):
                            today = data[-1]
                            warning = "do not pass transaction, transaction count: {}, price: {}".format(
                                today["transaction_count"], today["price"])
                        link = graphlink(code)
                        print("{} success: {}, {}, {}".format(
                            code, ",".join(passed_filters), warning, link))
                        if warning == "":
                            self.messages.append(link)

            except Exception as exception:
                with lock:
                    print(exception)
                    print("error", code)
            finally:
                queue.task_done()
Exemple #6
0
 def logImdbVars(self):
     """ Log IMDB variables to stdout. """
     if (not self.imdbInfo):
         log.info("  No IMDB information.")
     for key in sorted(self.imdbInfo.keys()):
         log.verbose("  imdb['%s'] = %s" % (key, self.imdbInfo[key]))