Spaces:
Starting
Starting
minor changes
Browse files- README.md +2 -0
- main.py +20 -0
- requirements.txt +2 -1
README.md
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Api is hosted on HF:
|
| 2 |
+
https://huggingface.co/spaces/arpy8/github-repo-scraper/
|
main.py
CHANGED
|
@@ -7,6 +7,8 @@ from flask_cors import CORS
|
|
| 7 |
app = Flask(__name__)
|
| 8 |
CORS(app)
|
| 9 |
|
|
|
|
|
|
|
| 10 |
def fetch_github_page(**kwargs):
|
| 11 |
try:
|
| 12 |
params = '&'.join([f'{k}={v}' for k, v in kwargs.items()])
|
|
@@ -40,6 +42,23 @@ def parse_repositories(page_content):
|
|
| 40 |
|
| 41 |
return repositories
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
@app.route('/data/<string:lang>')
|
| 44 |
def get_repos(lang):
|
| 45 |
page_content = fetch_github_page(l=lang)
|
|
@@ -49,5 +68,6 @@ def get_repos(lang):
|
|
| 49 |
repositories = parse_repositories(page_content)
|
| 50 |
return json.dumps(repositories, indent=4)
|
| 51 |
|
|
|
|
| 52 |
if __name__ == '__main__':
|
| 53 |
app.run(port=8000, debug=True)
|
|
|
|
| 7 |
app = Flask(__name__)
|
| 8 |
CORS(app)
|
| 9 |
|
| 10 |
+
LANGUAGES = ["python", "javascript", "html", "typescript", "java", "cpp", "php", "go", "css", "c"]
|
| 11 |
+
|
| 12 |
def fetch_github_page(**kwargs):
|
| 13 |
try:
|
| 14 |
params = '&'.join([f'{k}={v}' for k, v in kwargs.items()])
|
|
|
|
| 42 |
|
| 43 |
return repositories
|
| 44 |
|
| 45 |
+
@app.route('/all')
|
| 46 |
+
def get_all_repos():
|
| 47 |
+
payload = {}
|
| 48 |
+
|
| 49 |
+
for lang in LANGUAGES:
|
| 50 |
+
page_content = fetch_github_page(l=lang)
|
| 51 |
+
|
| 52 |
+
if isinstance(page_content, str) and page_content.startswith("Error"):
|
| 53 |
+
return page_content
|
| 54 |
+
|
| 55 |
+
repositories = parse_repositories(page_content)
|
| 56 |
+
payload[lang] = repositories
|
| 57 |
+
|
| 58 |
+
print(payload)
|
| 59 |
+
|
| 60 |
+
return json.dumps(payload, indent=4)
|
| 61 |
+
|
| 62 |
@app.route('/data/<string:lang>')
|
| 63 |
def get_repos(lang):
|
| 64 |
page_content = fetch_github_page(l=lang)
|
|
|
|
| 68 |
repositories = parse_repositories(page_content)
|
| 69 |
return json.dumps(repositories, indent=4)
|
| 70 |
|
| 71 |
+
|
| 72 |
if __name__ == '__main__':
|
| 73 |
app.run(port=8000, debug=True)
|
requirements.txt
CHANGED
|
@@ -2,4 +2,5 @@ Flask==3.0.3
|
|
| 2 |
beautifulsoup4==4.12.3
|
| 3 |
requests==2.32.3
|
| 4 |
html5lib==1.1
|
| 5 |
-
flask-cors==5.0.0
|
|
|
|
|
|
| 2 |
beautifulsoup4==4.12.3
|
| 3 |
requests==2.32.3
|
| 4 |
html5lib==1.1
|
| 5 |
+
flask-cors==5.0.0
|
| 6 |
+
gunicorn
|