-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport_github_stars.sh
executable file
·204 lines (172 loc) · 7.17 KB
/
export_github_stars.sh
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/bin/bash
# GitHub Stars Export Script - Foolproof Edition
# This script helps export GitHub starred repositories without requiring any technical knowledge
# Configuration - edit these variables (leaving blank is fine - you'll be prompted)
GITHUB_USERNAME="" # Your GitHub username
GITHUB_TOKEN="" # Your GitHub personal access token (optional)
ICLOUD_DIR="/Users/maximvs/Library/Mobile Documents/com~apple~CloudDocs/00X_000_JORDAN-PARKER-PLANS/Memory-🧿/00_GitHub/STARRED_github🌟"
# Workspace
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
VENV_DIR="${SCRIPT_DIR}/venv"
# Color definitions
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo -e "${BLUE}================================================${NC}"
echo -e "${BLUE}GitHub Starred Repositories Exporter${NC}"
echo -e "${BLUE}================================================${NC}"
echo -e "${GREEN}This script will export all your starred repositories from GitHub${NC}"
echo -e "${GREEN}Just answer a few simple questions and it will do everything for you.${NC}"
echo
# Check if Python 3 is installed
if ! command -v python3 &> /dev/null; then
echo -e "${RED}Python 3 is required but not installed.${NC}"
echo -e "${YELLOW}Please install Python 3 from python.org and try again.${NC}"
exit 1
fi
# Set up virtual environment to avoid system package issues
echo -e "${BLUE}Setting up Python environment...${NC}"
if [ ! -d "$VENV_DIR" ]; then
echo -e "${GREEN}Creating virtual environment...${NC}"
python3 -m venv "$VENV_DIR" || {
echo -e "${RED}Failed to create virtual environment. Trying an alternative method...${NC}"
# Try with the -m venv module directly
python3 -m venv "$VENV_DIR" || {
echo -e "${RED}Failed to create virtual environment. Please install virtualenv:${NC}"
echo -e "${YELLOW}pip3 install --user virtualenv${NC}"
exit 1
}
}
fi
# Activate virtual environment
echo -e "${GREEN}Activating virtual environment...${NC}"
source "${VENV_DIR}/bin/activate" || {
echo -e "${RED}Failed to activate virtual environment.${NC}"
exit 1
}
# Install required packages in the virtual environment
echo -e "${GREEN}Installing required packages...${NC}"
pip install PyGithub || {
echo -e "${RED}Failed to install PyGithub package.${NC}"
echo -e "${YELLOW}Please check your internet connection and try again.${NC}"
deactivate
exit 1
}
# Get GitHub username if not already set
if [ -z "$GITHUB_USERNAME" ]; then
echo -e "${YELLOW}Enter your GitHub username:${NC}"
read GITHUB_USERNAME
# Validate input isn't empty
while [ -z "$GITHUB_USERNAME" ]; do
echo -e "${RED}Username cannot be empty. Please enter your GitHub username:${NC}"
read GITHUB_USERNAME
done
fi
# Ask about GitHub token if not set
if [ -z "$GITHUB_TOKEN" ]; then
echo -e "${YELLOW}Do you want to use a GitHub personal access token? (recommended) [Y/n]:${NC}"
echo -e "${GREEN}This allows accessing private stars and avoids rate limits${NC}"
read USE_TOKEN
# Default to yes if enter is pressed
if [[ -z "$USE_TOKEN" || $USE_TOKEN =~ ^[Yy]$ ]]; then
echo -e "${YELLOW}Enter your GitHub personal access token:${NC}"
echo -e "${GREEN}(Create one at https://github.com/settings/tokens with 'repo' and 'read:user' scopes)${NC}"
read -s GITHUB_TOKEN
echo
# Check if token is empty but allow continuing
if [ -z "$GITHUB_TOKEN" ]; then
echo -e "${YELLOW}No token entered. Proceeding without authentication.${NC}"
echo -e "${YELLOW}This may result in rate limiting for large numbers of repositories.${NC}"
fi
else
echo -e "${YELLOW}Proceeding without authentication. This may result in rate limiting.${NC}"
fi
fi
# Prepare the Python export script
echo -e "${GREEN}Preparing export script...${NC}"
# Create a custom script with the provided credentials
CUSTOM_SCRIPT="${SCRIPT_DIR}/custom_export.py"
cat > "$CUSTOM_SCRIPT" << EOF
#!/usr/bin/env python3
import os
import sys
import json
import csv
import datetime
from github import Github, GithubException
# Configuration
GITHUB_USERNAME = "${GITHUB_USERNAME}"
GITHUB_TOKEN = "${GITHUB_TOKEN}"
OUTPUT_DIR = "${SCRIPT_DIR}"
# File paths
CSV_FILE = os.path.join(OUTPUT_DIR, "github_stars.csv")
JSON_FILE = os.path.join(OUTPUT_DIR, "github_stars.json")
MARKDOWN_FILE = os.path.join(OUTPUT_DIR, "github_stars.md")
README_FILE = os.path.join(OUTPUT_DIR, "github_stars_README.md")
# Re-use all the functions from the original script
$(cat "${SCRIPT_DIR}/export_github_stars.py" | grep -A 10000 "def get_github_stars" | grep -v "GITHUB_USERNAME")
if __name__ == "__main__":
main()
EOF
# Make the script executable
chmod +x "$CUSTOM_SCRIPT"
# Run the custom script
echo -e "${BLUE}Starting export process...${NC}"
echo -e "${YELLOW}This might take a while depending on how many repositories you've starred.${NC}"
echo -e "${YELLOW}Please be patient...${NC}"
echo
python "$CUSTOM_SCRIPT"
# Check if export was successful
if [ ! -f "${SCRIPT_DIR}/github_stars.csv" ]; then
echo -e "${RED}Export seems to have failed. No output files were created.${NC}"
echo -e "${YELLOW}Please check any error messages above and try again.${NC}"
# Clean up
rm -f "$CUSTOM_SCRIPT"
deactivate
exit 1
fi
# Clean up the custom script
rm -f "$CUSTOM_SCRIPT"
# Ask if user wants to move files to iCloud
echo
echo -e "${YELLOW}Do you want to move the exported files to iCloud? [Y/n]:${NC}"
read MOVE_TO_ICLOUD
# Default to yes if enter is pressed
if [[ -z "$MOVE_TO_ICLOUD" || $MOVE_TO_ICLOUD =~ ^[Yy]$ ]]; then
# Check if the directory exists
if [ ! -d "$ICLOUD_DIR" ]; then
echo -e "${YELLOW}The iCloud directory does not exist. Creating it...${NC}"
mkdir -p "$ICLOUD_DIR" || {
echo -e "${RED}Failed to create iCloud directory.${NC}"
echo -e "${YELLOW}The files will remain in the current directory.${NC}"
deactivate
exit 1
}
fi
# Move the files
echo -e "${GREEN}Moving files to iCloud...${NC}"
cp "${SCRIPT_DIR}/github_stars.csv" "${SCRIPT_DIR}/github_stars.json" "${SCRIPT_DIR}/github_stars.md" "${SCRIPT_DIR}/github_stars_README.md" "$ICLOUD_DIR/" || {
echo -e "${RED}Error: Failed to copy files to iCloud.${NC}"
echo -e "${YELLOW}The files remain in the current directory.${NC}"
deactivate
exit 1
}
echo -e "${GREEN}Files successfully copied to:${NC}"
echo -e "${BLUE}$ICLOUD_DIR${NC}"
# List the files in the iCloud directory
echo -e "${GREEN}Files in iCloud directory:${NC}"
ls -la "$ICLOUD_DIR" | grep github_stars
else
echo -e "${GREEN}Files remain in the current directory:${NC}"
ls -la "${SCRIPT_DIR}" | grep github_stars
fi
# Deactivate virtual environment
deactivate
echo
echo -e "${GREEN}GitHub Stars export completed successfully!${NC}"
echo -e "${BLUE}================================================${NC}"
echo -e "${YELLOW}You can view your starred repositories in the exported files.${NC}"
echo -e "${YELLOW}The markdown file (github_stars.md) is the most human-readable format.${NC}"
echo