Exemple #1
0
    def get_stations(self):
        c.logging('Begin load stations info')

        # проверяем есть ли у нас файл с информацией о системах, если нет - скачиваем
        if not os.path.exists(c.station_data_file):
            c.logging('Can\'t find station data file. Load it from www.davek.com.au')
            c.get_web_object(c.station_data_url, c.station_data_file)
            c.logging('Load station data file comlete')

        stp = c.stationpattern

        f = open(c.station_data_file, 'r')

        while True:
            # читаем файл построчно
            line = f.readline()
            if not line: break

            # обрезаем перенос строки в конце
            line = line[0:-1]

            if stp.search(line):
                search_result = stp.search(line).groups()

                tmp_system = search_result[0].lower()
                tmp_station = search_result[1].lower()

                if tmp_system not in self.cache_data[c.cd_st]:
                    self.cache_data[c.cd_st][tmp_system] = {}

                self.cache_data[c.cd_st][tmp_system][tmp_station] = search_result[2:]

        f.close()
        c.logging('Finish load stations info')
Exemple #2
0
    def get_systems(self):
        c.logging('Begin load systems info')
        # проверяем есть ли у нас файл с информацией о системах, если нет - скачиваем
        if not os.path.exists(c.system_data_file):
            c.logging('Can\'t find system data file. Load it from www.davek.com.au')
            c.get_web_object(c.system_data_url, c.system_data_file)
            c.logging('Load system data file comlete')

        smp = c.systemspattern

        f = open(c.system_data_file, 'r')

        while True:
            # читаем файл построчно
            line = f.readline()
            if not line: break

            # обрезаем перенос строки в конце
            line = line[0:-1]

            if smp.search(line):
                self.cache_data[c.cd_sm][str((smp.search(line).groups())[0].lower())] = (smp.search(line).groups())[1:]

        f.close()
        c.logging('Finish load systems info')
Exemple #3
0
    def get_price(self):

        c.logging('Begin load price info')

        # проверяем есть ли у нас файл с информацией о ценах, если нет - скачиваем
        # TODO: сделать проверку на актуальность файла и перезакачивать, если он протух
        if not os.path.exists(c.station_price_file):
            c.logging('Can\'t find price data file. Load it from www.davek.com.au')
            c.get_web_object(c.station_price_url, c.station_price_file)
            c.logging('Load price data file comlete')

        pp = c.pricepattern
        ps = c.pricepattern_system_line
        sdp = c.sd_pattern
        system_name = ''
        station_name = ''

        f = open(c.station_price_file, 'r')

        while True:
            # читаем файл построчно
            line = f.readline()
            if not line: break
            # обрезаем перенос строки в конце
            line = line[0:-1]

            if ps.search(line):
                # если строка содержит систему и станцию, парсим ее
                system_name = ((ps.search(line).groups())[0]).lower()
                station_name = ((ps.search(line).groups())[1]).lower()
                # проверяем станцию на размер и наоичие в кеше станций
                if system_name not in self.cache_data[c.cd_st] or \
                   station_name not in self.cache_data[c.cd_st][system_name] or \
                   (self.cache_data[c.cd_st][system_name][station_name])[2] != 'L':
                    # если размер не подходит, оставляем систему и станцию незаполненными. 
                    # это и будет одним из признаком сохранять товар или нет
                    system_name = ''
                    station_name = ''
                else:
                    # если по размеру проходит, создаем структуру в словаре (если ее еще нет)
                    if system_name not in self.cache_data[c.cd_pr]:
                        self.cache_data[c.cd_pr][system_name] = {}
                    if station_name not in self.cache_data[c.cd_pr][system_name]:
                        self.cache_data[c.cd_pr][system_name][station_name] = {}

            elif system_name != '' and station_name != '' and pp.search(line):
                product = ((pp.search(line).groups())[0]).lower()
                sell = (pp.search(line).groups())[1]
                buy = (pp.search(line).groups())[2]
                demand = (pp.search(line).groups())[3]
                stock = (pp.search(line).groups())[4]
                timestamp = (pp.search(line).groups())[5]

                if demand == '?' or demand == '-':
                    demand = -1
                
                if stock == '?' or stock == '-':
                    stock = -1

                if sdp.search(str(demand)):
                    demand = (sdp.search(str(demand)).groups())[0]

                if sdp.search(str(stock)):
                    stock = (sdp.search(str(stock)).groups())[0]

                self.cache_data[c.cd_pr][system_name][station_name][product] = (sell, buy, demand, stock, timestamp)
            else:
                pass
        # ----------------------------------------------------------------------------------------------------------
        f.close()
        c.logging('End load price info')