|
1 |
| -# GitHub Follow by Username |
| 1 | +# 🚀 GitHub Follow by Username |
2 | 2 |
|
3 |
| -## Introduction |
4 |
| -`GitHub Follow by Username` is a Python script that allows you to follow GitHub users by their usernames from a list in a file. This tool is particularly useful for managing your followings on GitHub efficiently. |
| 3 | +## 🎉 Introduction |
5 | 4 |
|
6 |
| -## Features |
7 |
| -- Follow any GitHub user by their username. |
8 |
| -- Specify the starting line to continue following users from a specific point. |
9 |
| -- Handles GitHub rate limits with a delay between follow actions. |
| 5 | +`GitHub Follow by Username` is a Python script that allows you to **follow GitHub users efficiently** by reading their usernames from a file. Leveraging asynchronous programming with `asyncio` and `aiohttp`, this tool manages GitHub's API rate limits gracefully while providing robust logging and resuming capabilities. |
10 | 6 |
|
11 |
| -## Installation |
12 |
| -### Prerequisites |
13 |
| -- Python 3.6 or higher |
14 |
| -- GitHub personal access token |
| 7 | +## ⭐ Features |
| 8 | + |
| 9 | +- **🔄 Asynchronous Operations:** Utilizes `asyncio` and `aiohttp` for concurrent API requests, enhancing performance. |
| 10 | +- **⏱️ Rate Limit Handling:** Dynamically manages GitHub API rate limits by monitoring response headers and implementing backoff strategies. |
| 11 | +- **🔁 Resumable Execution:** Tracks the last processed username to allow resuming from where the script left off in case of interruptions. |
| 12 | +- **📝 Comprehensive Logging:** Logs detailed information about each follow action, successes, failures, and rate limit statuses to both the console and a log file. |
| 13 | +- **🔒 Secure Token Management:** Uses environment variables to handle GitHub Personal Access Tokens (PAT) securely, preventing accidental exposure. |
| 14 | +- **⚙️ Concurrency Control:** Limits the number of concurrent API requests to avoid triggering GitHub's abuse detection mechanisms. |
| 15 | + |
| 16 | +## 📦 Installation |
| 17 | + |
| 18 | +### 🛠️ Prerequisites |
| 19 | + |
| 20 | +- **🐍 Python 3.6 or higher** |
| 21 | +- **🔑 GitHub Personal Access Token (PAT)** |
| 22 | + - **Scopes Required:** `read:user`, `user:follow` |
| 23 | + - [Creating a PAT](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) |
| 24 | + |
| 25 | +### 📜 Steps |
| 26 | + |
| 27 | +1. **Clone the Repository:** |
15 | 28 |
|
16 |
| -### Steps |
17 |
| -1. Clone the repository: |
18 | 29 | ```sh
|
19 | 30 | git clone https://github.com/OfficialCodeVoyage/GitHub_follow_by_username.git
|
20 | 31 | cd GitHub_follow_by_username
|
21 | 32 | ```
|
22 | 33 |
|
23 |
| -2. Install the required Python packages: |
| 34 | +2. **Set Up a Virtual Environment (Optional but Recommended):** |
| 35 | + |
24 | 36 | ```sh
|
25 |
| - pip install requests |
26 |
| - pip install time |
| 37 | + python -m venv venv |
| 38 | + # Activate the virtual environment: |
| 39 | + # On Windows: |
| 40 | + venv\Scripts\activate |
| 41 | + # On macOS/Linux: |
| 42 | + source venv/bin/activate |
27 | 43 | ```
|
28 | 44 |
|
29 |
| -## Usage |
30 |
| -1. Create a file named `usernames.txt` in the same directory as the script and add the GitHub usernames you want to follow, one per line. |
| 45 | +3. **Install the Required Python Packages:** |
31 | 46 |
|
32 |
| -2. Run the script with your GitHub personal access token and specify the line number to start from (0-indexed). Replace `'your_github_personal_access_token'` with your actual GitHub personal access token and set the `START_LINE` as needed: |
| 47 | + It's recommended to use a `requirements.txt` file for managing dependencies. Ensure you have a `requirements.txt` file with the following content: |
33 | 48 |
|
34 |
| - ```python |
35 |
| - if __name__ == "__main__": |
36 |
| - FILE_PATH = 'usernames.txt' # Path to the usernames file |
37 |
| - TOKEN = 'your_github_personal_access_token' # Your GitHub personal access token |
38 |
| - START_LINE = 0 # The line number to start from (0-indexed) |
| 49 | + ```plaintext |
| 50 | + aiohttp |
| 51 | + python-dotenv |
| 52 | + ``` |
| 53 | +
|
| 54 | + Then, install the dependencies: |
39 | 55 |
|
40 |
| - main(FILE_PATH, TOKEN, START_LINE) |
| 56 | + ```sh |
| 57 | + pip install -r requirements.txt |
41 | 58 | ```
|
42 | 59 |
|
43 |
| -### Script Details |
44 |
| -- **read_usernames(file_path)**: Reads usernames from a specified file and returns them as a list. |
45 |
| -- **follow_user(username, headers)**: Sends a PUT request to the GitHub API to follow a user. |
46 |
| -- **main(file_path, token, start_line)**: Reads the usernames from the file and follows users starting from the specified line. It handles rate limits by adding a delay between follow actions. |
| 60 | + **⚠️ Note:** Avoid installing standard library modules like `time` via `pip` as they are already included with Python. |
| 61 | +
|
| 62 | +## 🛠️ Usage |
| 63 | +
|
| 64 | +### 1. **🔧 Configure Environment Variables** |
| 65 | +
|
| 66 | +Create a `.env` file in the root directory of the project to securely store your GitHub PAT and other configurations. |
| 67 | +
|
| 68 | +```dotenv |
| 69 | +GITHUB_TOKEN=your_github_personal_access_token_here |
| 70 | +USERNAMES_FILE=usernames.txt |
| 71 | +LAST_LINE_FILE=last_line.txt |
| 72 | +``` |
| 73 | +
|
| 74 | +### 2. 📄 Prepare the Usernames File |
| 75 | +
|
| 76 | +Create a file named usernames.txt in the same directory as the script and add the GitHub usernames you want to follow, |
| 77 | +one per line. You are welcome to use my file as an example. |
| 78 | +
|
| 79 | +### 3. 🚀 Run the Script |
| 80 | +
|
| 81 | +```sh |
| 82 | +python follow_users.py |
| 83 | +``` |
| 84 | +
|
| 85 | +🔍 Optional Parameters: |
| 86 | +
|
| 87 | +If you want to specify a starting line number (useful for resuming), you can modify the .env file: |
| 88 | +
|
| 89 | +```dotenv |
| 90 | +START_LINE=0# Change to the desired line number (0-indexed) |
| 91 | +``` |
| 92 | +📝 Note: The script automatically resumes from the last processed line by reading the last_line.txt file. Adjusting START_LINE can override this behavior if needed. |
| 93 | +
|
| 94 | +## 🔍 Script Details |
| 95 | +
|
| 96 | +### 📚 Modules and Dependencies |
| 97 | +
|
| 98 | +- **`asyncio` & `aiohttp`:** For asynchronous HTTP requests to the GitHub API. |
| 99 | +- **`python-dotenv`:** For loading environment variables from the `.env` file. |
| 100 | +- **`logging`:** For comprehensive logging of the script's operations. |
| 101 | +- **`os` & `time`:** For environment variable management and handling rate limits. |
| 102 | + |
| 103 | +### 🔑 Key Functions |
| 104 | + |
| 105 | +- **`read_usernames(file_path: str) -> List[str]`:** |
| 106 | + Reads GitHub usernames from the specified file and returns them as a list. |
| 107 | + |
| 108 | +- **`follow_user(session: aiohttp.ClientSession, username: str) -> Tuple[int, str]`:** |
| 109 | + Sends a PUT request to the GitHub API to follow the specified user. |
| 110 | + |
| 111 | +- **`handle_rate_limit(headers: dict)`:** |
| 112 | + Checks the response headers for rate limit information and sleeps if the rate limit has been reached. |
| 113 | + |
| 114 | +- **`write_last_line(file_path: str, line_number: int) -> None`:** |
| 115 | + Writes the last processed line number to a file to enable resuming. |
| 116 | + |
| 117 | +- **`main()`:** |
| 118 | + Orchestrates reading usernames, following users asynchronously, handling rate limits, and logging. |
| 119 | +handling rate limits, and logging. |
| 120 | +
|
| 121 | +## 🤝 Contributing |
47 | 122 |
|
48 |
| -## Contributing |
49 | 123 | We welcome contributions from the community! Here’s how you can help:
|
50 | 124 |
|
51 |
| -1. Fork the repository. |
52 |
| -2. Create a new branch (`git checkout -b feature-branch`). |
53 |
| -3. Make your changes and commit them (`git commit -m 'Add new feature'`). |
54 |
| -4. Push to the branch (`git push origin feature-branch`). |
55 |
| -5. Open a pull request. |
| 125 | +1. **Fork the Repository.** |
| 126 | +
|
| 127 | +2. **Create a New Branch:** |
| 128 | +
|
| 129 | + ```sh |
| 130 | + git checkout -b feature-branch |
| 131 | + ``` |
| 132 | +
|
| 133 | +3. **Make Your Changes and Commit Them:** |
| 134 | +
|
| 135 | + ```sh |
| 136 | + git commit -m "Add new feature" |
| 137 | + ``` |
| 138 | +
|
| 139 | +4. **Push to the Branch:** |
| 140 | +
|
| 141 | + ```sh |
| 142 | + git push origin feature-branch |
| 143 | + ``` |
| 144 | +
|
| 145 | +5. **Open a Pull Request.** |
| 146 | +
|
| 147 | +## 🛡️ Security Best Practices |
| 148 | +
|
| 149 | +- **🚫 Never Commit `.env` Files:** |
| 150 | + Ensure that `.env` is listed in `.gitignore` to prevent accidental commits of sensitive information. |
| 151 | +
|
| 152 | +- **🔒 Use Git Hooks to Prevent Secret Exposure:** |
| 153 | + Implement tools like `git-secrets` to scan for sensitive data before allowing commits. |
| 154 | +
|
| 155 | +- **🔄 Regularly Rotate Personal Access Tokens (PATs):** |
| 156 | + Periodically revoke and regenerate PATs to minimize the risk of unauthorized access. |
| 157 | +
|
| 158 | +- **👥 Educate Collaborators:** |
| 159 | + Ensure that all team members are aware of best practices for handling secrets and sensitive information. |
| 160 | +
|
| 161 | +## 📜 License |
56 | 162 |
|
57 |
| -## License |
58 | 163 | This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
| 164 | +
|
| 165 | +## 📚 Additional Resources |
| 166 | +
|
| 167 | +- **📖 GitHub REST API Documentation:** |
| 168 | + [https://docs.github.com/en/rest](https://docs.github.com/en/rest) |
| 169 | +
|
| 170 | +- **🛠️ BFG Repo-Cleaner:** |
| 171 | + [https://rtyley.github.io/bfg-repo-cleaner/](https://rtyley.github.io/bfg-repo-cleaner/) |
| 172 | +
|
| 173 | +- **🔐 GitHub Secret Scanning:** |
| 174 | + [https://docs.github.com/en/code-security/secret-scanning](https://docs.github.com/en/code-security/secret-scanning) |
| 175 | +
|
| 176 | +- **📝 GitHub CLI Documentation:** |
| 177 | + [https://cli.github.com/manual/](https://cli.github.com/manual/) |
0 commit comments