Skip to content

Commit

Permalink
Add proxy flag
Browse files Browse the repository at this point in the history
  • Loading branch information
KarimPwnz committed Jun 30, 2023
1 parent 492ed0a commit 0627649
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions scripts/github_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@

from aiopath import AsyncPath


class NotFoundException(Exception):
pass

class GitHubDownloader:
def __init__(self, client, output_path):
def __init__(self, client, output_path, proxy):
self._client = client
self.output_path = output_path
self.proxy = proxy

@staticmethod
def _url_to_path(url):
return url.replace("https://raw.githubusercontent.com/", "")

async def download(self, url):
async with self._client.get(url) as resp:
async with self._client.get(url, proxy=self.proxy) as resp:
resp.raise_for_status()
return await resp.text()

Expand Down Expand Up @@ -58,15 +58,22 @@ async def main():
)
parser.add_argument(
"-l",
"--limit",
dest="limit",
help="Concurrent requests limit (default: 100)",
default=100,
type=int,
)
parser.add_argument("-p",
"--proxy",
dest="proxy",
help="Proxy to use with each request; proxy domain resolved per request",
default=None
)
args = parser.parse_args()
conn = aiohttp.TCPConnector(limit=args.limit)
async with aiohttp.ClientSession(connector=conn) as client:
downloader = GitHubDownloader(client=client, output_path=args.output)
downloader = GitHubDownloader(client=client, output_path=args.output, proxy=args.proxy)
tasks = []
urls = (l.rstrip("\n") for l in sys.stdin)
for url in urls:
Expand Down

0 comments on commit 0627649

Please sign in to comment.