Last active
June 28, 2021 06:01
-
-
Save matheusfillipe/9ae3d82412ce0be5804f32dc4b4e8ca1 to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/python3 | |
| ### Install ua-parser: | |
| ### sudo pip install pyyaml ua-parser user-agents | |
| import os | |
| from user_agents import parse | |
| print('Content-Type: text/html\n\n') | |
| ## This is for printing http headers when you dont know what is what ;) | |
| # for headername in os.environ: | |
| # print(f"<p>{headername} = {os.environ[headername]}</p>") | |
| ## I used this to figure out it was HTTP_USER_AGENT | |
| ua_string = os.environ["HTTP_USER_AGENT"] | |
| user_agent = parse(ua_string) | |
| print(f"<h4>UA: {str(user_agent)}</<h4>") | |
| print("<p>") | |
| print(f"{user_agent.is_mobile=}<br>") | |
| print(f"{user_agent.is_tablet=}<br>") | |
| print(f"{user_agent.is_touch_capable=}<br>") | |
| print(f"{user_agent.is_pc=}<br>") | |
| print(f"{user_agent.is_bot=}<br>") | |
| print("<p>") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment