Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

How to use it #4

Closed
Actpohomoc opened this issue Mar 12, 2020 · 10 comments
Closed

How to use it #4

Actpohomoc opened this issue Mar 12, 2020 · 10 comments

Comments

@Actpohomoc
Copy link

No description provided.

@Anatolii1108
Copy link

How to use it?

@shankarpandala
Copy link

Some basic information will be helpful. At least someone else will prepare the documentation

@frenck
Copy link
Member

frenck commented Mar 20, 2020

There is one function...

get_cases, import the package and call that function, pass in an aiohttp session and it will return data.

async def get_cases(session: ClientSession, *, source=DEFAULT_SOURCE):

There really isn't more to it.

@jdmogollonp
Copy link

Is not clear how to use the get_cases function? Can you provide and example?

@frenck
Copy link
Member

frenck commented Mar 20, 2020

Sorry, I don't want to be rude; but what part is unclear?
The function requires only a single parameter, which is an aiohttp client session...

@oskrgab
Copy link

oskrgab commented Mar 20, 2020

When I create the session, and used it as argument I got this:

from coronavirus import get_cases
import aiohttp

session = aiohttp.ClientSession()
print(get_cases(session))


Traceback (most recent call last):
File "Documents/coronavirus/corona_3.py", line 4, in
session = aiohttp.ClientSession()
File "Documents/site-packages/aiohttp/client.py", line 210, in init
loop = get_running_loop(loop)
File "Documents/site-packages/aiohttp/helpers.py", line 269, in get_running_loop
loop = asyncio.get_event_loop()
File "/var/containers/Bundle/Application/5DFB5E26-2341-431E-8E60-EE49EA92D03C/Pyto.app/Frameworks/Python.framework/python38.zip/asyncio/events.py", line 639, in get_event_loop
raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'Thread-4'.
Exception ignored in: <function ClientSession.del at 0x119133a60>
Traceback (most recent call last):
File "Documents/site-packages/aiohttp/client.py", line 302, in del
if not self.closed:
File "Documents/site-packages/aiohttp/client.py", line 916, in closed
return self._connector is None or self._connector.closed
AttributeError: 'ClientSession' object has no attribute '_connector'

@frenck
Copy link
Member

frenck commented Mar 20, 2020

This is all async @oskrgab... Your example is sync...

@frenck
Copy link
Member

frenck commented Mar 20, 2020

Untested example code, dry-coded straight in this GitHub comment box:

import asyncio
import aiohttp

from coronavirus import get_cases


async def main():
	session = aiohttp.ClientSession()
    cases = await get_cases(session)

    for case in cases:
      print(f"Cases in {case.country}: {case.confirmed}")

    await session.close()

if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())

@jdmogollonp
Copy link

Untested example code, dry-coded straight in this GitHub comment box:

import asyncio
import aiohttp

from coronavirus import get_cases


async def main():
	session = aiohttp.ClientSession()
    cases = await get_cases(session)

    for case in cases:
      print(f"Cases in {case.country}: {case.confirmed}")

    await session.close()

if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())

It would be nice to find that code at the READ.ME.
There are thousand researches trying to find this kind of data. And there is no time to explore the source code to figure out how to handle the session and the functions.
Thanks anyway.

@frenck frenck closed this as completed Mar 20, 2020
@frenck frenck mentioned this issue May 3, 2020
@griffi-gh
Copy link

griffi-gh commented May 12, 2020

covid
(pip install covid)
is sipler and better

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants