Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Added projects route
  • Loading branch information
Boomer3110 committed Feb 2, 2022
commit ec2c50bb03bdbaf60c44f11edf897c05ee9fe740
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
env
\__pycache__
venv/
ven/
temp
3 changes: 2 additions & 1 deletion src/routes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from flask import Blueprint
from src.routes.events import event
from src.routes.eb_details import eb
from src.routes.projects import projects

api_blueprint = Blueprint("API", __name__, url_prefix="/api/v1/")
api_blueprint.register_blueprint(event.event_bp)
api_blueprint.register_blueprint(eb.eb_bp)

api_blueprint.register_blueprint(projects.projects)

@api_blueprint.route("/", methods=["GET"])
def get_data():
Expand Down
68 changes: 68 additions & 0 deletions src/routes/projects/projects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from flask import Blueprint , jsonify
from dotenv import load_dotenv
import requests
from html.parser import HTMLParser


load_dotenv()
projects = Blueprint("projects", __name__, url_prefix="/projects")


class ParseOSCrepo(HTMLParser): #The HTML parser for scraping img link from
token: str = None

def handle_starttag(self, tag: str, attrs: str):
if self.token:
return

if tag != "meta":
return

token = None
for (index, (k, v)) in enumerate(attrs):
if k == "content":
token = v

if all([k == "property", v == "og:image"]):
if token:
self.token = token
return
for (inner_index, (nk, nv)) in enumerate(attrs, start=index):
if nk == "content":
self.token = nv
return

def imglink(github_repolink): #Web scraping the image link from github
req = requests.get(f'{github_repolink}')
parseObj = ParseOSCrepo()
parseObj.feed(req.text)
return parseObj.token


@projects.route("/", methods=["GET"])
def project_info():
results = []
req = requests.get("https://api.github.com/users/Open-Source-Community-VIT-AP/repos")
jsonfile = req.json()

for i in jsonfile: #Formatting the data
results.append(
{
"stars": i["stargazers_count"],
"Name" : i['name'],
"Description" : i['description'],
"Image" : imglink(i['html_url']),
"Repository_link": i['html_url'],
"ssh" : i["ssh_url"]
}
)

for i in range(len(results)): #Sorting according to stars
for j in range(len(results)-1):
if results[j]['stars']<results[j+1]['stars']:
results[j], results[j+1] = results[j+1],results[j]

for i in results: #Removing stars from the results
del i['stars']

return jsonify(results)