-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrename.py
More file actions
79 lines (55 loc) · 2.05 KB
/
rename.py
File metadata and controls
79 lines (55 loc) · 2.05 KB
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
import requests
import os
from dotenv import load_dotenv
from art import *
from os import system, name
load_dotenv()
usr_name = os.getenv('GH_USERNAME')
auth_token = os.getenv("GH_TOKEN")
repo_list_url = f"https://api.github.com/users/{usr_name}/repos"
repo_list = requests.get(repo_list_url).json()
common_files = {"index.html", "style.css", "styles.html", ".gitignore", "script.js", "package.json", "package-lock.json", "README.md"}
headers = {
'Authorization': f'token {auth_token}',
'Content-Type': 'application/json'
}
def clear():
if name == 'nt':
_ = system('cls')
else:
_ = system('clear')
def get_files(current_repo):
file_list = []
repo_list_url = f"https://api.github.com/repos/{usr_name}/{current_repo}/git/trees/main"
repo_list = requests.get(repo_list_url).json()
for i in repo_list['tree']:
if "." in i['path'] and i["path"] not in common_files:
file_list.append(i["path"])
return file_list
try:
for repo in repo_list:
clear()
tprint('\nGITHUB RENAME\n')
print("By Vishnu Vardhan JS\n\n")
print("(press Enter to Skip or Ctrl + c to Quit)\n")
current_repo = repo["name"]
print("Current Repository Name : ", current_repo, "\n")
print("File Peek : ", end="")
cur_files = get_files(current_repo)
if cur_files:
print(cur_files,"\n")
else:
print("No Useful Files Found!...\n")
rename_name = input("Enter New Name : ")
if rename_name == "":
continue
else:
data = {'name': rename_name}
url = f'https://api.github.com/repos/{usr_name}/{current_repo}'
rename_patch = requests.patch(url, headers=headers, json=data)
if rename_patch.status_code==200:
print(f"{current_repo} Rename to {rename_name} Successful!...")
else:
print(f"{current_repo} Rename to {rename_name} Failed!...")
except:
print("Unable To Fetch Repositories Please Try Again Later!\n")