Created
June 16, 2021 13:39
-
-
Save mjtiempo/91cad1e7f60389d54048b0797d034ff7 to your computer and use it in GitHub Desktop.
run asyc http request using asyncio and pypeln in python
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
from aiohttp import ClientSession, TCPConnector | |
import asyncio | |
import sys | |
import pypeln as pl | |
import csv | |
limit = 1000 | |
def csv2list(file): | |
results = [] | |
with open(file, newline='') as inputfile: | |
for row in csv.reader(inputfile): | |
results.append(row[0]) | |
return results | |
numbers = csv2list('Nelnet01.csv') | |
URL = "https://app1.teligentip.net/webSocketServer/sms/optinout/update.htm" | |
QNAME = "Firstmark" | |
APIsecret = "API_SECRET" | |
async def main(): | |
async with ClientSession(connector=TCPConnector(limit=0)) as session: | |
async def fetch(phonenum): | |
phonenum = str(phonenum) | |
async with session.post(URL, json={"queueName": "Firstmark","apiSecret": APIsecret,"action": "subscribe","customerNumber": phonenum}) as response: | |
print(await response.text(), phonenum) | |
await pl.task.each( | |
fetch, numbers, workers=limit, | |
) | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment