Skip to content

Commit 6dc2212

Browse files
committed
Refactor and Removed Carbonara API
1 parent 7c436fd commit 6dc2212

File tree

5 files changed

+17
-164
lines changed

5 files changed

+17
-164
lines changed

lib/Carbonara.py

-138
This file was deleted.

lib/Kod.py

+1-18
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
"""
22
Description: This use API for Kod so which is a code snippet generator for developers.
3+
Because its easy to generate code snippet with this API, I decided to use it.
34
Server API : REST.
45
Website : https://kod.so/
56
"""
67

7-
88
import requests
99
from datetime import datetime
1010
import random
11-
import gridfs
1211

1312
class Kodso:
1413
def __init__(self, database):
@@ -98,22 +97,6 @@ def show_snippet(self, code: str, **kwargs):
9897
download_jpg_url = code_url + "&output=jpg&download=1"
9998
download_svg_url = code_url + "&output=svg&download=1"
10099
return code_url, download_png_url, download_jpg_url, download_svg_url
101-
102-
# Then download the image located in the generated URL and save it
103-
image_resp = requests.get(code_url)
104-
image_data = image_resp.content
105-
106-
# Get the GridFSBucket object from the database object with the bucket name 'Snippets'
107-
bucket = gridfs.GridFSBucket(self.database.db, bucket_name=self.bucket_name)
108-
109-
# Store the image file in mongodb using the bucket object
110-
file_id = bucket.upload_from_stream(filename, image_data)
111-
112-
if file_id:
113-
self.write_log("save_snippet: Image saved to database successfully.")
114-
# Return the download link for the image.
115-
download_link = f"{self.plugin_url}/download/{filename}"
116-
return download_link
117100

118101
except Exception as e:
119102
self.write_log(f"An error occurred while saving the code snippet to the database: {e}")

lib/quick_chart.py

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
"""
2+
Description: This use API for QuickChart so which is a chart generator for developers.
3+
This uses URL parameters to generate charts from the website.
4+
Support all kinds of charts (Bar, Pie, Line, Doughnut, Radar, Polar Area, Bubble, Scatter, Area, Mixed).
5+
Server API : REST.
6+
Website : "https://quickchart.io"
7+
"""
8+
19
import requests
210
import json
311
import random

openapi.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"openapi": "3.0.0",
2+
"openapi": "3.0.1",
33
"info": {
44
"title": "Code Runner",
55
"version": "1.2"

script.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
"""
22
Description: This is ChatGPT Plugin for CodeRunner. Which can run and save code in 70+ languages.
3-
This is a Quart Web Server which is used to run the code and return the output.
3+
And can genrate graphs and plots for data science and machine learning.
4+
This has also support for managing files and documents.
45
Server API : Quart.
56
Language: Python.
6-
Date: 06/07/2023.
7+
Date: 19/07/2023.
78
Author : HeavenHM
89
"""
910

1011
# importing the required libraries.
1112
from datetime import datetime, timezone
1213
from urllib.parse import quote
13-
from quart import Quart, make_response, request, jsonify, redirect, Response, url_for, send_file
14+
from quart import Quart,request, jsonify, redirect, Response, url_for
1415
import traceback
1516
import random
1617
import json
1718
import quart
1819
import requests
1920
import os
21+
import io
2022
import gridfs
2123
from pathlib import Path
2224
from lib.mongo_db import MongoDB
2325
from lib.python_runner import *
2426
from lib.jdoodle_api import *
2527
from quart_cors import cors
26-
import io
2728
from lib.quick_chart import QuickChartIO
28-
from lib.Carbonara import Carbonara
29-
from lib.Kod import Kodso
29+
from lib.kod import Kodso
3030

3131
# Webhook user agent by PluginLab.
3232
webhook_user_agent = "PluginLab-Webhook-Delivery"
@@ -56,12 +56,12 @@
5656
global quick_chart
5757
quick_chart = None
5858
carbonara = None
59+
kodso = None
5960

6061
try:
6162
# setting the database
6263
database = MongoDB()
6364
quick_chart = QuickChartIO(database)
64-
carbonara = Carbonara(database)
6565
kodso = Kodso(database)
6666
except Exception as e:
6767
print("Exception while connecting to the database : " + str(e))

0 commit comments

Comments
 (0)