Init commit with preliminary func
This commit is contained in:
parent
523107e987
commit
a18fb8aa87
65
main.py
Normal file
65
main.py
Normal file
@ -0,0 +1,65 @@
|
||||
#
|
||||
# Pulling and pushing md files to/from bookstack
|
||||
#
|
||||
|
||||
import requests, json, os, creds
|
||||
|
||||
## Tweakables
|
||||
bookstackURL = "https://bs.corrgs.ca/api"
|
||||
keyToken = creds.keyToken
|
||||
secretToken = creds.secretToken
|
||||
|
||||
exportFolder = "export"
|
||||
importFolder = "import"
|
||||
|
||||
|
||||
## Advanced
|
||||
debug = True
|
||||
|
||||
headers = {}
|
||||
authHeader = { "Authorization" : f"Token {keyToken}:{secretToken}" }
|
||||
headers.update(authHeader)
|
||||
stars = "*"*25
|
||||
|
||||
|
||||
######
|
||||
# Book formats
|
||||
# Book > Chapter > Page
|
||||
######
|
||||
|
||||
def pullAllBooks():
|
||||
req = requests.get(f'{bookstackURL}/books', headers=headers)
|
||||
books = []
|
||||
for book in json.loads(req.content.decode())['data']:
|
||||
books.append(book)
|
||||
if debug:
|
||||
print(f"{stars}\nPulling books status code: {req.status_code}\n{stars}")
|
||||
print(books)
|
||||
return books
|
||||
|
||||
def pullAllChapters(bookID):
|
||||
req = requests.get(f'{bookstackURL}/books', headers=headers)
|
||||
chapters = []
|
||||
|
||||
def backupAllBooks(): ## This exports each book as a single page... it works but isn't a true backup solution
|
||||
jsonTests = []
|
||||
for book in pullAllBooks():
|
||||
req = requests.get(f"{bookstackURL}/books/{book['id']}/export/markdown", headers=headers)
|
||||
with open(f"{exportFolder}/{book['name']}", 'w+') as file:
|
||||
file.write(req.content.decode())
|
||||
|
||||
def importBooks(): ##### Incomplete
|
||||
importFiles = os.listdir(importFolder)
|
||||
for file in importFiles:
|
||||
with open(f'{importFolder}/{file}', 'r') as file:
|
||||
filedata = file.read()
|
||||
|
||||
if debug:
|
||||
## Pull all books
|
||||
pullAllBooks()
|
||||
|
||||
## Download allbooks
|
||||
backupAllBooks()
|
||||
|
||||
## Import test books
|
||||
importBooks()
|
||||
Loading…
Reference in New Issue
Block a user