Skip to content

Commit

Permalink
Merge pull request #130 from Exifly/main
Browse files Browse the repository at this point in the history
v1.3.14
  • Loading branch information
gdjohn4s authored May 8, 2023
2 parents a35633a + 99f65af commit 731d1f1
Show file tree
Hide file tree
Showing 33 changed files with 4,092 additions and 154 deletions.
1,684 changes: 1,684 additions & 0 deletions API_LIST.md

Large diffs are not rendered by default.

19 changes: 7 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
<br>
</h1>

![screenshot](./assets/Hero.jpg)

<h3 align="center">Your Gateway To A World Of Public APIs.</h3>
![screenshot](./assets/hero-apivaulot.jpg)

<p align="center">
<a href="#key-features">Key Features</a> •
<a href="#how-to-use">How To Use</a> •
<a href="#credits">Credits</a> •
<a href="#support">Support</a> •
Expand All @@ -20,13 +17,6 @@
<a href="https://github.com/Exifly/ApiVault/issues/new?assignees=&labels=add+api&template=add-your-api.md&title=%5BAPIFT%5D">Click here to submit your API</a>
</h1>

## Key Features

- Dark/Light mode
- Search bar to find your API needs
- Possibility to send or upload your own public API to get listed
- Submit your API


## How To Use

Expand Down Expand Up @@ -116,6 +106,12 @@ Thanks go to these wonderful people ✨:
<td align="center"><a href="https://github.com/caickPassarella"><img src="https://avatars.githubusercontent.com/u/25408543?v=4" width="100px;" alt="Caick"/><br /><sub><b>Caick</b></sub></a><br />🥳</td>
<td align="center"><a href="https://github.com/kotkaravishkar"><img src="https://avatars.githubusercontent.com/u/94035734?v=4" width="100px;" alt="Avishkar Kotkar
"/><br /><sub><b>Avishkar Kotkar
</b></sub></a><br />🥳</td>
<td align="center"><a href="https://github.com/iamjamesfrancis"><img src="https://avatars.githubusercontent.com/u/55175085?v=4" width="100px;" alt="James Francis
"/><br /><sub><b>James Francis
</b></sub></a><br />🥳</td>
<td align="center"><a href="https://github.com/MOHDNEHALKHAN"><img src="https://avatars.githubusercontent.com/u/125626654?v=4" width="100px;" alt="MOHD NEHAL KHAN
"/><br /><sub><b>MOHD NEHAL KHAN
</b></sub></a><br />🥳</td>
</tr>
</tbody>
Expand All @@ -128,7 +124,6 @@ We would love to have you, feel free to open issues and pull requests and **Don'
<a href="https://www.buymeacoffee.com/exifly" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/purple_img.png" alt="Buy Me A Coffee" style="height: 41px !important;width: 174px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;" ></a>

## License

ApiVault is licensed under the terms of **MIT License**. Check out [LICENSE](https://github.com/Exifly/ApiVault/blob/main/LICENSE) for details.

<br>
Expand Down
Binary file added assets/hero-apivaulot.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,683 changes: 1,683 additions & 0 deletions backend/README.md

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion backend/data/entries.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"count": 1426,
"entries": [
{
"API": "AdoptAPet",
Expand Down
1 change: 0 additions & 1 deletion backend/data/entries_custom.json

This file was deleted.

2 changes: 1 addition & 1 deletion backend/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ services:
aliases:
- apivault_network

command: bash -c "/bin/bash /code/docker/start.sh"
command: "python3 /code/docker/start_server.py"
ports:
- "5001:5001"

Expand Down
12 changes: 0 additions & 12 deletions backend/docker/start.sh

This file was deleted.

10 changes: 10 additions & 0 deletions backend/docker/start_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import subprocess

PS_CD="cd /code"
PS_START_SERVER="python start.py"
PS_START_SERVER_2="python3 start.py"

result_code = subprocess.call(PS_START_SERVER, shell=True)
if result_code != 0:
print(f"Command {PS_START_SERVER} failed to run.. Trying {PS_START_SERVER_2}")
subprocess.call(PS_START_SERVER_2, shell=True)
2 changes: 1 addition & 1 deletion backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Flask==2.2.3
Flask==2.2.5
Flask-Cors==3.0.10
81 changes: 52 additions & 29 deletions backend/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from flask import Flask, jsonify, request
from search import Search
import random as rnd
import collections
import datetime
import logging
import json
Expand All @@ -13,9 +14,11 @@
app.config['CORS_HEADERS'] = 'Content-Type'


filelog_name = 'apivault-{date:%Y%m%d}.txt'.format( date=datetime.datetime.now())
filelog_name = 'apivault-{date:%Y%m%d}.txt'.format(
date=datetime.datetime.now())
os.makedirs(os.path.dirname(f'log/{filelog_name}'), exist_ok=True)
logging.basicConfig(filename=f'log/{filelog_name}.log', filemode="w+" ,level=logging.INFO)
logging.basicConfig(
filename=f'log/{filelog_name}.log', filemode="w+", level=logging.INFO)


# Load the JSON data
Expand All @@ -30,50 +33,70 @@
@app.route('/api/search')
@cross_origin()
def search():
"""
1. Get the search query and category from the request arguments
2. Filter the data entries based on the search query and category
3. Return the filtered results as a JSON object
"""
query = request.args.get('q')
category = request.args.get('category')
results = Search.search_entries(data['entries'], query, category)
"""
1. Get the search query and category from the request arguments
2. Filter the data entries based on the search query and category
3. Return the filtered results as a JSON object
"""
query = request.args.get('q')
category = request.args.get('category')
results = Search.search_entries(data['entries'], query, category)

logging.info(f'Search query="{query}" category="{category}" results={len(results)}')
return jsonify(results)
logging.info(
f'Search query="{query}" category="{category}" results={len(results)}')
return jsonify(results)


@app.route('/api/random')
@cross_origin()
def random():
"""
1. Get the requested quantity from the request arguments
2. Convert the quantity to an integer if it exists, otherwise use the default value of 9
3. Generate random data entries and return them as a JSON object
"""
query = request.args.get('quantity')
quantity = int(query) if query != None else 9
entries = rnd.sample(data['entries'], min(quantity, len(data['entries'])))
"""
1. Get the requested quantity from the request arguments
2. Convert the quantity to an integer if it exists, otherwise use the default value of 9
3. Generate random data entries and return them as a JSON object
"""
query = request.args.get('quantity')
quantity = int(query) if query != None else 9
entries = rnd.sample(data['entries'], min(quantity, len(data['entries'])))

logging.info(f'Random request quantity={quantity} results={len(entries)}')
return jsonify(entries)
logging.info(f'Random request quantity={quantity} results={len(entries)}')
return jsonify(entries)


@app.route('/api/all')
@cross_origin()
def all():
"""Get all entries """
categorie = request.args.get('categorie')
if not categorie:
return data['entries']
return jsonify(Search.all_entries(data['entries'], categorie))
"""Get all entries """
categorie = request.args.get('categorie')
if not categorie:
return data['entries']
return jsonify(Search.all_entries(data['entries'], categorie))


@app.route('/api/count')
@cross_origin()
def count():
"""Get the count of entries"""
return jsonify(data['count'])
"""Get the count of entries"""
return jsonify(len(data.get('entries')))


@app.route('/api/categories/trending')
@cross_origin()
def trending_categories():
"""
Uses the 'Category' field from each entry to count
the number of occurrences of each category. Then, returns
the name and count of the top 10 categories, sorted in descending order
Returns:
A JSON response containing a list of the top 10 categories and their API counts.
"""
categories = collections.Counter(
entry['Category'] for entry in data['entries'])
top_categories = [{"category_name": category, "api_count": count}
for category, count in categories.most_common(10)]

return jsonify(top_categories)


if __name__ == '__main__':
Expand Down
23 changes: 23 additions & 0 deletions backend/utils/sitemap/generate_sitemap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from datetime import datetime
import xml.etree.ElementTree as ET

# legge gli URL dal file
with open('urls.txt', 'r') as f:
urls = f.read().splitlines()

# crea un nuovo oggetto ElementTree
urlset = ET.Element('urlset')
urlset.set('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9')

# per ogni URL, crea un nuovo elemento url e aggiungi loc e lastmod
for url in urls:
url_elem = ET.SubElement(urlset, 'url')
loc_elem = ET.SubElement(url_elem, 'loc')
loc_elem.text = url
lastmod_elem = ET.SubElement(url_elem, 'lastmod')
lastmod_elem.text = datetime.now().strftime('%Y-%m-%d')
priority_el = ET.SubElement(url_elem, 'priority')
priority_el.text = "0.2"

# crea il file sitemap.xml e scrive l'ElementTree al suo interno
ET.ElementTree(urlset).write('sitemap.xml', encoding='utf-8', xml_declaration=True)
Loading

0 comments on commit 731d1f1

Please sign in to comment.