예제 #1
0
 def _save_spreadsheet(self):
     stopper = Time()
     print("Saving...")
     stopper.start()
     self.spreadsheet.save()
     stopper.end()
     print(f"Spreadsheet has been saved. ({stopper.result:0.3f}s)")
예제 #2
0
    def get_data(self):
        stopper = Time()

        try:
            self._check_permissions()
            datetime = Time.now()
            print(f"Datetime: {datetime}")

            for crate_name in self.required_crates:
                crate = Crate(crate_name)
                print(f"{crate.short_name} data:")

                if MAKE_ORDERS_HISTOGRAM_REQUEST is True:
                    order_histogram_data = self.order_histogram.get_data(crate)
                    stopper.start()
                    self.spreadsheet.insert_histogram_data(
                        crate, datetime, order_histogram_data)
                    stopper.end()
                    print(f"  Data extraction time: ({stopper.result:0.3f}s)")
                if MAKE_PRICE_OVERVIEW_REQUEST is True:
                    price_overview_data = self.price_overview.get_data(crate)
                    stopper.start()
                    self.spreadsheet.insert_price_overview_data(
                        crate, datetime, price_overview_data)
                    stopper.end()
                    print(f"  Data extraction time: ({stopper.result:0.3f}s)")
                if DRAW_COLORS_SHEET is True:
                    self.spreadsheet.insert_colors()

            self._save_spreadsheet()
        except PermissionError:
            print('\033[91m' + 'Permission denied' + '\033[0m')
예제 #3
0
 def _check_permissions(self):
     stopper = Time()
     print("Checking permissions...")
     stopper.start()
     self.spreadsheet.save()
     stopper.end()
     print(f"Done. ({stopper.result:0.3f}s)")
예제 #4
0
 def _load_workbook(self):
     try:
         stopper = Time()
         print("Loading spreadsheet...")
         stopper.start()
         workbook = load_workbook(self.filename)
         stopper.end()
         print(f"Done. ({stopper.result:0.3f}s)")
         return workbook
     except FileNotFoundError:
         stopper = Time()
         print("Creating spreadsheet...")
         stopper.start()
         workbook = self._create_workbook()
         stopper.end()
         print(f"Done. ({stopper.result:0.3f}s)")
         return workbook
예제 #5
0
 def make_request(self, param):
     request_time = Time()
     request_status = 500
     try:
         request_time.start()
         url = self.api + self.endpoint + str(param)
         response = get(url)
         request_status = response.status_code
         if response.status_code == 200:
             return response.json()
         return None
     except ConnectionError:
         request_status = 500
         return None
     except HTTPError as error:
         request_status = error.response.status_code
     finally:
         request_time.end()
         print(
             f"  Request {self.name}: {request_status} ({request_time.result:0.3f}s)"
         )