-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGithub_CTI_extraction.py
56 lines (44 loc) · 2.03 KB
/
Github_CTI_extraction.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import requests
git_token = "YOUR_GITHUB_TOKEN"
# Github CTI extraction tool is used in order to get infos CTI on Github
print()
print("Hello, What Github CTI extraction tool can do for you today? ")
user_input = str(input("Choose between one of thoses: Best matches, Better ranked, Most forked, Recent Update: "))
keyword_input = str(input("Optional: (default keyword: CTI) Any specific keywords to add to your research? +keyword1+keyword2... "))
print()
def FCTU():
if user_input == "Best matches":
URL = f'https://api.github.com/search/repositories?q=cti{keyword_input}&type=repositories'
return URL
elif user_input == "Better ranked":
URL = f'https://api.github.com/search/repositories?q=cti{keyword_input}&ty+threats&type=repositories&s=stars&o=desc'
return URL
elif user_input == "Most forked":
URL = f'https://api.github.com/search/repositories?q=cti{keyword_input}&type=repositories&s=forks&o=desc'
return URL
elif user_input == "Recent Update":
URL = f'https://api.github.com/search/repositories?q=cti{keyword_input}&type=repositories&s=updated&o=desc'
return URL
else :
print("The purpose of this tool is to monitor Open source CTI tools on github via CLI")
print("First choose the critera of your research between the one proposed")
print("Then add a keyword/keywords respecting the pattern given to filter more ")
print()
exit()
headers = {
'Authorization' : f'token {git_token}',
}
URL = FCTU()
try:
response = requests.get(URL, headers=headers)
if response.status_code == 200:
data = response.json()
for item in data['items']:
print("-"*100)
print(f'{str(item["updated_at"].split("T")[0])} {item["full_name"]}: {item["description"]} ')
print("-"*100)
print()
else:
print(f'request failed: {response.status_code}')
except Exception as e:
print(f'something failed {e}')