Import project
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
venv/
|
||||
assets/
|
||||
0
assets/import/bands/.gitkeep
Normal file
0
assets/import/bands/.gitkeep
Normal file
0
assets/import/characters/.gitkeep
Normal file
0
assets/import/characters/.gitkeep
Normal file
7
example_band.json
Normal file
7
example_band.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"id": "1",
|
||||
"name": "BAND-MAID",
|
||||
"description": "Band-Maid (stylized as BAND-MAID) is an all girl rock band from Tokyo that formed in July 2013. The band combines a rock sound with a maid image modeled on Japanese maid cafés.",
|
||||
"imageURL": "https://cdn.discordapp.com/attachments/851543504831119380/1009467684490063892/unknown.png",
|
||||
"enabled": 0
|
||||
}
|
||||
18
example_characters.json
Normal file
18
example_characters.json
Normal file
@@ -0,0 +1,18 @@
|
||||
[
|
||||
{
|
||||
"id": "1",
|
||||
"bandId": "1",
|
||||
"name": "Miku Kobato",
|
||||
"description": "Miku Kobato is a Japanese singer, songwriter and guitarist. She is the initial founding member and main lyricist for BAND-MAID.",
|
||||
"imageIdentifier": "bandmaid/miku.png",
|
||||
"enabled": 0
|
||||
},
|
||||
{
|
||||
"id": "2",
|
||||
"bandId": "1",
|
||||
"name": "Akane Hirose",
|
||||
"description": "Akane Hirose is a Japanese drummer and founding member of BAND-MAID.",
|
||||
"imageIdentifier": "bandmaid/akane.png",
|
||||
"enabled": 0
|
||||
}
|
||||
]
|
||||
67
main.py
Normal file
67
main.py
Normal file
@@ -0,0 +1,67 @@
|
||||
import discogs_client, json, re, urllib.request, os
|
||||
|
||||
client = discogs_client.Client('ExampleApplication/0.1', user_token="")
|
||||
|
||||
band_id =
|
||||
member_id =
|
||||
discogs_id = input("Enter Discogs ID: ")
|
||||
band = client.artist(discogs_id)
|
||||
|
||||
band_json = {}
|
||||
band_json['name'] = band.name
|
||||
band_json['id'] = band_id
|
||||
band_json['description'] = band.profile
|
||||
band_json['image'] = band.images[0]['uri']
|
||||
band_json['enabled'] = 0
|
||||
|
||||
members_json = []
|
||||
|
||||
def resolve_ref(match):
|
||||
print(f"Resolving {match.group()} => ", end="")
|
||||
ref = client.artist(int(match.group()[2:-1]))
|
||||
print(f"{ref.name}")
|
||||
return ref.name
|
||||
|
||||
def sanitize_path(path):
|
||||
return path.replace(" ", "_")
|
||||
|
||||
def image_closest_to_aspect(images):
|
||||
aspect = 0.6
|
||||
closest = None
|
||||
for image in images:
|
||||
if image['width'] / image['height'] > aspect and image['width'] < image['height']:
|
||||
if closest is None or image['width'] < closest['width']:
|
||||
closest = image
|
||||
return closest if closest is not None else images[0]
|
||||
|
||||
band_folder = sanitize_path(band.name)
|
||||
if not os.path.exists(f"assets/{band_folder}"):
|
||||
os.makedirs(f"assets/{band_folder}")
|
||||
|
||||
|
||||
for member in band.members:
|
||||
print(member.name)
|
||||
profile = str(member.profile)
|
||||
profile = re.sub(r'\[a[0-9|a-zA-Z]*\]', resolve_ref, profile)
|
||||
profile = re.sub(r'\[a=[0-9|a-zA-Z ]*\]', lambda match: match.group()[3:-1], profile)
|
||||
|
||||
print("Downloading image...")
|
||||
image_path = f"{band_folder}/{member.id}_{sanitize_path(member.name)}.jpeg"
|
||||
urllib.request.urlretrieve(image_closest_to_aspect(member.images)['uri'], f"assets/{image_path}")
|
||||
|
||||
member = {
|
||||
'id': member_id,
|
||||
'bandId': band_id,
|
||||
'name': member.name,
|
||||
'description': profile,
|
||||
'imageIdentifier': image_path,
|
||||
'enabled': 0
|
||||
}
|
||||
members_json.append(member)
|
||||
member_id += 1
|
||||
|
||||
with open(f"aseets/import/characters/{band_folder}_characters.json", "w") as characters_file:
|
||||
json.dump(members_json, characters_file, indent=4, sort_keys=False)
|
||||
|
||||
with open(f"assets/import/bands/{band_folder}.json", "w") as band_file:
|
||||
json.dump(band_json, band_file, indent=4, sort_keys=False)
|
||||
10
requirements.txt
Normal file
10
requirements.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
certifi==2022.6.15
|
||||
charset-normalizer==2.0.12
|
||||
idna==3.3
|
||||
oauthlib==3.2.0
|
||||
pkg-resources==0.0.0
|
||||
python-dateutil==2.8.2
|
||||
python3-discogs-client==2.3.15
|
||||
requests==2.27.1
|
||||
six==1.16.0
|
||||
urllib3==1.26.12
|
||||
Reference in New Issue
Block a user