-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
repo.py
77 lines (62 loc) · 2.18 KB
/
repo.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
import json
import requests
from bs4 import BeautifulSoup
import time
from datetime import datetime
# datetime object containing current date and time
now = str(datetime.now())
print("now =", now)
# Parsing data from api
def getjson(url):
response = requests.get(url)
return json.loads(response.text)
# Parsing metadata from url
def getBanner(url):
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
metas = soup.find_all('meta') #Get Meta og:image
for m in metas:
if m.get('property') == 'og:image':
banner = m.get('content')
return banner
# color name to css color code list
colors = getjson(
'https://raw.githubusercontent.com/ozh/github-colors/master/colors.json')
# all the repos list which i want to show on website
repos_list = [
"vedic-lang/vedic", "vedicscriptures/bhagavad-gita-api","PtPrashantTripathi/PortfolioTracker",
"PtPrashantTripathi/IPL-2020-Prediction", "PtPrashantTripathi/linkpe",
"PtPrashantTripathi/movieinfo", "PtPrashantTripathi/Shree-Ganesh",
"PtPrashantTripathi/Cloud-Storage-System", "PtPrashantTripathi/Adhyatma",
"PtPrashantTripathi/php-social-networking-site"
]
# execuation timer
start_time = time.time()
# empty list variable for repo variable
repos_data = []
# main fuction
for repo in repos_list:
rdata = getjson(f'https://api.github.com/repos/{repo}')
banner = getBanner(f'https://github.com/{repo}')
data = {
"name": rdata["name"],
"url": rdata["html_url"],
"description": rdata["description"],
"banner": banner,
"color":
colors[rdata["language"]]["color"] if rdata["language"] else '',
"lang": rdata["language"],
"date": rdata["created_at"],
"stars": rdata["stargazers_count"],
"forks": rdata["forks"],
"generatedOn": now
}
repos_data.append(data)
print(f"{repo} done\t--- {time.time() - start_time} seconds ---")
# Serializing json
json_data = json.dumps(repos_data, indent=4)
# Writing to repos.json
with open("repos.json", "w") as outfile:
outfile.write(json_data)
# Total execuation time
print(f"all done\t--- {time.time() - start_time} seconds ---")