|
| 1 | +from flask import Blueprint, current_app, jsonify |
| 2 | +from dotenv import load_dotenv |
| 3 | +from src.utils.project_img import ParseOSCrepo |
| 4 | +import requests |
| 5 | + |
| 6 | +load_dotenv() |
| 7 | +projects_bp = Blueprint("projects_bp", __name__, url_prefix="/projects") |
| 8 | + |
| 9 | + |
| 10 | +def img_link(github_repolink): # Web scraping the image link from github |
| 11 | + req = requests.get(f"{github_repolink}") |
| 12 | + parseObj = ParseOSCrepo() |
| 13 | + parseObj.feed(req.text) |
| 14 | + return parseObj.token |
| 15 | + |
| 16 | + |
| 17 | +@projects_bp.route("/", methods=["GET"]) |
| 18 | +def project_info(): |
| 19 | + current_app.config["JSON_SORT_KEYS"] = False |
| 20 | + results = [] |
| 21 | + req = requests.get( |
| 22 | + "https://api.github.com/users/Open-Source-Community-VIT-AP/repos" |
| 23 | + ) |
| 24 | + jsonfile = req.json() |
| 25 | + |
| 26 | + for i in jsonfile: # Formatting the data |
| 27 | + results.append( |
| 28 | + { |
| 29 | + "Stars": i["stargazers_count"], |
| 30 | + "Name": i["name"], |
| 31 | + "Description": i["description"], |
| 32 | + "Image": img_link(i["html_url"]), |
| 33 | + "Repository_link": i["html_url"], |
| 34 | + "SSH": i["ssh_url"], |
| 35 | + } |
| 36 | + ) |
| 37 | + |
| 38 | + for i in range(len(results)): # Sorting according to stars |
| 39 | + for j in range(len(results) - 1): |
| 40 | + if results[j]["Stars"] < results[j + 1]["Stars"]: |
| 41 | + results[j], results[j + 1] = results[j + 1], results[j] |
| 42 | + |
| 43 | + for i in results: # Removing stars from the results |
| 44 | + del i["Stars"] |
| 45 | + |
| 46 | + return jsonify(results[0:10]) |
0 commit comments