Question

Create a Flask application that integrates Flask-SQLAlchemy (with MySQL) to build a small web application.

Assignment Requirements:

  1. Database Setup (MySQL): o Create a database using MySQL. o Define the following models using Flask-SQLAlchemy: ▪ User: For managing users (name, email, social_login_provider, profile_picture, created_at). ▪ ScrapedData: For storing data scraped from a website (URL, content, metadata, created_by_user_id as a foreign key to User, and created_at). ▪ PromptLog: For storing prompts and their generated outputs (prompt_text, generated_output, created_by_user_id as a foreign key to User, and created_at).
  2. Application Setup: o Follow the below folder structure: config / config.py modules / web_application / api / … modules / web_application / forms / … modules / web_application / models / … modules / web_application / templates / … modules / web_application / views / … modules / web_application / tests / … static templates .env app.py other files as required
  3. Social Login Integration: o Implement social login using Google or Facebook OAuth (use Flask-Dance or any other library of your choice). o Upon login, save user details (name, email, profile picture, and provider) in the User table.
  4. LangChain Integration: o Integrate LangChain for prompt-based interactions. o Create an endpoint where users can send a prompt and receive a response. o Save both the prompt and the generated response in the PromptLog table with tokens used. o You may use GenAI to get the data from the scraped website.
  5. Web Scraping Feature: o Provide an interface where logged-in users can enter a URL (Social Media Profile, Website etc). o Scrape the content (Name, About, Source (Company, Social Media Account, Others), Industry, Page Content Type, Contact, Email etc) and metadata (e.g., title, description, etc.) of the provided URL. o Save the scraped data in the ScrapedData table, associating it with the logged-in user. o Ensure the scraper handles common issues like timeouts and invalid URLs or JS based websites that load content after load gracefully.
  6. Dashboard (Frontend): o Create a simple dashboard (using Bootstrap or any frontend library) with the following features: ▪ Display a list of the user’s scraped URLs with their content and metadata. ▪ Display a list of the user’s prompts and generated outputs. ▪ Allow users to delete or edit their scraped data and prompts.
  7. API Development: o Develop RESTful APIs for: ▪ Creating, reading, updating, and deleting scraped data. ▪ Creating and retrieving prompts and their generated responses.
  8. Additional Requirements: o Ensure the application is containerized using Docker. o Write unit tests for key functionalities (e.g., user login, prompt generation, web scraping). o Use environment variables to manage sensitive information (e.g., database credentials, API keys).

Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
November 20, 2024

Hey!

This is an interesting assignment! You can start by following the steps from this tutorial here:

https://www.digitalocean.com/community/tutorials/how-to-use-flask-sqlalchemy-to-interact-with-databases-in-a-flask-application

The tutorial will get you pretty far with your assignment. If you ever get stuck feel free to post specific questions here and the community will be happy to help.

For the database migrations, you could also take a look at this guide here.

The best way to learn is by doing and asking questions! Good luck with your project!

- Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.