lagrangedao / smart-contract

Lagrange DAO Computing Contracts
MIT License
4 stars 3 forks source link

add a flask support query nft via flask #21

Open flyworker opened 1 year ago

flyworker commented 1 year ago

sample query @datanft_bp.route('/nfs/', methods=['Get']) def get_datanft_detail(dataset_name): nft = Nft.query.filter_by(name=name).first()

flyworker commented 1 year ago

python scheduler servicwith flask

You can create a simple Python scheduler service using Flask, a popular web framework, combined with the Advanced Python Scheduler (APScheduler) library to handle scheduling tasks. Here's a basic example to get you started:

First, make sure you have Flask and APScheduler installed. You can install them using pip:
pip install Flask APScheduler
Create a file named app.py and add the following code:

from flask import Flask, jsonify
from apscheduler.schedulers.background import BackgroundScheduler
from datetime import datetime

app = Flask(__name__)

def scheduled_task():
    print(f"Scheduled task executed at {datetime.now()}")

scheduler = BackgroundScheduler()
scheduler.add_job(func=scheduled_task, trigger="interval", seconds=10)
scheduler.start()

@app.route('/')
def hello():
    return jsonify(message='Hello from Flask scheduler service!')

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)

In this example, we have a simple Flask application with a single route that returns a "Hello from Flask scheduler service!" message. We've also created a background scheduler using the APScheduler library and added a job that executes the scheduled_task function every 10 seconds.

Run the Flask application:

python app.py
Visit http://127.0.0.1:5000/ in your web browser to see the "Hello from Flask scheduler service!" message.

In your terminal or console, you should see the output of the scheduled_task function every 10 seconds, indicating that the task is running as scheduled.

Rishabh42 commented 1 year ago

Thanks for the info, just to clarify some things:

  1. The scanner will scan for new NFTs that were minted and add the details of those to the DB table and also scan for transfer events and update the owner's address if the NFT was transferred ? I was also working on making the scanner run continuously in the background

  2. The GET methos which queries the details of the NFT from the DB should be a part of the Flask script or the scanning script? Currently I've implemented this in the Flask script but can shift that code to the NFTscanner if that's what you want

Please confirm Thanks