Simplify code for accommodation
This commit is contained in:
		
							parent
							
								
									2c9b97f0c2
								
							
						
					
					
						commit
						a9c71afb97
					
				| 
						 | 
				
			
			@ -251,29 +251,23 @@ def as_date(d: date | datetime) -> date:
 | 
			
		|||
    return d.date() if isinstance(d, datetime) else d
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_accommodation(from_date: date, filepath: str) -> list[Event]:
 | 
			
		||||
def get_accommodation(filepath: str) -> list[Event]:
 | 
			
		||||
    """Get birthdays from config."""
 | 
			
		||||
    events = []
 | 
			
		||||
    with open(filepath) as f:
 | 
			
		||||
        items = yaml.safe_load(f)
 | 
			
		||||
 | 
			
		||||
    for item in items:
 | 
			
		||||
        title = (
 | 
			
		||||
            f'{item["location"]} Airbnb'
 | 
			
		||||
            if item["operator"] == "airbnb"
 | 
			
		||||
            else item["name"]
 | 
			
		||||
        )
 | 
			
		||||
        from_date = item["from"]
 | 
			
		||||
        to_date = item["to"]
 | 
			
		||||
        e = Event(
 | 
			
		||||
            date=from_date,
 | 
			
		||||
            end_date=to_date,
 | 
			
		||||
            name="accommodation",
 | 
			
		||||
            title=title,
 | 
			
		||||
            url=item.get("url"),
 | 
			
		||||
        )
 | 
			
		||||
        events.append(e)
 | 
			
		||||
    return events
 | 
			
		||||
        return [
 | 
			
		||||
            Event(
 | 
			
		||||
                date=item["from"],
 | 
			
		||||
                end_date=item["to"],
 | 
			
		||||
                name="accommodation",
 | 
			
		||||
                title=(
 | 
			
		||||
                    f'{item["location"]} Airbnb'
 | 
			
		||||
                    if item["operator"] == "airbnb"
 | 
			
		||||
                    else item["name"]
 | 
			
		||||
                ),
 | 
			
		||||
                url=item.get("url"),
 | 
			
		||||
            )
 | 
			
		||||
            for item in yaml.safe_load(f)
 | 
			
		||||
        ]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def waste_collection_events() -> list[Event]:
 | 
			
		||||
| 
						 | 
				
			
			@ -346,7 +340,7 @@ def get_data(now: datetime) -> typing.Mapping[str, str | object]:
 | 
			
		|||
 | 
			
		||||
    my_data = config["data"]["personal-data"]
 | 
			
		||||
    events += birthday.get_birthdays(last_year, os.path.join(my_data, "entities.yaml"))
 | 
			
		||||
    events += get_accommodation(today, os.path.join(my_data, "accommodation.yaml"))
 | 
			
		||||
    events += get_accommodation(os.path.join(my_data, "accommodation.yaml"))
 | 
			
		||||
    events += travel.all_events(today, config["data"]["personal-data"])
 | 
			
		||||
    events += conference.get_list(os.path.join(my_data, "conferences.yaml"))
 | 
			
		||||
    events += waste_collection_events() + bristol_waste_collection_events(today)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue