Talk:Daybreak (achievements)

From Guild Wars 2 Wiki
Jump to: navigation, 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)
   #!/usr/bin/python
   
   import json
   import sys
   import urllib2
   
   reload(sys)
   sys.setdefaultencoding('utf-8')
   
   base_url = 'https://api.guildwars2.com/v2/'
   mastery_dict = {'Tyria': 'Central Tyria', 'Maguuma': 'Heart of Thorns', 'Desert': 'Crystal Desert'}
   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 = urllib2.Request(url, None)
       f = urllib2.urlopen(req, None, 60)
       x = json.load(f)
       f.close()
       return x
   
   cat = makeRequest('achievements/categories/' + str(cat_id))
   achievements = makeRequest('achievements', 'ids=' + ','.join(str(x) for x in cat['achievements']))
   item_ids = {r['id'] for a in achievements for r in a.get('rewards', []) if r['type'] == 'Item'}
   items = {item['id']: item['name'] for item in makeRequest('items', 'ids=' + ','.join(str(x) for x in item_ids))} if item_ids else dict()
   title_ids = {r['id'] for a in achievements for r in a.get('rewards', []) if r['type'] == 'Title'}
   titles = {title['id']: title['name'] for title in makeRequest('titles', 'ids=' + ','.join(str(x) for x in title_ids))} if title_ids else dict()
   
   for a in achievements:
       print '{{Achievement table row'
       print '| id = ' + str(a['id'])
       print '| name = ' + a['name']
       print '| description = ' + a['requirement']
       print '| flavor = ' + a['description']
       if 'CategoryDisplay' in a['flags']:
           print '| type = meta'
       elif 'Repeatable' in a['flags']:
           print '| type = repeatable'
       cap = a.get('point_cap')
       if cap:
           print '| cap = ' + str(cap)
       print '| tiers =',
       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)
       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)