Created
May 9, 2021 06:34
-
-
Save athphane/36bca01f131bf84af1f60c510d19c604 to your computer and use it in GitHub Desktop.
Script to scrape MDP Registry Data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import aiofiles as aiofiles | |
import aiohttp | |
async def download_file(reg): | |
file_name = f'downloads/{reg}.csv' | |
async with aiohttp.ClientSession() as session: | |
url = f'https://reg.mdp.org.mv/lists/?dhaairaa={reg}&download=1' | |
async with session.get(url) as resp: | |
if resp.status == 200: | |
f = await aiofiles.open(file_name, mode='wb') | |
await f.write(await resp.read()) | |
await f.close() | |
return file_name | |
return None | |
async def main(): | |
reg_nos = [ | |
'A01', 'A02', 'A03', 'A04', 'A05', 'B01', 'B02', 'B03', 'B04', 'B05', 'B06', 'C01', 'C02', 'C03', 'C04', 'D01', | |
'D02', 'D03', 'D04', 'E01', 'E02', 'E03', 'E04', 'E05', 'F01', 'F02', 'F03', 'G01', 'G02', 'G03', 'H01', 'H02', | |
'H03', 'I01', 'I02', 'I03', 'J01', 'J02', 'K01', 'K02', 'L01', 'L02', 'M01', 'M02', 'N01', 'N02', 'N03', 'N04', | |
'O01', 'O02', 'O03', 'O04', 'P01', 'P02', 'P03', 'Q01', 'Q02', 'Q03', 'Q04', 'Q05', 'R01', 'R02', 'R03', 'S01', | |
'S02', 'S03', 'S04', 'S05', 'S06', 'S07', 'T01', 'T02', 'T03', 'T04', 'T05', 'T06', 'T07', 'T08', 'T09', 'T10', | |
'T11', 'T12', 'T13', 'T14', 'T15', 'U01', 'U02', | |
] | |
for reg in reg_nos: | |
file_name = await download_file(reg) | |
print(f"{reg}: {file_name}") | |
loop = asyncio.get_event_loop() | |
loop.run_until_complete(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment