Talk:Daybreak (achievements)
From Guild Wars 2 Wiki
Jump to navigationJump to search
Script for creating a first version of the achievements from the API[edit]
Here is a script that fills most of the achievement template. Text for tiers has to be added by hand because the API doesn't provide that. The script is called with the achievement category identifier (196 for Daybreak). The script is now updated to include rewards, too. --Andreasg.gw2 (talk) 01:53, 29 November 2017 (UTC)
- I updated the script to hopefully map all information from the API to the corresponding fields in the achievement template. This should make the script useful for all new achievement pages. Category IDs can be found here (Noxx's script from Talk:Achievement). Note that API categories may be incomplete, e.g., "Brandstone Research" missing, and in an order different from the meta achievement. --Andreasg.gw2 (talk) 18:14, 1 December 2017 (UTC)
- I updated the script again to alphabetically sort achievements and to put meta-achievements first. I also updated the script to Python 3. --Andreasg.gw2 (talk) 19:09, 14 January 2020 (UTC)
#!/usr/bin/python3 import json import sys import urllib.request, urllib.error, urllib.parse base_url = 'https://api.guildwars2.com/v2/' mastery_dict = {'Tyria': 'Central Tyria', 'Maguuma': 'Heart of Thorns', 'Desert': 'Crystal Desert', 'Unknown': 'Icebrood Saga'} cat_id = int(sys.argv[1]) def makeRequest(rel_url, query_string=None): url = base_url + rel_url if query_string is not None: url = url + '?' + query_string req = urllib.request.Request(url, None) f = urllib.request.urlopen(req, None, 60) x = json.load(f) f.close() return x cat = makeRequest('achievements/categories/' + str(cat_id)) qs = 'ids=' + ','.join(str(x) for x in cat['achievements']) achievements = sorted(makeRequest('achievements', qs), key=lambda a: a['name']) achiev_dict = {a['id']: a['name'] for a in achievements} item_ids = {r['id'] for a in achievements for r in a.get('rewards', []) + a.get('bits', []) if r['type'] == 'Item'} items = {} if item_ids: qs = 'ids=' + ','.join(str(x) for x in item_ids) items = {item['id']: item['name'] for item in makeRequest('items', qs)} skin_ids = {r['id'] for a in achievements for r in a.get('bits', []) if r['type'] == 'Skin'} skins = {} if skin_ids: qs = 'ids=' + ','.join(str(x) for x in skin_ids) skins = {skin['id']: skin['name'] for skin in makeRequest('skins', qs)} title_ids = {r['id'] for a in achievements for r in a.get('rewards', []) if r['type'] == 'Title'} titles = {} if title_ids: qs = 'ids=' + ','.join(str(x) for x in title_ids) titles = {title['id']: title['name'] for title in makeRequest('titles', qs)} print('{{Achievement table header') print('| id = ' + str(cat_id)) print('| icon = ') print('| title = ') print('| group = ') print('}}') for order in range(3): for a in achievements: if ('CategoryDisplay' in a['flags']) != (order == 0): continue if ('MoveToTop' in a['flags']) != (order == 1): continue print('{{Achievement table row') print('| id = ' + str(a['id'])) print('| name = ' + a['name']) print('| description = ' + a['requirement']) print('| flavor = ' + a['description'].replace('<c=@Flavor>', "").replace('</c>', "")) if 'CategoryDisplay' in a['flags']: print('| type = meta') elif 'Repeatable' in a['flags']: print('| type = repeatable') if 'Hidden' in a['flags']: print('| hidden = yes') cap = a.get('point_cap') if cap: print('| cap = ' + str(cap)) prereqs = [achiev_dict.get(p) for p in a.get('prerequisites', [])] for p in prereqs: if p: print('| prerequisite = ' + p) print('| tiers =', end=' ') for t in a['tiers']: print(str(t['count']) + ';' + str(t['points'])) mastery = next((mastery_dict[r['region']] for r in a.get('rewards', []) if r['type'] == 'Mastery'), None) if mastery: print('| mastery = ' + mastery) reward = next(((items.get(r['id']), r['count']) for r in a.get('rewards', []) if r['type'] == 'Item'), None) if reward and reward[0]: print('| reward = ' + reward[0]) if reward[1] > 1: print('| quantity = ' + str(reward[1])) title = next((titles.get(r['id']) for r in a.get('rewards', []) if r['type'] == 'Title'), None) if title: print('| title = ' + str(title)) objectives = [b['text'] for b in a.get('bits', []) if b['type'] == 'Text' and b['text']] if objectives: print('| objectives = ' + '\n'.join(objectives)) collection = [items[b['id']] if b['type'] == 'Item' else skins[b['id']] for b in a.get('bits', []) if b['type'] in ['Item', 'Skin']] if collection: print('| collection = ' + '\n'.join(collection)) print('}}') print('|}')
Feedback 2018/09/04[edit]
Is the icon for the wiki achievement category supposed to match the in-game icon? --Hitakashi (talk) 02:19, 5 September 2018 (UTC)
- Yep, and thanks to this comment, another user updated it, so thanks! —Ventriloquist 15:30, 5 September 2018 (UTC)