Talk:The Sun Is Silent for This One
From Guild Wars 2 Wiki
Jump to navigationJump to search
Script for creating a first version of the achievements from the API[edit]
This is a simple script for creating a first version of a collection page from the API. The script takes the achievement ID and the collection rarity as parameters. --Andreasg.gw2 (talk) 21:57, 1 December 2017 (UTC)
#!/usr/bin/python from collections import defaultdict import json import sys import urllib2 reload(sys) sys.setdefaultencoding('utf-8') base_url = 'https://api.guildwars2.com/v2/' type_urls = {'Item': 'items', 'Skin': 'skins', 'Minipet': 'minis'} ach_id = int(sys.argv[1]) rarity = sys.argv[2] if len(sys.argv) > 2 else 'Basic' 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 achievement = makeRequest('achievements/' + str(ach_id)) id_sets = defaultdict(set) bits = achievement.get('bits', []) for b in bits: try: id_sets[b['type']].add(b['id']) except KeyError: pass name_dict = {} for (key, value) in id_sets.iteritems(): name_dict.update({x['id']: x['name'] for x in makeRequest(type_urls[key], 'ids=' + ','.join(str(y) for y in value))}) print '[[' + achievement['name'] + ']] is a ' + ('hidden ' if 'Hidden' in achievement['flags'] else "") + '[' + '[' + rarity + ' Collections]] [' + '[achievement]].' print "" print '== Achievement ==' print '{' + '{achievement}}' print "" print '=== Collection items ===' for b in bits: try: name = name_dict[b['id']] print '* {' + '{item icon|' + name + '}}' except KeyError: pass print "" print '[' + '[Category:' + rarity + ' Collections]]'