def check_quick_stats(): client = DateLaZiClient() client.sync() quick_stats = DLZSerializer.deserialize(client.serialized_data) last_updated = quick_stats.pop("Data") db_stats = client._local_data if db_stats and quick_stats.items() <= db_stats.items(): msg = "No updates to quick stats" logger.info(msg) return msg diff = parse_diff(quick_stats, db_stats) diff["Actualizat la"] = last_updated incidence = client.serialized_data["Incidență"] infections = client.serialized_data["Judete"] items = { "*Incidențe*": split_in_chunks(incidence, limit=5), "*Infectări*": split_in_chunks(infections, limit=5), "*Vaccinări*": [ f"`Total: {client.serialized_data['Total doze administrate']}`", ], **{ f"*{company.title()} (24h)*": { "Total": f'+{data["total_administered"]}', "Rapel": f'+{data["immunized"]}', } for company, data in client.serialized_data.get("Vaccinări", {}).items( ) if data["total_administered"] or data["immunized"] }, } send_message( bot=telegram.Bot(token=os.environ["TOKEN"]), text=parse_global( title="🔴 Cazuri noi", stats=diff, items=items, footer="\nDetalii: https://coronavirus.pradan.dev/", emoji="🔸", ), chat_id=os.environ["CHAT_ID"], ) msg = "Quick stats updated" logger.info(msg) return msg
def test_no_old_version(self, data): assert parse_diff(data, None) == data
def test_different_keys(self): data = {"abc": 1, "cde": 2} old_values = {"fgh": 123, "ijk": 456} assert parse_diff(data, old_values) == data
def test_different_values(self, data, old_data, results): assert parse_diff(data, old_data) == results
def test_same_values(self): data = {"abc": 1, "cde": 2} assert parse_diff(data, data) == data