Created
August 16, 2020 20:41
-
-
Save webbyfox/09931a0db515f3aaaae57059b760e572 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
import requests | |
import re | |
# Framework to detect | |
FRAMEWORKS = ['jquery', 'angular', 'react', 'vue', 'bootstrap'] | |
def get_version(str): | |
version_pattern = "v([\d.]*)" | |
version = re.findall(version_pattern, str) | |
filtered_version = list(filter(None, version)) | |
if len(filtered_version) >= 1: | |
return filtered_version[0] | |
def get_framework(file_path): | |
file_content = str(requests.get(file_path).content) | |
comment_block_pattern = "\\*(.*?)\*\/" | |
comment_block = re.search(comment_block_pattern, file_content).group(1) | |
version = get_version(comment_block) | |
for item in FRAMEWORKS: | |
if len(re.findall(item, comment_block, re.IGNORECASE)) > 0: | |
return file_path, '-->', item, version | |
return | |
if __name__ == '__main__': | |
print(get_framework(file_path='https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.4.0.js')) | |
print(get_framework(file_path='https://unpkg.com/react@16/umd/react.development.js')) | |
print(get_framework(file_path='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.8.0/angular.min.js')) | |
print(get_framework(file_path='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.8.0/angular.js')) | |
print(get_framework(file_path='https://cdn.jsdelivr.net/npm/vue/dist/vue.js')) | |
print(get_framework(file_path='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js')) | |
print(get_framework(file_path='https://code.jquery.com/jquery-1.12.4.js')) | |
print(get_framework(file_path='https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.slim.js')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment