-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
152 lines (123 loc) · 4.94 KB
/
app.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import streamlit as st
import requests
import re
import os
from PIL import Image
# All Functions for fetching email
def get_repos(user, token, sort='created', direction='desc'):
headers = {
'Authorization': f'token {token}'
}
repos_url = f"https://api.github.com/users/{user}/repos"
repos_params = {
'type': 'owner',
'sort': sort,
'direction': direction
}
repos_response = requests.get(repos_url, headers=headers, params=repos_params)
if repos_response.status_code == 401:
st.error("Error: Unauthorized. The provided token may be expired or invalid.")
return None
if repos_response.status_code != 200:
st.error(f"Error fetching repositories: {repos_response.status_code}")
return None
return repos_response.json()
def get_commits(user, repo, token, direction='desc'):
headers = {
'Authorization': f'token {token}'
}
commits_url = f"https://api.github.com/repos/{user}/{repo}/commits"
commits_params = {
'direction': direction
}
commits_response = requests.get(commits_url, headers=headers, params=commits_params)
if commits_response.status_code == 401:
st.error("Error: Unauthorized. The provided token may be expired or invalid.")
return None
if commits_response.status_code != 200:
st.error(f"Error fetching commits for {repo}: {commits_response.status_code}")
return None
return commits_response.json()
def get_patch_data(commit_url):
patch_url = commit_url + ".patch"
response = requests.get(patch_url)
if response.status_code == 401:
st.error("Error: Unauthorized. The provided token may be expired or invalid.")
return None
if response.status_code != 200:
st.error(f"Error fetching patch data: {response.status_code}")
return None
return response.text
def extract_email(patch_data):
# Regex to extract email
email_pattern = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b'
match = re.search(email_pattern, patch_data)
if match:
email = match.group(0)
if "@users.noreply.github.com" in email:
return None
return email
return None
def get_commit_email(user, token, sort='created', direction='desc'):
repos = get_repos(user, token, sort=sort, direction=direction)
if not repos:
st.info("No repositories found for the user.")
return None
for repo in repos:
commits = get_commits(user, repo['name'], token, direction)
if commits is None:
continue
for commit in commits:
if commit['author'] and commit['author']['login'] == user:
commit_url = commit['html_url']
patch_data = get_patch_data(commit_url)
if patch_data is None:
continue
email = extract_email(patch_data)
if email:
return email
return None
def get_user_profile(user, token):
headers = {
'Authorization': f'token {token}'
}
user_url = f"https://api.github.com/users/{user}"
user_response = requests.get(user_url, headers=headers)
if user_response.status_code == 401:
st.error("Error: Unauthorized. The provided token may be expired or invalid.")
return None
if user_response.status_code != 200:
st.error(f"Error fetching user profile: {user_response.status_code}")
return None
return user_response.json()
# User Interface Starts here
icon = Image.open('assets/icon.png')
st.set_page_config(page_title='Osintgit', page_icon=icon)
st.title("Osintgit")
st.write("An Open Source Intelligence Tool to Find the Email Addresses of GitHub Users")
username = st.text_input("GitHub Username", "")
token = os.getenv('ghtoken')
#st.write(token)
if st.button("Find Email"):
if username:
store_username=username
with st.spinner("Searching for email...."):
try:
profile = get_user_profile(username, token)
email = get_commit_email(username, token, sort='created', direction='desc')
if not email:
email = get_commit_email(username, token, sort='created', direction='asc')
if profile and store_username == profile["login"]:
st.image(profile['avatar_url'], width=100)
st.write(f"**User ID:** {profile['id']}")
st.write(f"**Username:** {profile['login']}")
if email:
st.success(f"**Email:** {email}")
else:
st.warning("No email found. This is our limitation.")
else:
st.warning("Failed to fetch user profile.")
except Exception as e:
st.error(str(e))
else:
st.warning("Please enter username")