Advertisement
ipetkov

github users

Dec 27th, 2023
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.63 KB | None | 0 0
  1. import requests
  2. import tkinter as tk
  3. from tkinter import ttk
  4. from tkinter import messagebox
  5.  
  6. def get_user_followers(username):
  7.     url = f"https://api.github.com/users/{username}/followers"
  8.     response = requests.get(url)
  9.     if response.status_code == 200:
  10.         followers = [follower["login"] for follower in response.json()]
  11.         return followers
  12.     else:
  13.         messagebox.showerror("Error", f"Failed to retrieve followers for {username}.")
  14.         return []
  15.  
  16. def get_user_following(username):
  17.     url = f"https://api.github.com/users/{username}/following"
  18.     response = requests.get(url)
  19.     if response.status_code == 200:
  20.         following = [user["login"] for user in response.json()]
  21.         return following
  22.     else:
  23.         messagebox.showerror("Error", f"Failed to retrieve following for {username}.")
  24.         return []
  25.  
  26. def find_users_not_following_back():
  27.     username = entry.get()
  28.  
  29.     if not username:
  30.         messagebox.showwarning("Warning", "Please enter your GitHub username.")
  31.         return
  32.  
  33.     followers = get_user_followers(username)
  34.     following = get_user_following(username)
  35.  
  36.     not_following_back = [user for user in following if user not in followers]
  37.  
  38.     # Clear the text widget
  39.     result_text.delete(1.0, tk.END)
  40.  
  41.     # Display the result
  42.     label_result.config(text=f"Users not following you back ({username}):")
  43.     for user in not_following_back:
  44.         result_text.insert(tk.END, f"{user}\n")
  45.  
  46. # Create the main window
  47. window = tk.Tk()
  48. window.title("GitHub Follower Analyzer")
  49. window.geometry("400x300")
  50.  
  51. # Create a label and an entry field for the username
  52. label = ttk.Label(window, text="Enter your GitHub username:")
  53. label.pack(pady=10)
  54.  
  55. entry = ttk.Entry(window, width=30)
  56. entry.pack()
  57.  
  58. # Create a button to initiate the search
  59. button = ttk.Button(window, text="Find Users", command=find_users_not_following_back)
  60. button.pack(pady=10)
  61.  
  62. # Create a label for the result
  63. label_result = ttk.Label(window, text="Users not following you back:")
  64. label_result.pack(pady=5)
  65.  
  66. # Create a frame for the result text and scrollbar
  67. result_frame = ttk.Frame(window)
  68. result_frame.pack(fill=tk.BOTH, expand=True)
  69.  
  70. # Create a text box to display the result
  71. result_text = tk.Text(result_frame, height=8, width=40)
  72. result_text.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
  73.  
  74. # Configure the text box with a scroll bar
  75. scrollbar = ttk.Scrollbar(result_frame, orient=tk.VERTICAL, command=result_text.yview)
  76. scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
  77.  
  78. result_text.configure(yscrollcommand=scrollbar.set, wrap="none")  # Add wrap="none"
  79.  
  80. # Start the UI main loop
  81. window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement