├── LICENSE ├── README.md ├── app.py └── requirements.txt /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Rohit Chouhan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohit-chouhan/github-automation/e6434cfcd82d76f77cfb76c589a5a5092c07de57/README.md -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | #==========================================# 2 | # Developed by : github.com/rohit-chouhan, github.com/7k5x 3 | # License : MIT 4 | # Last Update : August 14, 2021 5 | #==========================================# 6 | import requests 7 | #Using GetPass, so you should have Python 2.5 or higher 8 | import getpass 9 | 10 | 11 | 12 | #KeyboardInterrupt in loop means Ctrl+C 13 | 14 | def follow(t): 15 | page = 1 16 | indexing = 0 17 | try: 18 | limit=int(input("\n Enter Follow Limit: ")) 19 | except ValueError: 20 | limit=1000000 21 | except: 22 | exit(1) 23 | try: 24 | user=str(input(" Enter The User name of Person to Follow their Followers: ")) 25 | except: 26 | print("Please enter your username") 27 | exit(1) 28 | for i in range(limit): 29 | try: 30 | response = requests.get('https://api.github.com/users/'+user+'/followers?page='+str(page), headers= {'Authorization' : 'Bearer '+t+''}) 31 | except KeyboardInterrupt: 32 | print('\n') 33 | exit(0) 34 | except: 35 | print("Error getting response") 36 | try: 37 | res = response.json() 38 | except KeyboardInterrupt: 39 | print('\n') 40 | exit(0) 41 | except: 42 | print("Error parsing JSON") 43 | try: 44 | requests.put('https://api.github.com/user/following/'+res[indexing]['login'], headers= {'Authorization' : 'Bearer '+t+''}) 45 | print(" ("+str(i+1)+") Followed User Successfully: @"+res[indexing]['login']) 46 | #IndexError is caused when your limit is over the number of followers the user has, so it's not an error to worry about 47 | except IndexError: 48 | break 49 | except KeyboardInterrupt: 50 | print('\n') 51 | exit(0) 52 | except: 53 | try: 54 | print("Error following user @"+res[indexing]['login']) 55 | except: 56 | print("Error following user "+str(i+1)) 57 | #There are 30 people(0~29) per API page index. This might change later on. 58 | if indexing==29: 59 | page+=1 60 | indexing=0 61 | elif i==limit: 62 | break 63 | else: 64 | pass 65 | indexing+=1 66 | 67 | print("\n\n===== Task Completed =====") 68 | print("\n\nNote: Github takes 5-10min to update!") 69 | 70 | def unfollow(u,t): 71 | page = 1 72 | indexing = 0 73 | try: 74 | limit=int(input("\n Enter UnFollow Limit: ")) 75 | except ValueError: 76 | #10M is more than enough 77 | limit=1000000 78 | except: 79 | exit(1) 80 | for i in range(limit): 81 | try: 82 | response = requests.get('https://api.github.com/users/'+u+'/following?page='+str(page), headers= {'Authorization' : 'Bearer '+t+''}) 83 | except KeyboardInterrupt: 84 | print('\n') 85 | exit(0) 86 | except: 87 | print("Error getting response") 88 | try: 89 | res = response.json() 90 | except KeyboardInterrupt: 91 | print('\n') 92 | exit(0) 93 | except: 94 | print("Error parsing JSON") 95 | try: 96 | requests.delete('https://api.github.com/user/following/'+res[indexing]['login'], headers= {'Authorization' : 'Bearer '+t+''}) 97 | print(" ("+str(i+1)+") Unfollowed User Successfully: @"+res[indexing]['login']) 98 | #IndexError is caused when your limit is over the number of followers the user has, so it's not an error to worry about 99 | except KeyboardInterrupt: 100 | print('\n') 101 | exit(0) 102 | except IndexError: 103 | break 104 | except: 105 | try: 106 | print("Error unfollowing user @"+res[indexing]['login']) 107 | except: 108 | print("Error unfollowing user "+str(i+1)) 109 | #There are 30 people(0~29) per API page index. This might change later on. 110 | if indexing==29: 111 | page+=1 112 | indexing=0 113 | elif i==limit: 114 | break 115 | else: 116 | pass 117 | indexing+=1 118 | 119 | print("\n\n===== Task Completed =====") 120 | print("\n\nNote: Github takes some time to update!") 121 | 122 | print("============Github Tool by @rohit-chouhan =============") 123 | 124 | try: 125 | username=input("Your Username: ") 126 | except KeyboardInterrupt: 127 | print('\n') 128 | exit(0) 129 | except: 130 | print('Error in input') 131 | exit(1) 132 | #Use getpass for token security 133 | try: 134 | usertoken=getpass.getpass('Token: ') 135 | except KeyboardInterrupt: 136 | print('\n') 137 | exit(0) 138 | except: 139 | print('Error in input') 140 | 141 | #GetPass doesn't show your stuff, so you could enter the wrong thing. This solves the problem. 142 | if not usertoken.startswith("ghp_"): 143 | print('You didn\'t input a proper access token. It should start with ghp_ and should be 40 letters in length.') 144 | exit(1) 145 | if len(usertoken)>40 or len(usertoken)<40: 146 | print('You didn\'t input a proper access token. It should start with ghp_ and should be 40 letters in length.') 147 | exit(1) 148 | 149 | print("\n\n========= Tools ===========") 150 | print("1.Follow\n2.Unfollow") 151 | try: 152 | ans = input("\nYour Choice: ") 153 | except KeyboardInterrupt: 154 | print('\n') 155 | exit(0) 156 | except: 157 | print('Error in input') 158 | 159 | if ans=="1": 160 | follow(usertoken) 161 | elif ans=="2": 162 | unfollow(username,usertoken) 163 | else: 164 | print("Wrong input") 165 | exit(1) 166 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | requests 2 | --------------------------------------------------------------------------------