Skip to content

Instantly share code, notes, and snippets.

@MojtabaMonfared
Created August 8, 2022 21:28
Show Gist options
  • Select an option

  • Save MojtabaMonfared/4576e68582863b2e2dd00cc3b0675f31 to your computer and use it in GitHub Desktop.

Select an option

Save MojtabaMonfared/4576e68582863b2e2dd00cc3b0675f31 to your computer and use it in GitHub Desktop.
automate making cards in a list for trello.com

first of all you need to install trello python library

pip install trello

then you need to have a text file including your book titles books.txt

save this script and put your API_KEY and TOKEN and LIST_ID

create a list and put .json in front of your url for example: https://trello.com/b/4GT6TNDDh/Tasks.json and look for list id in json file it should be look like this: 62f15c85XXXXXXXXX7a059ff

and i think you're good to go :)

from trello import TrelloApi
import requests
from bs4 import BeautifulSoup as bs

trello = TrelloApi('API_KEY', 'TOKEN')

def getHTMLdocument(url):
    # request for HTML document of given url
    response = requests.get(url)
    # response will be provided in JSON format
    return response.text

with open('books.txt', 'r') as books:
        name = books.readlines()
        for i in name:
            url = f'https://www.goodreads.com/search?q={i}&qid=NHH3SBkK2v'
            soup = bs(getHTMLdocument(url), 'html.parser')
            author = soup.select('.authorName span')[0].get_text()
            title = soup.select('.bookTitle span')[0].get_text()
            trello.lists.new_card('LIST_ID', due='2022-02-02', name=title, desc=f"Author: {author}")
            print(f"book {i} added!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment