def prepare_loaded_data(self, file_name): """ Przygotowuje i wczytuje dane z pliku :param file_name: plik z danymi :return: """ #utworzenie bufora buff = Buffer() data = CsvReader.read_from_file(file_name, 1) #zmiana czasu data = DataOperation.change_time_relative(data) #zmiana wysokosci na metry data = DataOperation.change_altitude_cm_m(data) #stworzenie zapisywacza saver = FileSaver("saved_data/dane.txt") #kazda linijke z pliku csv buforujemy osobno for d in data: buff.set_data(d) buffered_data = buff.get_data() #sprawdzamy czy kazda linijka jest poprawnie zapisana if InputValidator.input_val(buffered_data): #zapisujemy kazda linijke do nowego pliku saver.save_data(buffered_data) #odczyt danych z pliku csv i wizualizacja r_data = CsvReader.read_from_file(saver.get_file_name()) #tworzymy wizualizator, drugi parametr do interwal czasowy self.visualizer = PlotCreator(r_data, 1) self.data_loaded = True print "Dane zaladowane"
def __init__(self, log_level=logging.INFO): # setup logger self.logger = logging.getLogger("mylogger") self.logger.setLevel(log_level) fomatter = logging.Formatter( '[%(levelname)-5s]%(filename)-15s:%(lineno)s | %(message)s') fileHandler = logging.FileHandler('./myLoggerTest.log') streamHandler = logging.StreamHandler() fileHandler.setFormatter(fomatter) streamHandler.setFormatter(fomatter) self.logger.addHandler(fileHandler) self.logger.addHandler(streamHandler) self.saver = FileSaver(self.logger) self.lotto_data = self.saver.load_lotto_data()
def store_proc(self, store_q): ''' Store process read data form store_q and using file saver to store the data into file :param store_q: store queue: The queue that result solve process send data getting from HTML to the file saver :return: ''' output = FileSaver() while True: if not store_q.empty(): data = store_q.get() if data == 'end': print('File saving...') output.ouput_end(output.filepath) return output.store_data(data) else: time.sleep(0.1) pass
import sys #przeplyw danych csvReader -> podzial na wiersze -> buffer -> InputValidation - >fileSaver #utworzenie bufora buff = Buffer() file_name = raw_input("Podaj nazwe pliku z danymi w formacie csv \n") #wczytanie danych z pliku csv data = CsvReader.read_from_file(file_name, 1) #zmiana czasu data = DataOperation.change_time_relative(data) #zmiana wysokosci na metry data = DataOperation.change_altitude_cm_m(data) #stworzenie zapisywacza saver = FileSaver("saved_data/dane.txt") #kazda linijke z pliku csv buforujemy osobno for d in data: buff.set_data(d) buffered_data = buff.get_data() #sprawdzamy czy kazda linijka jest poprawnie zapisana if InputValidator.input_val(buffered_data): #zapisujemy kazda linijke do nowego pliku saver.save_data(buffered_data) #odczyt danych z pliku csv i wizualizacja r_data = CsvReader.read_from_file(saver.get_file_name()) #tworzymy wizualizator, drugi parametr do interwal czasowy visualizer = PlotCreator(r_data, 1)
class LottoManager: HTTP_OK = 200 __version__ = 0.2 def __init__(self, log_level=logging.INFO): # setup logger self.logger = logging.getLogger("mylogger") self.logger.setLevel(log_level) fomatter = logging.Formatter( '[%(levelname)-5s]%(filename)-15s:%(lineno)s | %(message)s') fileHandler = logging.FileHandler('./myLoggerTest.log') streamHandler = logging.StreamHandler() fileHandler.setFormatter(fomatter) streamHandler.setFormatter(fomatter) self.logger.addHandler(fileHandler) self.logger.addHandler(streamHandler) self.saver = FileSaver(self.logger) self.lotto_data = self.saver.load_lotto_data() def get_lotto(self, drwNo): ''' get lotto info from REST API ''' url = "http://www.nlotto.co.kr/common.do?method=getLottoNumber&drwNo=%d" % ( drwNo) self.logger.debug("[+] Request %s" % (url)) response = requests.get(url) self.logger.debug("[+] Response Status Code is %d" % (response.status_code)) if response.status_code != self.HTTP_OK: return None else: data = response.json() if data["returnValue"] == "fail": return None info = { "totalSell": data["totSellamnt"], "winnerCount": data["firstPrzwnerCo"], "bonusNum": data["bnusNo"], "Num": [data["drwtNo%d" % (x)] for x in range(1, 7)] } return info def get_all_lotto(self): ''' get all lotto info using get_lotto ''' drwNo = 1 while True: if drwNo not in self.lotto_data: info = self.get_lotto(drwNo) self.logger.debug("[*] Request %d Lotto Data" % (drwNo)) if info: self.lotto_data[drwNo] = info else: break drwNo += 1 self.logger.info("[+] get %d data" % (drwNo)) def save_lotto_data(self, filename=None): self.saver.save_lotto_data(self.lotto_data, filename) def load_lotto_data(self, filename=None): self.lotto_data = self.saver.load_lotto_data(filename)
import requests from FileSaver import FileSaver if __name__ == '__main__': page = requests.get('http://www.163.com') page.encoding = 'utf8' content = page.text fs = FileSaver() fs.save('asdfasdfsafd', {}, content=content)