ERepublik: Somehow fix plugin to work with the new ERepublik API. Closes GH-123.

master
Valentin Lorentz 2013-05-22 15:57:18 +02:00
parent fe8fac7a7c
commit 66081032f3
2 changed files with 13 additions and 8 deletions

View File

@ -9,19 +9,22 @@ from math import ceil
import types
class Citizen:
def loadByName(self, name):
try:
self.doc = libxml2.parseFile('http://api.erepublik.com/v2/feeds/citizen_by_name/xml/' +
name)
except:
if name.isdigit():
return self.loadById(name)
import supybot.utils.web as web
lines = filter(lambda x:'<id>' in x, web.getUrl('http://api.erpk.org/citizen/search/' + name + '/1.xml?key=nIKh0F7U').split('\n'))
if not lines:
return None
self.ctxt = self.doc.xpathNewContext()
return self
line = lines[0]
id = line.split('>')[1].split('<')[0]
return self.loadById(id)
def loadById(self, id):
try:
self.doc = libxml2.parseFile('http://api.erepublik.com/v2/feeds/citizens/' + str(id))
self.doc = libxml2.parseFile('http://api.erpk.org/citizen/profile/' + str(id) + '.xml?key=nIKh0F7U')
except:
return None
self.ctxt = self.doc.xpathNewContext()
@ -258,7 +261,7 @@ class Citizen:
return (
' \x02 ' + self.getName() + ': Location: \x02' +
self.getCountry() + ', ' + self.getRegion() +
';\x02 Wellness: \x02' + str(self.getWellness()) + ';\x02 Rank: \x02' + str(self.getRank()) + ' ( ' + str(self.getRanklvl()) + ' ) ' +
';\x02 Wellness: \x02' + str(self.getWellness()) + ';\x02 Rank: \x02' + str(self.getRank()) +
';\x02 Experience: \x02' + str(self.getExperience()) +
';\x02 Employed at: \x02' + self.getEmployer() +
';\x02 Citizenship: \x02' + self.getCitizenship() + ';\x02 Work Skill: \x02' + str(self.getVestinu()) +

View File

@ -33,6 +33,8 @@ from supybot.commands import *
import supybot.plugins as plugins
import supybot.ircutils as ircutils
import supybot.callbacks as callbacks
import local.lib as lib
reload(lib)
from local.lib import Citizen, Stats, Vojnik, Ekonomija
try:
from supybot.i18n import PluginInternationalization