logger
This commit is contained in:
parent
3f2f7475f2
commit
ab47043281
13
app.py
13
app.py
@ -1,8 +1,9 @@
|
|||||||
from flask import Flask, session, request, redirect, Response
|
from flask import Flask, session, request, redirect, Response
|
||||||
import os, requests, time
|
import os, requests, time
|
||||||
from hashlib import sha256
|
from hashlib import sha256
|
||||||
from supaclient import supaClient
|
from supaclient import supaClient, logger
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
from supabase import Client
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
URL = os.getenv("SUPABASE_IP") + "/"
|
URL = os.getenv("SUPABASE_IP") + "/"
|
||||||
@ -32,6 +33,9 @@ def proxy(path):
|
|||||||
headers = request.headers
|
headers = request.headers
|
||||||
json_ctx = request.get_json()
|
json_ctx = request.get_json()
|
||||||
|
|
||||||
|
# flags
|
||||||
|
logger_args = []
|
||||||
|
|
||||||
# process
|
# process
|
||||||
if path == "rest/v1/niming_posts": # niming post
|
if path == "rest/v1/niming_posts": # niming post
|
||||||
# hash
|
# hash
|
||||||
@ -40,6 +44,10 @@ def proxy(path):
|
|||||||
# ig posting
|
# ig posting
|
||||||
igid = None
|
igid = None
|
||||||
|
|
||||||
|
# set logger
|
||||||
|
logger_args.append("newpost")
|
||||||
|
logger_args.append(hash)
|
||||||
|
|
||||||
# edit payload
|
# edit payload
|
||||||
json_ctx["hash"] = hash
|
json_ctx["hash"] = hash
|
||||||
json_ctx["igid"] = igid
|
json_ctx["igid"] = igid
|
||||||
@ -50,6 +58,9 @@ def proxy(path):
|
|||||||
headers = [(name, value) for (name, value) in resp.raw.headers.items() if name.lower() not in excluded_headers]
|
headers = [(name, value) for (name, value) in resp.raw.headers.items() if name.lower() not in excluded_headers]
|
||||||
response = Response(resp.content, resp.status_code, headers)
|
response = Response(resp.content, resp.status_code, headers)
|
||||||
|
|
||||||
|
# logger
|
||||||
|
logger_res = logger(app.shared_resource.client, logger_args)
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
# run
|
# run
|
||||||
|
@ -4,10 +4,26 @@ import os
|
|||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
|
# service url
|
||||||
URL = os.getenv("SUPABASE_IP")
|
URL = os.getenv("SUPABASE_IP")
|
||||||
# service key
|
# service key
|
||||||
KEY = os.getenv("SUPABASE_KEY")
|
KEY = os.getenv("SUPABASE_KEY")
|
||||||
|
|
||||||
class supaClient:
|
class supaClient:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.client = create_client(URL, KEY)
|
self.client = create_client(URL, KEY)
|
||||||
|
|
||||||
|
# logger
|
||||||
|
def logger(dbclient: Client, args: list):
|
||||||
|
if args[0] == "newpost":
|
||||||
|
hash:str = args[1]
|
||||||
|
pres = dbclient.table("niming_posts").select("id, hash").eq("hash", hash).execute()
|
||||||
|
id = int(pres.data[0]["id"])
|
||||||
|
|
||||||
|
dbres = dbclient.table("niming_log").insert({
|
||||||
|
"message": "[id=%d] new post"%id,
|
||||||
|
"source": "client"
|
||||||
|
}).execute()
|
||||||
|
|
||||||
|
return dbres
|
||||||
|
return None
|
Loading…
Reference in New Issue
Block a user