Last active
November 1, 2022 06:48
-
-
Save Splint3r7/69e73ac50b809b8618d41729d8bf03e8 to your computer and use it in GitHub Desktop.
Extract Emails from Npm Packge Names - https://api.npms.io/
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 requests | |
import sys | |
import json | |
import concurrent.futures | |
output_file = open("emails_res.txt", "w") | |
def Emails(package): | |
req = requests.get("https://api.npms.io/v2/package/{}".format(package)) | |
resp = json.loads(req.text) | |
try: | |
for key, value in resp.items(): | |
if key == "collected": | |
metadata = value['metadata'] | |
emails = len(metadata['maintainers']) | |
for email in range(0, emails): | |
email_obj = metadata['maintainers'][email] | |
for key, value in email_obj.items(): | |
if "email" in key: | |
print(value) | |
output_file.write(str(value)+"\n") | |
except Exception as e: | |
print(e) | |
if __name__ == '__main__': | |
packages_list = [] | |
packages = open("all_packages_names.txt", "r") | |
for package in packages: | |
package = package.strip() | |
packages_list.append(package) | |
packages.close() | |
with concurrent.futures.ThreadPoolExecutor(max_workers=100) as executor: | |
executor.map(Emails, packages_list) | |
output_file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment