-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
95 lines (80 loc) · 4.08 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
import streamlit as st
import requests,random,time
from deta import Deta
deta = Deta(st.secrets['key'])
# Base key
db= deta.Base("usernames")
st.set_page_config(page_title="Github Shoutout",page_icon="images/githublogo.png",layout="centered",initial_sidebar_state="auto") # setting the page config
def verifying(username):
if username:
try:
api_url = f"https://api.github.com/users/{username}" # api url
response = requests.get(api_url) # get response
data = response.json() # parse data as json
if db.get(username):
st.warning("Username already exists")
elif data["followers"] and data["name"] and data["bio"]: # if followers or following is not zero
db.put({"key":username}) # add entryin database with key lowercase username
st.success("Username stored in database.")
else:
st.error("Sorry, you don't have followers or your name and bio is not setup")
except Exception as e: # if username is not valid
print(e)
st.error("Invalid github username")
def random_username():
names = db.fetch().items
github_username=list(names[random.randint(0,len(names)-1)].values())[0]
try:
api_url = f"https://api.github.com/users/{github_username}" # api url
response = requests.get(api_url)
data = response.json()
acc_link=data['html_url']
st.markdown(f"""<div id='container'><img id='pfp' src="https://github.com/{github_username}.png" alt="github profile pic"/>
<h3>Name: {data['name']}</h3>
<p id="bio">Bio: {data['bio']}</p>
<p id="ff">Followers: {data["followers"]} | Following: {data["following"]}</p>
<table>
<tr>
<th>Stats</th>
<th>Streak</th>
<th>Languages</th>
</tr>
<tr>
<td><img src='http://github-profile-summary-cards.vercel.app/api/cards/stats?username={github_username}&theme=github_dark' width=200px height=100px></td>
<td><img src='https://streak-stats.demolab.com?user={github_username}&theme=github-dark&hide_border=true&border_radius=32&date_format=j%20M%5B%20Y%5D&ring=888888' width=180px height=100px></td>
<td><img src='http://github-profile-summary-cards.vercel.app/api/cards/repos-per-language?username={github_username}&theme=github_dark' width= 200px height=100px></td>
</tr>
</table><br><br>
<a target="_blank" href="{acc_link}">
<button id='btn'>
Follow {github_username} on GitHub
</button><br><br>
</a></div>""",unsafe_allow_html=True) #displaying the data
#
except Exception as e:
st.error("Something went wrong, try again later")
def main():
st.markdown("""<a href='https://github.com/samadpls/Github-Shoutout'><img src='https://img.shields.io/github/stars/samadpls/Github-Shoutout?color=red&label=star%20me&logoColor=red&style=social'></a>""",unsafe_allow_html=True)
img , heading = st.columns([1,8]) # using columns to display the heading and image
with img:
st.image("images/githublogo.png",width=70) # github logo
with heading:
st.markdown('# Shoutout to Github User') # heading
st.markdown("`Click on the button to see the profile`") # description
if st.button("Press Me"):
with st.spinner('Wait for it...'):
time.sleep(2)
random_username()
#New username
with st.expander("Add your profile :"): # sub header
text = st.empty()
username=text.text_input("Enter your github username",max_chars=40)
st.markdown(""" `
Made with 🤍 by samadpls
`
""") # footer
verifying(username.strip().lower())
if __name__=="__main__":
with open('styles.css') as f:
st.markdown(f"<style>{f.read()}</style>",unsafe_allow_html=True) # loading the css file
main()