def __init__(self, parent=None): QWidget.__init__(self, parent) self.config = config.Config() self.data = self.config.data Context(self.data['window'], self.data['window2']) self.setAttribute(Qt.WA_TranslucentBackground, True) self.setAttribute(Qt.WA_TransparentForMouseEvents, True) self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint) self.setFixedSize(250, 500) self.move(Context.i.x, Context.i.y) self.font = QFont('Arial', 12, 2) self.style = 'color: yellow' self.vbox = QVBoxLayout() self.vbox.setAlignment(Qt.AlignTop) QWidget.setLayout(self, self.vbox) self.labels = {} for name in labelTemplate: self.labels[name] = self.addLabel() self.updateLabel() self.controller = Controller(sys.argv[1:]) self.initKeys()
def __init__(self, parent=None): QWidget.__init__(self, parent) self.config = config.Config() self.data = self.config.data Context(self.data['window'], self.data['window2']) self.controller = Controller() self.setAttribute(Qt.WA_TranslucentBackground, True) self.setAttribute(Qt.WA_TransparentForMouseEvents, True) self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint) self.setFixedSize(Context.i.w, Context.i.h) self.move(Context.i.x, Context.i.y) self.marks = [] self.pen = QPen() self.brush = QBrush() self.painter = QPainter() self.initKeys() self.filename = None self.labels = [] self.form = QFormLayout() gbox = QGroupBox() gbox.setLayout(self.form) scroll = QScrollArea() scroll.setStyleSheet("background-color:rgba(0,0,0,0.3)") scroll.setWidget(gbox) scroll.setWidgetResizable(True) scroll.setFixedHeight(Context.i.h) scroll.setFixedWidth(250) scroll.setParent(self)
class LinePresenter: """ LinePresenter is the presenter that output message to LINE bot. """ c = config.Config() def __init__(self): pass def out(self, corona_data: str, errMsg: str): formatted_message = self._create_message(corona_data, errMsg) self._send_message(formatted_message) line_bot_api = LineBotApi(c.LINE_ACCESS_TOKEN) handler = WebhookHandler(c.LINE_CHANNEL_SECRET) @handler.add(MessageEvent, message=TextMessage) def _send_message(self, formatted_message): self.line_bot_api.reply_message( self.c.REPLY_TOKEN, TextSendMessage(text=formatted_message)) def _create_message(self, data: corona_data.CoronaData, errMsg: str) -> str: """ create_message format the message into the format you want to output to LINE bot. :param data: data is data resource. :return: message formatted """ if errMsg == "": with open("adopter/presenter/output_template.txt") as f: return f.read().format( today=datetime.date.today().__str__(), jp_pref_name=data.pref_JP_name, total_confirmed=data.total_confirmed, newly_confirmed=data.newly_confirmed, yesterday_confirmed=data.yesterday_confirmed, recovered=data.recovered, deaths=data.deaths, confirmed_by_city=self.create_confirmed_by_city_message( data)).__str__() else: with open("adopter/presenter/error_template.txt") as f: return f.read().__str__() def create_confirmed_by_city_message(self, data: corona_data.CoronaData) -> str: res = "" print(data.confirmed_by_city) for k, v in data.confirmed_by_city.items(): res += "{}: {}\n".format(k, v) return res
def test_loaded_config(self): cfg = config.Config('s3://{}/test.json'.format(self.bucket)) for key in self.value['Application'].keys(): self.assertEqual(cfg.application[key], self.value['Application'][key]) for key in self.value['Daemon'].keys(): self.assertEqual(cfg.daemon[key], self.value['Daemon'][key]) for key in self.value['Logging'].keys(): self.assertEqual(cfg.logging[key], self.value['Logging'][key])
def do_request() -> dict: """ リクエストを送信する関数 :return: str:リクエストで取得したJson """ c = config.Config() url = c.CORONA_URL response = requests.get(url) return response.json()
def __init__(self, args, operating_system): """Create an instance of the controller passing in the debug flag, the options and arguments from the cli parser. :param argparse.Namespace args: Command line arguments :param str operating_system: Operating system name from helper.platform """ self.set_state(self.STATE_INITIALIZING) self.args = args self.debug = args.foreground try: self.config = config.Config(args.config) except ValueError: sys.exit(1) self.logging_config = config.LoggingConfig(self.config.logging, self.debug) self.operating_system = operating_system
class DatastoreRepository(corona_data_repository.CoronaDataRepositoryInterface ): c = config.Config() dclient = datastore.Client() def __init__(self): pass def get_by_pref(self, pref: str) -> str: """ TODO: get covid data by pref name """ today = date.today() query = self.dclient.query(kind=str(today)) query = query.add_filter("pref_jp_name", '=', pref) result = query.fetch(1) result = list(result) print("get the {}'s data.".format(result[0]["pref_en_name"])) return result[0]
class DataStore(RepositoryInterface, Singleton): c = config.Config() dclient = datastore.Client() logger = logging.getLogger('corona_data_linker_logger') def insert(self, corona_data: List[CoronaData]): today = date.today() c = config.Config batch = self.dclient.batch() batch.begin() for data in corona_data: key = self.dclient.key(str(today), data.pref_JP_name) entity = datastore.Entity(key) entity['pref_en_name'] = data.pref_EN_name entity['pref_jp_name'] = data.pref_JP_name entity['newly_confirmed'] = data.newly_confirmed entity['yesterday_confirmed'] = data.yesterday_confirmed entity['confirmed_by_city'] = data.confirmed_by_city entity['total_deaths'] = data.total_deaths entity['total_confirmed'] = data.total_confirmed entity['recovered'] = data.recovered batch.put(entity) batch.commit() self.logger.info("inserted today's data.") def delete(self, corona_data: List[CoronaData], data_period: int): target_day = date.today() - timedelta(days=data_period) batch = self.dclient.batch() batch.begin() for data in corona_data: key = self.dclient.key(str(target_day), data.pref_JP_name) batch.delete(key) batch.commit() self.logger.info("deleted {}'s data.".format(target_day))
def test_value_error_raised_for_missing_file(self): with self.assertRaises(ValueError): config.Config('s3://{}/{}.json'.format(self.bucket, uuid.uuid4()))
def test_value_error_raised_for_missing_file(self): with self.assertRaises(ValueError): config.Config('{}/{}/{}.json'.format(os.environ['S3_ENDPOINT'], self.bucket, uuid.uuid4()))
def setUp(self): self.config = config.Config()
def setUp(self, _mock_queue_unused): self.cfg = config.Config() self.cfg.application.update(self.CONFIG) self._obj = mcp.MasterControlProgram(self.cfg)