def publishDatawrapper(): """ Veroeffentlicht die Datawrapper Inhalte neu, damit die veraenderten Werte in der Tabelle bei Google Sheets neu geladen werden """ dw = Datawrapper( access_token= 'm5n8O1c2TOtNOt5C5mtwYHyZ2IQ76JJa1NTdHeLD2HmXUi6esiSMjeXaAv0U8H8A') dw.publish_chart('OXn7r') print( '"Hessen: Aktuelle Corona-Zahlen" bei Datawrapper aktualisiert (publish)!' ) dw.publish_chart('I1p2e') print( '"Entwicklung der schweren Corona-Faelle in Hessen" bei Datawrapper aktualisiert (publish)!' )
def now(config): """This method is going to be called by main.py and it should return the output DataFrame. Parameters ---------- config : dict """ # INIT idStateCode = config["br"]["maps"]["idStateCode"] idStatesMap = config["br"]["maps"]["idStatesMap"] states = idStatesMap.keys() ACCESS_TOKEN = os.getenv("MAP_ACCESS_TOKEN") if None in idStatesMap.values(): IS_DEV = True print("Generating new ids") else: IS_DEV = os.getenv("IS_MAP_DEV") == "True" if not IS_DEV: map_folder_id = config["br"]["maps"]["MAP_FOLDER_ID"] else: map_folder_id = 38060 # "maps-coronacidades" dw = Datawrapper(access_token=ACCESS_TOKEN) if IS_DEV: # Create states map for state_id in states: config["br"]["maps"]["idStatesMap"][state_id] = Map( config, map_folder_id, ACCESS_TOKEN, basemapCMD=f"brazil-{idStateCode[state_id]}-municipalities", state_id=state_id, ).createMap() # Update layout Map( config, map_folder_id, ACCESS_TOKEN, basemapCMD=f"brazil-{idStateCode[state_id]}-municipalities", state_id=state_id, ).applyDefaultLayout(config["br"]["maps"]["idStatesMap"][state_id]) dw.publish_chart(config["br"]["maps"]["idStatesMap"][state_id]) print(state_id + ": " + config["br"]["maps"]["idStatesMap"][state_id]) # Create country map config["br"]["maps"]["BR_ID"] = Map( config, map_folder_id, ACCESS_TOKEN, basemapCMD="brazil-states-2018", state_id=None, ).createMap() # Update layout Map( config, map_folder_id, ACCESS_TOKEN, basemapCMD="brazil-states-2018", state_id=None, ).applyDefaultLayout(config["br"]["maps"]["BR_ID"]) dw.publish_chart(config["br"]["maps"]["BR_ID"]) print("BR : " + config["br"]["maps"]["BR_ID"]) else: # Update states map for state_id in states: Map( config, map_folder_id, ACCESS_TOKEN, basemapCMD=f"brazil-{idStateCode[state_id]}-municipalities", state_id=state_id, ).updateMap(config["br"]["maps"]["idStatesMap"][state_id]) dw.publish_chart(config["br"]["maps"]["idStatesMap"][state_id]) print(state_id + ": " + config["br"]["maps"]["idStatesMap"][state_id]) # Update country map Map( config, map_folder_id, ACCESS_TOKEN, basemapCMD="brazil-states-2018", state_id=None, ).updateMap(config["br"]["maps"]["BR_ID"]) dw.publish_chart(config["br"]["maps"]["BR_ID"]) print("BR : " + config["br"]["maps"]["BR_ID"]) out_frame = (pd.DataFrame({ "place_id": list(config["br"]["maps"]["idStatesMap"].keys()), "map_id": list(config["br"]["maps"]["idStatesMap"].values()), }).append( pd.DataFrame({ "place_id": "BR", "map_id": [config["br"]["maps"]["BR_ID"]] })).reset_index(drop=True)) # Gens the hashes for version control out_frame["hashes"] = [ "".join(random.choice("0123456789ABCDEF") for i in range(16)) for i in range(out_frame.shape[0]) ] return out_frame
properties = { "visualize": { "custom-colors": {"Male": GREEN, "Female": PURPLE}, "inside_labels": {"enabled": False}, "color_key": { "stack": False, "enabled": False, "position": "top", "label_values": True, }, "pie_size": {"inside_labels": 50, "outside_labels": 25}, "outside_labels": {"edge": False, "color": True, "enabled": True}, } } dw.update_metadata(chart_info["id"], properties) dw.publish_chart(chart_info["id"], display=False) dw.export_chart( chart_info["id"], output="png", filepath="img/gender.png", display=False, border_width=0, zoom=10, ) # Age group chart_info = dw.create_chart( title="Age group of the interviewed scientists", chart_type=VBAR_CHART, data=prepare_column(data, "Age, years", sort=False), )