Code Monkey home page Code Monkey logo

in2000-sql-api's Introduction

in2000-weather-sqlapi

This is a Python Flask application that serves activities and optimal weather conditions for them, from an SQL database, with caching and deployment to Azure Web App via GitHub Actions. The API is to be used for the weather app in IN2000

Features

  • Flask web application serving weather data
  • Caching using Flask-Caching
  • Deployment to Azure Web App using GitHub Actions
  • Simple API to fetch all activities or a specific activity
  • Example JSON response if cache is not available

Prerequisites

  • Python 3.10
  • Azure Web App for deployment
  • GitHub repository for CI/CD pipeline
  • Environment variables configured for database connection and API key

Setup

  1. Clone the repository:

    git clone https://github.com/your-username/in2000-weather-sqlapi.git
    cd in2000-weather-sqlapi
  2. Create a virtual environment and activate it:

    python -m venv venv
    source venv/bin/activate
  3. Install dependencies:

    pip install -r requirements.txt
  4. Create a .env file and set the required environment variables:

    api_key_update=your_api_key
    SQLAZURECONNSTR_SQL_activity=your_connection_string
  5. Run the application:

    python app.py

Endpoints

  • GET / - Renders the main page.
  • GET /api/activities - Fetches all activities.
  • GET /api/activities/<int:activity_id> - Fetches a specific activity by ID.
  • POST /db/updatecache - Updates the activities cache. Requires X-API-KEY header.

Deployment

This project uses GitHub Actions to build and deploy the application to Azure Web App.

GitHub Actions Workflow

The GitHub Actions workflow is defined in .github/workflows/main.yml. It includes two jobs:

  • build: Checks out the code, sets up Python, creates a virtual environment, installs dependencies, and uploads a zipped artifact for deployment.
  • deploy: Downloads the artifact, unzips it, and deploys the application to Azure Web App using the specified publish profile.

Deploying

The easiest way to deploy this project is by removing the GitHub actions workflow, creating an Azure Web App and link it up to this repository. This will automatically generate a GitHub actions file that will publish the API. You then setup the environment variables in the Azure Web App.

Triggering Deployment

The deployment workflow triggers on push to the master branch or can be manually triggered via the GitHub Actions UI.

in2000-sql-api's People

Contributors

gransmango avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.