Last active
December 12, 2021 17:14
-
-
Save NNBnh/4a8e30c39232706d915bfa208e2ad09e to your computer and use it in GitHub Desktop.
Script I use to convert artists bookmarks into ___booru artist's names (remember to customize this script to fit your bookmarks file).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json, requests | |
with open('bookmarks.json') as file: | |
bookmarks = json.load(file) | |
saved = [] | |
error = {} | |
for bookmark in bookmarks: | |
url = bookmark['uri'] | |
artists = json.loads(requests.get('https://danbooru.donmai.us/artists.json?search[url_matches]=' + url).content) | |
artist = [artist['name'] for artist in artists] | |
print(url + ': ', end='') | |
print(artist) | |
if len(artist) == 1: | |
saved += artist | |
else: | |
if artist: | |
error[url] = artist + [bookmark['title']] | |
else: | |
error[url] = bookmark['title'] | |
with open('artist.json', 'w') as saved_file: | |
saved_file.write(json.dumps(saved, indent=2)) | |
with open('error.json', 'w') as error_file: | |
error_file.write(json.dumps(error, indent=2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment