|
| 1 | +from tkinter import * |
| 2 | + |
| 3 | +import requests |
| 4 | +from requests.auth import HTTPBasicAuth |
| 5 | + |
| 6 | +# Creating GUI |
| 7 | +root = Tk() |
| 8 | + |
| 9 | +# Giving Title to the program |
| 10 | +root.title("Github User Details") |
| 11 | + |
| 12 | +# Icon |
| 13 | +root.iconbitmap('icon.ico') |
| 14 | + |
| 15 | +# Frame |
| 16 | +frame1 = LabelFrame(root, width=50, height=150, bd=5, bg='grey') |
| 17 | +frame1.grid(row=0, column=0, padx=5, pady=5) |
| 18 | + |
| 19 | +# Header |
| 20 | +head = Label(frame1, text="GITHUB USER DATA COLLECTOR", font=("Arial", 15), fg="black", bd=2, anchor=W) |
| 21 | +head.grid(row=0, columnspan=2, padx=50, pady=30, sticky=W + E) |
| 22 | + |
| 23 | +# Entry columns |
| 24 | + |
| 25 | +leb1 = Label(frame1, text="Enter username - ") |
| 26 | +leb1.grid(row=2, columnspan=2, padx=30, pady=5) |
| 27 | + |
| 28 | +e1 = Entry(frame1, width=30, borderwidth=5) |
| 29 | +e1.grid(row=3, columnspan=2, padx=30, pady=15) |
| 30 | + |
| 31 | + |
| 32 | +# Function for the button - show details |
| 33 | +def show_details(): |
| 34 | + # creating connection |
| 35 | + |
| 36 | + authentication = HTTPBasicAuth(e1.get(), "password") |
| 37 | + data = requests.get('https://api.github.com/users/' + e1.get(), |
| 38 | + auth=authentication) |
| 39 | + # getting data |
| 40 | + user_data = data.json() |
| 41 | + |
| 42 | + # storing data in a string |
| 43 | + |
| 44 | + a = "\n\t\tINFO OF {} ----".format(e1.get()) + "\n\n\n\tName - \t {}".format( |
| 45 | + user_data['name']) + "\n\n\tEmail - \t {}".format( |
| 46 | + user_data['email']) + "\n\n\tId - \t {}".format( |
| 47 | + user_data['id']) + "\n\n\tLocation - \t {}".format( |
| 48 | + user_data['location']) + "\n\n\tFollowers - \t {}".format( |
| 49 | + user_data['followers']) + "\n\n\tFollowing - \t {}".format( |
| 50 | + user_data['following']) + "\n\n\tPublic repos - \t {}".format( |
| 51 | + user_data['public_repos']) + "\n\n\tRepos_url - \t{}".format( |
| 52 | + user_data['repos_url']) + "\n\n\tBio - \t {}".format( |
| 53 | + user_data['bio']) |
| 54 | + |
| 55 | + # Frame2 |
| 56 | + |
| 57 | + frame2 = LabelFrame(root, width=70, height=150) |
| 58 | + frame2.grid(row=0, column=1, padx=5, pady=5) |
| 59 | + |
| 60 | + # Text field |
| 61 | + |
| 62 | + t1 = Text(frame2, width=70, font=("Arial", 10)) |
| 63 | + t1.insert(INSERT, a) |
| 64 | + |
| 65 | + t1.grid(row=2, column=1) |
| 66 | + t1.configure(state='disabled') |
| 67 | + |
| 68 | + # function for more button |
| 69 | + |
| 70 | + def more(): |
| 71 | + # storing data in a string |
| 72 | + |
| 73 | + b = "\n\n\tUpdated At - \t{}".format( |
| 74 | + user_data['updated_at']) + "\n\n\tSite Admin - \t{}".format( |
| 75 | + user_data['site_admin']) + "\n\n\tHireable - \t{}".format( |
| 76 | + user_data['hireable']) + "\n\n\tNode Id - \t{}".format( |
| 77 | + user_data['node_id']) + "\n\n\tSubscription Url - \t{}".format( |
| 78 | + user_data['subscriptions_url']) + "\n\n\tType - \t{}".format( |
| 79 | + user_data['type']) + "\n\n\tUrl - \t{}".format(user_data['url']) |
| 80 | + |
| 81 | + # Frame3 |
| 82 | + |
| 83 | + frame3 = LabelFrame(root, width=75, height=150) |
| 84 | + frame3.grid(row=0, column=2) |
| 85 | + |
| 86 | + # Text field |
| 87 | + |
| 88 | + t2 = Text(frame3, font=("Arial", 10)) |
| 89 | + t2.insert(INSERT, b) |
| 90 | + t2.grid(row=2, column=1) |
| 91 | + t2.configure(state='disabled') |
| 92 | + |
| 93 | + # Show another function |
| 94 | + |
| 95 | + def show_another(): |
| 96 | + # destroying frames other than main frame |
| 97 | + |
| 98 | + frame2.destroy() |
| 99 | + frame3.destroy() |
| 100 | + |
| 101 | + # deleting the text in the entry box |
| 102 | + |
| 103 | + e1.delete(0, END) |
| 104 | + |
| 105 | + # show another button |
| 106 | + |
| 107 | + show_another_button = Button(frame1, text="Check Another", command=show_another, bg="yellow", anchor=W, |
| 108 | + fg="black") |
| 109 | + show_another_button.grid(row=13, column=1) |
| 110 | + |
| 111 | + # create a button for more data |
| 112 | + |
| 113 | + more_button = Button(frame2, text="More info", command=more, bg="yellow", fg="black") |
| 114 | + more_button.grid(row=13, column=1) |
| 115 | + |
| 116 | + |
| 117 | +# creating button - Show details |
| 118 | + |
| 119 | +show_details_button = Button(frame1, text="Show Details", command=show_details, bg="yellow", fg="black") |
| 120 | +show_details_button.grid(row=7, columnspan=2, padx=10, pady=20) |
| 121 | + |
| 122 | + |
| 123 | +# credits function |
| 124 | + |
| 125 | +def credits_for_project(): |
| 126 | + credit_string = "\n\n\t\t\tCREDITS--\n\n\tTHIS BASIC APPLICATION COULD NOT HAVE BEEN DONE WITHOUT\n\n" \ |
| 127 | + "\tTHE HELP OF -\n\n" \ |
| 128 | + "\tGOOGLE , TUTORIALSPOINT, GEEKSFORGEEKS. \n\n" \ |
| 129 | + "\tI was not aware about all the widgets in TKINTER PYTHON and \n\n" \ |
| 130 | + "\tcreating a connection between host site and customer.\n\n" \ |
| 131 | + "\tI took some basic help from these sites.\n\n" \ |
| 132 | + "\tTHANK YOU !\n\n" \ |
| 133 | + "\twww.google.com\n\n" \ |
| 134 | + "\twww.tutorialspoint.com\n\n" \ |
| 135 | + "\twww.geeksforgeeks.org" |
| 136 | + |
| 137 | + credit_frame = LabelFrame(root, width=75, height=150) |
| 138 | + credit_frame.grid(row=0, column=2) |
| 139 | + |
| 140 | + t2 = Text(credit_frame, font=("Arial", 10)) |
| 141 | + t2.insert(INSERT, credit_string) |
| 142 | + t2.grid(row=2, column=1) |
| 143 | + t2.configure(state='disabled') |
| 144 | + |
| 145 | + |
| 146 | +# Credit button |
| 147 | + |
| 148 | +credits_button = Button(root, text="Credits", command=credits_for_project, fg="blue") |
| 149 | +credits_button.grid(row=15, column=1) |
| 150 | + |
| 151 | + |
| 152 | +# About this Application Function |
| 153 | + |
| 154 | +def about_this_application(): |
| 155 | + about_text = "\t\tLittle About me --\n\nHello I'm currently a 1st year student in\n\n" \ |
| 156 | + "Institute of Technical Education and Research\n\n" \ |
| 157 | + "This is my 1st attempt in any coding competition.\n\n\t\tLittle about Project--\n\n" \ |
| 158 | + "Here I present you a very basic application which can extract data\n\n" \ |
| 159 | + "from GITHUB profile. The modules used are -\n\n" \ |
| 160 | + "TKINTER, PYTHON\n\n" \ |
| 161 | + "REQUESTS/HTTPBasicAUTH, PYTHON\n\n" \ |
| 162 | + "Tkinter is used to create GUI , while requests\n\n" \ |
| 163 | + "HTTPBasicAUTH is used to create a connection between host site and customer.\n" \ |
| 164 | + "After the connection is made we simply request for the data\n\n" \ |
| 165 | + "and store it in a variable, since the data extracted is quite complex\n\n" \ |
| 166 | + "I have used JSON to extract data from the variable.\n\n" \ |
| 167 | + "THANK YOU !" |
| 168 | + |
| 169 | + about_frame = LabelFrame(root, width=75, height=150) |
| 170 | + about_frame.grid(row=0, column=2) |
| 171 | + |
| 172 | + t2 = Text(about_frame, font=("Arial", 10)) |
| 173 | + t2.insert(INSERT, about_text) |
| 174 | + t2.grid(row=2, column=1) |
| 175 | + t2.configure(state='disabled') |
| 176 | + |
| 177 | + |
| 178 | +about_button = Button(root, text="About:", command=about_this_application, fg="blue", anchor=W) |
| 179 | +about_button.grid(row=10, column=0) |
| 180 | + |
| 181 | +root.mainloop() |
0 commit comments