Skip to content

Instantly share code, notes, and snippets.

@stefanschmidt
Created March 13, 2022 00:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefanschmidt/d6cce188f8017bf1a7a5bbe0c532d4be to your computer and use it in GitHub Desktop.
Save stefanschmidt/d6cce188f8017bf1a7a5bbe0c532d4be to your computer and use it in GitHub Desktop.
Simple command line interface for fileinfo.com
#!/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