Skip to content

Commit 9c5f284

Browse files
committed
supabase content removed
1 parent ad44c4e commit 9c5f284

3 files changed

Lines changed: 0 additions & 157 deletions

File tree

app.py

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from flask import Flask, jsonify,request,url_for
2-
from db import SupabaseInterface
32
from collections import defaultdict
43
from flasgger import Swagger
54
import re,os,traceback
@@ -54,61 +53,6 @@ def greeting():
5453

5554

5655

57-
58-
@app.route('/get-data', methods=['GET'])
59-
@cross_origin(supports_credentials=True)
60-
@require_secret_key
61-
def get_data():
62-
"""
63-
Fetch data from Supabase.
64-
---
65-
responses:
66-
200:
67-
description: Data fetched successfully
68-
schema:
69-
type: array
70-
items:
71-
type: object
72-
500:
73-
description: Error fetching data
74-
schema:
75-
type: object
76-
properties:
77-
error:
78-
type: string
79-
"""
80-
try:
81-
response = SupabaseInterface().get_instance().client.table('dmp_pr_updates').select('*').execute()
82-
data = response.data
83-
return jsonify(data)
84-
except Exception as e:
85-
return jsonify({'error': str(e)}), 200
86-
87-
88-
89-
@app.route('/v1/issues', methods=['GET'])
90-
@require_secret_key
91-
def v1get_issues():
92-
try:
93-
response = SupabaseInterface().get_instance().client.table('dmp_issue_updates').select('*').execute()
94-
data = response.data
95-
96-
#group data based on issues
97-
grouped_data = defaultdict(list)
98-
for record in data:
99-
issue_url = record['issue_url']
100-
grouped_data[issue_url].append({
101-
'id': record['id'],
102-
'name': record['body_text']
103-
})
104-
105-
result = [{'issue_url': issue_url, 'issues': issues} for issue_url, issues in grouped_data.items()]
106-
grouped_data = group_by_owner(result)
107-
return jsonify(grouped_data)
108-
109-
except Exception as e:
110-
error_traceback = traceback.format_exc()
111-
return jsonify({'error': str(e), 'traceback': error_traceback}), 200
11256

11357

11458
@app.route('/issues', methods=['GET'])

db.py

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +0,0 @@
1-
import os, sys
2-
from typing import Any
3-
from supabase import create_client, Client
4-
from supabase.lib.client_options import ClientOptions
5-
from abc import ABC, abstractmethod
6-
import psycopg2,json
7-
from psycopg2.extras import RealDictCursor
8-
from dotenv import load_dotenv
9-
10-
11-
load_dotenv()
12-
13-
client_options = ClientOptions(postgrest_client_timeout=None)
14-
15-
16-
17-
class SupabaseInterface():
18-
19-
_instance = None
20-
21-
def __init__(self):
22-
if not SupabaseInterface._instance:
23-
24-
# Load environment variables
25-
26-
SUPABASE_URL = os.getenv('SUPABASE_URL')
27-
SUPABASE_KEY = os.getenv('SUPABASE_KEY')
28-
self.client: Client = create_client(SUPABASE_URL, SUPABASE_KEY)
29-
SupabaseInterface._instance = self
30-
else:
31-
SupabaseInterface._instance = self._instance
32-
33-
34-
35-
@staticmethod
36-
def get_instance():
37-
# Static method to retrieve the singleton instance
38-
if not SupabaseInterface._instance:
39-
# If no instance exists, create a new one
40-
SupabaseInterface._instance = SupabaseInterface()
41-
return SupabaseInterface._instance
42-
43-
44-
def get_postgres_connection():
45-
46-
# Database configuration
47-
DB_HOST =os.getenv('POSTGRES_DB_HOST')
48-
DB_NAME =os.getenv('POSTGRES_DB_NAME')
49-
DB_USER =os.getenv('POSTGRES_DB_USER')
50-
DB_PASS =os.getenv('POSTGRES_DB_PASS')
51-
conn = psycopg2.connect(
52-
host=DB_HOST,
53-
database=DB_NAME,
54-
user=DB_USER,
55-
password=DB_PASS
56-
)
57-
return conn
58-
59-
60-
61-
def postgres_query(query,params=None):
62-
conn = SupabaseInterface.get_postgres_connection()
63-
64-
cursor = conn.cursor(cursor_factory=RealDictCursor)
65-
66-
# cursor = conn.cursor()
67-
if not params:
68-
cursor.execute(query)
69-
else:
70-
cursor.execute(query,params)
71-
72-
rows = cursor.fetchall()
73-
results_as_dicts = [dict(row) for row in rows]
74-
75-
cursor.close()
76-
conn.close()
77-
return results_as_dicts
78-
79-
def readAll(self, table):
80-
data = self.client.table(f"{table}").select("*").execute()
81-
return data.data
82-
83-
def add_data(self, data,table_name):
84-
data = self.client.table(table_name).insert(data).execute()
85-
return data.data
86-
87-
def add_data_filter(self, data, table_name):
88-
# Construct the filter based on the provided column names and values
89-
filter_data = {column: data[column] for column in ['dmp_id','issue_number','owner']}
90-
91-
# Check if the data already exists in the table based on the filter
92-
existing_data = self.client.table(table_name).select("*").eq('dmp_id',data['dmp_id']).execute()
93-
94-
# If the data already exists, return without creating a new record
95-
if existing_data.data:
96-
return "Data already exists"
97-
98-
# If the data doesn't exist, insert it into the table
99-
new_data = self.client.table(table_name).insert(data).execute()
100-
return new_data.data

query.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from db import SupabaseInterface
21
from models import *
32
from sqlalchemy import func
43
import os

0 commit comments

Comments
 (0)