Code Monkey home page Code Monkey logo

onedrive-update-detector's Introduction

OneDrive update detector

Monitors a OneDrive directory for uploads of new files.

Due to OneDrive API restrictions, this service will only monitor files under /me/drive/approot, which usually corresponds to /Apps/app_name in your personal OneDrive.

Also due to OneDrive API restrictions, this service will instead:

  1. Detect any folders where files with the configured file type(s) were created or updated
  2. Downloads the newest files from the folders detected above.

You can specify which files to check for in the configuration below. Note that the webhook which starts this process is only triggered upon new file creation or file deletion.

The service requires the file write permission to create the approot special directory.

This service only supports storing credentials for one user.

Virtual environment

This app uses Python's virtual environment feature. To enable:

$ source venv/bin/activate

Installation

Install dependencies.

$ pip3 install -r requirements.txt

Copy (and edit) custom script file. To see how the script is called, look at files.py

$ cp script.example.py script.py

For development, install ngrok from here.

Azure Active Directory app registration

This app needs to be registered on Azure Active Directory. In order to use personal accounts, select the option that allows all users to use the service.

Generate client secret

Generate a client secret from the certificates and secrets section. Copy this into the configuration as shown below.

Add permissions

Add a permission in Azure Active Directory from the API permissions section. This app requires the following delegated Microsoft Graph API permissions to be added to the app.

offline_acess
Files.Read
User.Read

Configuration

This app requires the following environment variables to be configured.

FLASK_APP = name of app
FILE_TYPES = file types to look for, comma separated - e.g. ".csv,.db"
DOWNLOAD_LOCATION = path to the folder where files are downloaded to.
MODE = debug, development, or production

The following are variables related to the Microsoft API. See the documentation for more details.

TENANT = "common", "organizations", or "consumers"
APPLICATION_ID = corresponds to client_id, obtained from Azure Active Directory
REDIRECT_URL = corresponds to redirect_uri, should be set to localhost:5000 for development with ngrok.
APPLICATION_URL = url of the app (no paths) - eg. "https://123.jp.ngrok.io"
NOTIFICATION_URL = url of the app for webhooks to be notified to
CLIENT_SECRET = client secret registered in the Azure Active Directory.

Development

$ ngrok http 5000
$ python3 index.py

Production

Set MODE environment variable to production. Make a tunnel using a service like Cloudflare Tunnel. Note that you should ONLY expose the /webhooks/notify endpoint to the public. Then run:

$ python3 index.py

In case this is not in a virtual environment, replace python3 with the path obtained from the command:

$ source venv/bin/activate
$ which python3

It may be sensible to create a systemd service for this. This application is not yet dockerized.

onedrive-update-detector's People

Contributors

natsuozawa avatar

Stargazers

Heath B avatar Yuto Takano 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.