This repository has been archived by the owner on Nov 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.py
143 lines (125 loc) · 3.7 KB
/
main.py
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
# Idea from: https://github.com/RealPeha/
import os
import sys
import logging
import requests
from time import sleep
from github import Github as PyGithub
logging.basicConfig(level=logging.INFO, format=f"[\x1b[38;5;199mGithub\x1b[0m] \x1b[38;5;199m->\x1b[0m %(message)s")
if sys.platform == "linux":
clear = lambda: os.system("clear")
else:
clear = lambda: os.system("cls")
Check_Interval = 60
Milestone_Step = 500
Repository_ID = "REPO_ID"
Access_Token = "ACCESS_TOKEN"
github = PyGithub(Access_Token)
headers = {
"Authorization": f"token {Access_Token}"
}
milestones = [
":broken_heart:",
":heart:",
":orange_heart:",
":purple_heart:",
":yellow_heart:",
":heartpulse:",
":sparkling_heart:",
":gift_heart:",
":heartbeat:",
":two_hearts:",
":revolving_hearts:"
]
def Milestone_Emoji(stars: int):
Milestone_Index = round(stars / 500)
return milestones[Milestone_Index]
def Get_Repo_Stars():
try:
r = requests.get(f"https://api.github.com/repositories/{Repository_ID}", headers=headers)
return r.json()["stargazers_count"]
except:
return False
def Rename_Repo(json):
try:
r = requests.patch(f"https://api.github.com/repositories/{Repository_ID}", headers=headers, json=json)
if "id" in r.text:
return True
else:
return False
except:
return False
def Get_Stargazers():
try:
stargazers = []
r = requests.get(f"https://api.github.com/repositories/{Repository_ID}/stargazers", headers=headers)
for user in r.json():
stargazers.append(user["login"])
if stargazers == []:
return ["No stargazers..."]
return stargazers
except Exception as error:
logging.info(f"Unknown Error \x1b[38;5;199m->\x1b[0m {error}")
return False
def Get_Forks():
try:
forks = []
r = requests.get(f"https://api.github.com/repositories/{Repository_ID}/forks", headers=headers)
for user in r.json():
forks.append(user["owner"]["login"])
if forks == []:
return ["No forks..."]
else:
return forks
except Exception as error:
logging.info(f"Unknown Error \x1b[38;5;199m->\x1b[0m {error}")
return False
def Update_Readme():
try:
content = "# Information\n`If you would like to be on this repo's readme`</br>`simply fork or star it!`</br>\n"
content += "# Forks\n"
count = 1
for user in Get_Forks():
content += f"`{count}` - `{user}`</br>"
count += 1
content += "\n# Stargazers\n"
count = 1
for user in Get_Stargazers():
content += f"`{count}` - `{user}`</br>"
count += 1
stars = Get_Repo_Stars()
repo = github.get_user().get_repo(f"This-Repo-Has-{stars}-Stars")
file = repo.get_contents("README.md")
repo.update_file("README.md", "Update README.md", content, file.sha)
return True
except Exception as error:
logging.info(f"Unknown Error \x1b[38;5;199m->\x1b[0m {error}")
return False
def Task():
try:
logging.info("Started task!")
while True:
stars = Get_Repo_Stars()
if stars != False:
rename = Rename_Repo({
"name": f"This-Repo-Has-{stars}-Stars",
"description": f"Yes it's true {Milestone_Emoji(stars)}"
})
if rename != False:
logging.info(f"Renamed repo, stars count is now \x1b[38;5;199m@\x1b[0m {stars}")
else:
logging.info(f"Failed to rename repo, stars count is now \x1b[38;5;199m@\x1b[0m {stars}")
update = Update_Readme()
if update != False:
logging.info(f"Updated file \x1b[38;5;199m->\x1b[0m README.md")
else:
logging.info(f"Failed to update file \x1b[38;5;199m->\x1b[0m README.md")
else:
logging.info(f"Failed to fetch stars!")
logging.info(f"Now waiting {Check_Interval} seconds!")
sleep(Check_Interval)
except Exception as error:
logging.info(f"Unknown Error \x1b[38;5;199m->\x1b[0m {error}")
if __name__ == "__main__":
clear()
Task()