Skip to content

Instantly share code, notes, and snippets.

@mjtiempo
Created June 16, 2021 13:39
Show Gist options
  • Save mjtiempo/91cad1e7f60389d54048b0797d034ff7 to your computer and use it in GitHub Desktop.
Save mjtiempo/91cad1e7f60389d54048b0797d034ff7 to your computer and use it in GitHub Desktop.
run asyc http request using asyncio and pypeln in python
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