コード例 #1
0
def configure_fake_data():
    # This was added to make it easier to test the weather event reporting
    # We have /api/reports but until you submit new data each run, it's missing
    # So this will give us something to start from.
    loop = None
    try:
        loop = asyncio.get_running_loop()
        print("got loop!", loop)
    except RuntimeError:
        pass  # Boo, why can't I just get nothing back?

    if not loop:
        loop = asyncio.get_event_loop()

    try:
        loc = Location(city="Portland", state="OR", country="US")
        loop.run_until_complete(
            report_service.add_report("Misty sunrise today, beautiful!", loc))
        loop.run_until_complete(
            report_service.add_report("Clouds over downtown.", loc))
    except RuntimeError:
        print(
            "Note: Could not import starter date, this fails on some systems and "
            "some ways of running the app under uvicorn.")
        print("Fake starter data will no appear on home page.")
        print("Once you add data with the client, it will appear properly.")
コード例 #2
0
def configure_fake_data():
    # This was added to make it easier to test the weather event reporting
    # We have /api/reports but until you submit new data each run, it's missing
    # So this will give us something to start from.
    loc = Location(city="Portland", state="OR", country="US")
    asyncio.run(
        report_service.add_report("Misty sunrise today, beautiful!", loc))
    asyncio.run(report_service.add_report("Clouds over downtown.", loc))
コード例 #3
0
def configure_fake_data():
    # This was added to make it easier to test the weather event reporting
    # We have /api/reports but until you submit new data each run, it's missing
    # So this will give us something to start from.

    # Changed this from the video due to changes in Python 3.10:
    # DeprecationWarning: There is no current event loop, loop = asyncio.get_event_loop()
    loop = asyncio.new_event_loop()

    try:
        loc = Location(city="Portland", state="OR", country="US")
        loop.run_until_complete(
            report_service.add_report("Misty sunrise today, beautiful!", loc))
        loop.run_until_complete(
            report_service.add_report("Clouds over downtown.", loc))
    except RuntimeError:
        print(
            "Note: Could not import starter date, this fails on some systems and "
            "some ways of running the app under uvicorn.")
        print("Fake starter data will no appear on home page.")
        print("Once you add data with the client, it will appear properly.")
コード例 #4
0
async def reports_get() -> List[Report]:
    report_service.add_report("A raport", Location(city="Tarnow"))
    report_service.add_report("B report", Location(city="Warszawa"))
    return await report_service.get_reports()
コード例 #5
0
def configure_fake_data():
    "Added to test app"
    loc = Location(city="Accra")
    loc2 = Location(city="Portland", state="OR", country="US")
    asyncio.run(report_service.add_report("Heavy Rainfall", loc))
    asyncio.run(report_service.add_report("Clouds over downtown.", loc2))