Giter VIP home page Giter VIP logo

aben20807 / img-host-transfer Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 12 KB

A Python script for changing image hosting service to google drive from others (google photo, imgur, flickr, etc)

Home Page: https://aben20807.github.io/posts/20230415-image-host-transfer-program-with-chatgpt-v2/

License: MIT License

Python 100.00%
cli google-drive-api google-drive-api-python google-drive-api-v3 image-hosting markdown python3 website-tool image-hosting-transfer chatgpt

img-host-transfer's Introduction

Img Host Transfer

A Python script for changing image hosting service to google drive. It will download all images from markdown files and upload them to a specific google drive folder. After that, the shared links for newly uploaded images are used to replace old links in the original markdown files.

Prerequisites

  • Online setting in Google Cloud:
    • New a project and switch on Google Drive API.
    • In the Credentials tab, create a Service Account. In this step, you will download a JSON file and name it credentials.json, please keep it secret.
    • Add the email of the Service Account as an editor to your root folder for images to be backed up in google drive, i.e., share the Service Account the permission to modify (Note: the root folder is not your real root folder but the folder expected to store images)
    • In the same configuration page, open the folder permission to read for anybody to make everyone can access the image via the new links from your google drive
  • Local environment:
    • New a .env file, root_id="<ROOT_ID>", where <ROOT_ID> is the mentioned root folder ID you want to place generated folders for markdown files. You can access it in your google drive from the folder URL; for example, https://drive.google.com/drive/u/0/folders/XXXXXXXXXXXXXXXXXXXXXXX, the XXXXXXXXXXXXXXXXXXXXXXX is the folder ID

    • Open a terminal, clone this repo and cd in, then type:

      $ virtualenv -p python3.8 .venv
      $ source .venv/bin/activate
      $ pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib python-dotenv

Usage

Single file

$ python python/img_host_transfer.py credentials.json --md-file ../blog-post/content/posts/20220729-weekly-collection.md
$ python python/img_host_transfer.py credentials.json -f ../blog-post/content/posts/gallery-demo.md

Apply all markdown files in a directory

$ python python/img_host_transfer.py credentials.json -r ../blog-post/content/posts/

Backup Imgur images for HackMD

Note: no HackMD API

Recommended steps after the above prerequisites:

  1. Download all markdown files from the note setting HackMD_User_00000000000/ from the web GUI
  2. In the HackMD_User_00000000000/, use git init, git add ., and git commit -m "init" sequentially so that you can find which files are updated easily
  3. Use the following command to backup your Imgur images to your Google Drive, this command will replace the old Imgur URL with a new Google Drive URL after being uploaded
$ python python/img_host_transfer.py credentials.json --hackmd -r ../HackMD_User_00000000000/
  1. Depends on how much time you want to spend
    1. Upload the folder (HackMD_User_00000000000/) which contains the updated markdown files to your Google Drive folder which contains uploaded images (or a Github repo). When you find the image in HackMD is disappear, go to your Google Drive folder (or the Github repo) to find the image
    2. Replace the local updated markdown files to your HackMD account

Disclaimer

This tool works for me, but it might not work for you. Always make a backup first. I am not responsible for any loss or corruption of data.

License

MIT

img-host-transfer's People

Contributors

aben20807 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  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.