Created
March 13, 2022 00:17
-
-
Save stefanschmidt/d6cce188f8017bf1a7a5bbe0c532d4be to your computer and use it in GitHub Desktop.
Simple command line interface for fileinfo.com
This file contains 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
#!/usr/bin/env python | |
import sys | |
import requests as req | |
from bs4 import BeautifulSoup | |
if not(len(sys.argv) == 2): | |
sys.exit("Usage: fileinfo.py extension") | |
ext = str(sys.argv[1]) | |
url = "https://fileinfo.com/extension/" + ext | |
resp = req.get(url) | |
soup = BeautifulSoup(resp.text, 'html.parser') | |
filetypes = soup.find_all("h2", class_="title") | |
if len(filetypes) > 0: | |
for filetype in filetypes: | |
print(filetype.text) | |
else: | |
sys.exit('The extension ".' + ext + '" was not found.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment