Exemplo n.º 1
0
 def onStartup(self):
     """Initialize plugin settings """
     # try to load admin plugin
     self._adminPlugin = self.console.getPlugin("admin")
     if not self._adminPlugin:
         self.error("Could not find admin plugin")
         return False
     # register our command
     self._registerCommands()
     # get bf3stats API
     self._bf3stats = bf3stats.api(ident=self._bf3stats_ident, secret=self._bf3stats_secret)
Exemplo n.º 2
0
    def get(self):
        template_values = {}
        mysecrets = Secrets()
        stats_obj = bf3stats.api(plattform='ps3', secret=mysecrets.bf3StatsKey, ident=mysecrets.bf3StatsIdent)

        # If weapon info is empty, fill it
        template_values['weapons_added'] = 'Weapons not added to datastore.'
        if not models.Weapon.all(keys_only=True).get():

            # Pull the information on all the Kits
            # Data looks like:
            # {'status': 'data', 'stats': {'kits': {'recon':{'name':'Recon', 'unlocks': [{'name':'','id':'', desc':'',}]}}}}
            kit_data = stats_obj.player('botono9', parts='clear,imgInfo,kits,kitsName,kitsInfo,kitsUnlocks')

            for k in kit_data['stats']['kits'].iterkeys():
                kit_name = kit_data['stats']['kits'][k]['name']
                for item in kit_data['stats']['kits'][k]['unlocks']:
                    models.Weapon(
                        weapon_id = item['id'],
                        weapon_name = item['name'],
                        weapon_description = item['desc'],
                        weapon_kit = kit_name,
                        weapon_type = item['type'], #weapon or kititem
                        weapon_img = item['img']).put()
                # HACK IT!
            models.Weapon(
                weapon_id = 'pM9',
                weapon_name = 'M9',
                weapon_description = """Formally known as Pistol, Semiautomatic, 9mm, M9, the M9 was selected as the primary sidearm of the entire United States military in 1985. Developed in Italy, the M9 was selected in a series of often disputed trials, only narrowly beating out other contenders, because of its high quality and low price. The M9 is the primary sidearm of the USMC.""",
                weapon_kit = 'General',
                weapon_type = 'weapon', #weapon or kititem
                weapon_img = 'weapons/m9.png').put()
            template_values['weapons_added'] = 'Weapons datastore filled!'

        # Update user info from Google Doc
        template_values['players_added'] = 'Players not added to datastore.'
        if not models.Player.all(keys_only=True).get():
            # Last updated date is in weapons_data['list'][member_name]['stats']['date_update']
            weapons_data = stats_obj.playerlist(AOA_MEMBERS, parts='clean,weapons')
            if weapons_data['status'] == 'ok':
                failed_members = weapons_data.get('failed', {})
                counter = 0
                for member_name in weapons_data['list'].iterkeys():
                    models.Player(
                        player_name = member_name,
                        player_stats = cPickle.dumps(weapons_data['list'][member_name]['stats']['weapons']),
                        player_stats_updated = datetime.datetime.fromtimestamp(weapons_data['list'][member_name]['stats']['date_update']),
                        player_active = True).put()
            template_values['players_added'] = 'Players datastore filled!'
        template = jinja_environment.get_template('templates/init.html')
        self.response.out.write(template.render(template_values))