Skip to content

Commit

Permalink
Add AscensionHistoryRequest.
Browse files Browse the repository at this point in the history
Thanks to Nathan Shayefar for this code.
  • Loading branch information
scelis committed Apr 28, 2010
1 parent 51693ee commit cdf5757
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/kol/data/Patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,8 @@
"effectRemoved" : r"<td>Effect removed\.<\/td>",
"youDontHaveThatEffect" : r"<td>You don't have that effect\.",
"youDontHaveSGEEA" : r"<td>You don't have a green soft eyedrop echo antidote\.",

# Ascension History patterns.
"fullAscension" : r'</tr><td[^>]*>([0-9]+).*?</td><td[^>]*>([0-9/]+).*?</td><td[^>]*><span[^>]*>([0-9,]+).*?</span>.*?</td><td[^>]*><img [^>]*title="(.*?)"[^>]*></td><td[^>]*>(.*?)</td><td[^>]*><span[^>]*>([0-9,]+)</span></td><td[^>]*><span[^>]*>([0-9,]+)</span></td><td[^>]*><img [^>]*title="(.*?)"[^>]*></td><td[^>]*>(<img [^>]*title="(.*?)"[^>]*>|<img src="http://images.kingdomofloathing.com/otherimages/spacer.gif" width=30 height=30>)(<img [^>]*title="(.*?)"[^>]*>|</td>)',
"familiarAscension" : r'(.*?) \(([0-9.]+)%\) -',
}
74 changes: 74 additions & 0 deletions src/kol/request/AscensionHistoryRequest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
from GenericRequest import GenericRequest
from kol.manager import PatternManager
from datetime import timedelta, datetime

class AscensionHistoryRequest(GenericRequest):
def __init__(self, session, playerId, preNS13=False):
super(AscensionHistoryRequest, self).__init__(session)
self.url = session.serverURL + "ascensionhistory.php?back=other&who=%s" % playerId
if preNS13:
self.url += "&prens13=1"

def parseResponse(self):
"""
Parses through the response and constructs an array of ascensions.
Each ascension is represented as a dictionary with the following
keys:
id -- The ascension #.
start -- The start date of the ascension (as datetime).
end -- The end date of the ascension (as datetime).
level -- The level at which the user ascended.
class -- The class of the user during the ascension
sign -- The sign of the user during the ascension
turns -- The number of turns the ascension lasted
days -- The number of days the ascension lasted
familiar -- The most used familiar this ascension
famUsage -- The use percentage of the most used familiar
type -- The type of ascension (normal, hardcore, casual, BM)
path -- The path of the ascension (teet, booze, oxy)
"""

fullAscensionPattern = PatternManager.getOrCompilePattern('fullAscension')
famPattern = PatternManager.getOrCompilePattern('familiarAscension')

ascensions = []

stripText = self.responseText.replace("&nbsp;", "")
for ascension in fullAscensionPattern.finditer(stripText):
ascNumber = ascension.group(1)
ascDate = ascension.group(2)
ascLevel = int(ascension.group(3))
ascClass = ascension.group(4).strip()
ascSign = ascension.group(5).strip()
ascTurns = int(ascension.group(6).replace(',',''))
ascDays = int(ascension.group(7).replace(',',''))
ascFamiliarData = ascension.group(8)
ascType = ascension.group(10)
ascPath = ascension.group(12)

try:
ascEnd = datetime.strptime(ascDate, "%m/%d/%y")
except ValueError:
ascEnd = dateStr

runlength = timedelta(ascDays - 1)
ascStart = ascEnd - runlength

if ascFamiliarData == "No Data":
ascFamiliar = "None"
ascFamUsage = 0
else:
for match in famPattern.finditer(ascFamiliarData):
ascFamiliar = match.group(1).strip()
ascFamUsage = match.group(2)

if ascType == "Hardcore" and ascPath == "Bad Moon":
ascType = "Bad Moon"
ascPath = "None"

asc = {"id":ascNumber, "start":ascStart, "end":ascEnd, "level":ascLevel, "class":ascClass, "sign":ascSign, "turns":ascTurns, "days":ascDays, "familiar":ascFamiliar, "famUsage":ascFamUsage, "type":ascType, "path":ascPath}

ascensions.append(asc)

self.responseData["ascensions"] = ascensions

0 comments on commit cdf5757

Please sign in to comment.