def getOutputHTML(cursor, userID): output = ' <ul class="alert">' row = cursor.fetchone() while row != None: if row[4] == "/user.py?uid={0}".format(userID): # Ability Unlocks link to user profile and stand out output = output + '<li id="alert_' + str( row[0] ) + '"><div class="tableHead"><a href="' + row[ 4] + '"><div class="inlineBlock" style="width:90%;">' + ghShared.timeAgo( row[2] ) + ' ago - ' + row[ 3] + '</div></a><div class="inlineBlock" style="vertical-align:top;min-width:20px;"><img src="/images/xRed16.png" style="cursor:pointer;" title="Click to remove this alert" alt="Red X" onclick="updateAlertStatus(' + str( row[0]) + ', 2)" /></div></div></li>' else: output = output + '<li id="alert_' + str( row[0] ) + '"><div><a href="' + row[ 4] + '"><div class="inlineBlock" style="width:90%;">' + ghShared.timeAgo( row[2] ) + ' ago - ' + row[ 3] + '</div></a><div class="inlineBlock" style="vertical-align:top;min-width:20px;"><img src="/images/xRed16.png" style="cursor:pointer;" title="Click to remove this alert" alt="Red X" onclick="updateAlertStatus(' + str( row[0]) + ', 2)" /></div></div></li>' row = cursor.fetchone() if output.find("<li") > -1: output = output + "</ul>" else: output = "No Alerts" return output
def getAlertsRow(self): result = '' statVals = "" titleStr = "" result += '<tr id="cont_' + self.spawnName + '" name="cont_' + self.spawnName + '" class="statRow">' # resource title row result += ' <td style="width:90px;"><span style="font-size: 12px;font-weight: bold;"><a href="' + ghShared.BASE_SCRIPT_URL + 'resource.py/' + str( self.spawnGalaxy ) + '/' + self.spawnName + '" class="nameLink">' + self.spawnName + '</a></td>' result += ' <td style="width:160px">entered ' + ghShared.timeAgo( self.entered) + ' ago</td>' # resource despawn alert if self.despawnAlert == 2: despawnStyle = "background-image:url(/images/email16.png);background-repeat:no-repeat;background-position:0px 0px;" despawnTitle = "e-mail" elif self.despawnAlert == 1: despawnStyle = "background-image:url(/images/browser16.png);background-repeat:no-repeat;background-position:0px 0px;" despawnTitle = "home page" elif self.despawnAlert == 4: despawnStyle = "background-image:url(/images/mobile16.png);background-repeat:no-repeat;background-position:0px 0px;" despawnTitle = "mobile" else: despawnStyle = "background-image:url(/images/none16.png);background-repeat:no-repeat;background-position:0px 0px;" despawnTitle = "none" result += "<td style='width:16px;{0}' tag='{1}' onclick='toggleAlertType(this, \"{2}\", 1);' title='{3}'></td>".format( despawnStyle, self.despawnAlert, self.spawnID, despawnTitle) result += "</tr>" return result
tType = doc.createTextNode(str(row[6])) eType.appendChild(tType) eWaypoint.appendChild(eType) eTitle = doc.createElement("title") tTitle = doc.createTextNode(row[7]) eTitle.appendChild(tTitle) eWaypoint.appendChild(eTitle) ePlanet = doc.createElement("planet") tPlanet = doc.createTextNode(row[10]) ePlanet.appendChild(tPlanet) eWaypoint.appendChild(ePlanet) eAdded = doc.createElement("added") tAdded = doc.createTextNode(ghShared.timeAgo(row[11])) eAdded.appendChild(tAdded) eWaypoint.appendChild(eAdded) eAddedTime = doc.createElement("addedTime") tAddedTime = doc.createTextNode(str(row[11])) eAddedTime.appendChild(tAddedTime) eWaypoint.appendChild(eAddedTime) eResTypeID = doc.createElement("resTypeID") tResTypeID = doc.createTextNode(str(row[12])) eResTypeID.appendChild(tResTypeID) eWaypoint.appendChild(eResTypeID) eResType = doc.createElement("resType") tResType = doc.createTextNode(str(row[13]))
def getMobileHTML(self, loggedIn, reputation): result = '' statHeads = "" statVals = "" titleStr = "" # prepare stat value table contents if (self.stats.ER != None and self.percentStats.ER != None): statVals = statVals + "<span class='" + ghShared.percOfRangeColor( self.percentStats.ER) + "'> ER: " + str( self.stats.ER) + "(" + ( "%.0f" % float(self.percentStats.ER)) + "%)</span>" if (self.stats.CR != None and self.percentStats.CR != None): statVals = statVals + "<span class='" + ghShared.percOfRangeColor( self.percentStats.CR) + "'> CR: " + str( self.stats.CR) + "(" + ( "%.0f" % float(self.percentStats.CR)) + "%)</span>" if (self.stats.CD != None and self.percentStats.CD != None): statVals = statVals + "<span class='" + ghShared.percOfRangeColor( self.percentStats.CD) + "'> CD: " + str( self.stats.CD) + "(" + ( "%.0f" % float(self.percentStats.CD)) + "%)</span>" if (self.stats.DR != None and self.percentStats.DR != None): statVals = statVals + "<span class='" + ghShared.percOfRangeColor( self.percentStats.DR) + "'> DR: " + str( self.stats.DR) + "(" + ( "%.0f" % float(self.percentStats.DR)) + "%)</span>" if (self.stats.FL != None and self.percentStats.FL != None): statVals = statVals + "<span class='" + ghShared.percOfRangeColor( self.percentStats.FL) + "'> FL: " + str( self.stats.FL) + "(" + ( "%.0f" % float(self.percentStats.FL)) + "%)</span>" if (self.stats.HR != None and self.percentStats.HR != None): statVals = statVals + "<span class='" + ghShared.percOfRangeColor( self.percentStats.HR) + "'> HR: " + str( self.stats.HR) + "(" + ( "%.0f" % float(self.percentStats.HR)) + "%)</span>" if (self.stats.MA != None and self.percentStats.MA != None): statVals = statVals + "<span class='" + ghShared.percOfRangeColor( self.percentStats.MA) + "'> MA: " + str( self.stats.MA) + "(" + ( "%.0f" % float(self.percentStats.MA)) + "%)</span>" if (self.stats.PE != None and self.percentStats.PE != None): statVals = statVals + "<span class='" + ghShared.percOfRangeColor( self.percentStats.PE) + "'> PE: " + str( self.stats.PE) + "(" + ( "%.0f" % float(self.percentStats.PE)) + "%)</span>" if (self.stats.OQ != None and self.percentStats.OQ != None): statVals = statVals + "<span class='" + ghShared.percOfRangeColor( self.percentStats.OQ) + "'> OQ: " + str( self.stats.OQ) + "(" + ( "%.0f" % float(self.percentStats.OQ)) + "%)</span>" if (self.stats.SR != None and self.percentStats.SR != None): statVals = statVals + "<span class='" + ghShared.percOfRangeColor( self.percentStats.SR) + "'> SR: " + str( self.stats.SR) + "(" + ( "%.0f" % float(self.percentStats.SR)) + "%)</span>" if (self.stats.UT != None and self.percentStats.UT != None): statVals = statVals + "<span class='" + ghShared.percOfRangeColor( self.percentStats.UT) + "'> UT: " + str( self.stats.UT) + "(" + ( "%.0f" % float(self.percentStats.UT)) + "%)</span>" # construct resource container if self.overallScore != None and self.overallScore > 0: titleStr = ' title="' + str("%.0f" % (float(self.overallScore))) + '"' result += ' <a href="' + ghShared.BASE_SCRIPT_URL + 'resource.py/' + str( self.spawnGalaxy) + '/' + self.spawnName + '" class="nameLink">' result += ' <div id="cont_' + self.spawnName + '" class="control"' + titleStr + ' style="text-align:left;">' # resource title row result += ' <div style="margin-bottom:4px;">' result += ' ' + self.resourceTypeName + ' (' + self.spawnName + ')' # non-stat info result += ' entered ' + ghShared.timeAgo( self.entered) + ' ago by ' + self.enteredBy if (loggedIn and reputation >= ghShared.MIN_REP_VALS['REMOVE_RESOURCE']): result += ' <span title="Mark Unavailable" style="cursor: pointer;float:right;" onclick="markUnavailable(this, \'' + self.spawnName + '\', ' + str( self.spawnGalaxy) + ',\'all\');"> [X]</span>' result += ' </div>' # stats information result += ' <div>' result += statVals result += ' </div></div></a>' return result
if (alertTypes == ""): errstr = errstr + "Error: no alert types given. \r\n" print 'Content-type: text/html\n' # Only process if no errors if (errstr == ""): if (logged_state > 0): result = ' <ul class="alert">' conn = dbShared.ghConn() # open list of users existing filters cursor = conn.cursor() cursor.execute("SELECT alertID, alertType, alertTime, alertMessage, alertLink FROM tAlerts WHERE userID='" + currentUser + "' AND alertType IN (" + alertTypes + ") AND alertStatus < 2 ORDER BY alertTime DESC LIMIT 10;") row = cursor.fetchone() while row != None: result = result + '<li id="alert_' + str(row[0]) + '"><div><a href="' + row[4] + '"><div class="inlineBlock" style="width:90%;">' + ghShared.timeAgo(row[2]) + ' ago - ' + row[3] + '</div></a><div class="inlineBlock" style="min-width:20px;"><img src="/images/xRed16.png" style="cursor:pointer;" title="Click to remove this alert" alt="Red X" onclick="updateAlertStatus(' + str(row[0]) + ', 2)" /></div></div></li>' row = cursor.fetchone() cursor.close() conn.close() if result.find("<li") > -1: result = result + "</ul>" else: result = "No Alerts" else: result = "Error: must be logged in to get alerts" else: result = errstr print result
def getHTML(self, formatStyle, resBoxMargin, loggedIn, reputation): result = '' unPlanetStr = ",'all'" statHeads = "" statVals = "" titleStr = "" # style 0 is wide format if formatStyle == 0: resBoxStyle = "margin-left:" + resBoxMargin + ";min-width:500px;" # style 2 is survey tool format elif formatStyle == 2: resBoxStyle = "padding-left:" + resBoxMargin + ";" else: # other is compact style resBoxStyle = "" # prepare stat value table contents if (self.percentStats.ER != None or formatStyle == 0): statHeads = statHeads + "<td class='header'><span>ER</span></td>" if (self.stats.ER != None and self.percentStats.ER != None): statVals = statVals + "<td class='" + ghShared.percOfRangeColor( self.percentStats.ER) + "'><span>" + str( self.stats.ER) + "<br />(" + ("%.0f" % float( self.percentStats.ER)) + "%)</span></td>" elif (self.percentStats.ER != None): statVals = statVals + "<td>?</td>" else: statVals = statVals + "<td></td>" if (self.percentStats.CR != None or formatStyle == 0): statHeads = statHeads + "<td class='header'><span>CR</span></td>" if (self.stats.CR != None and self.percentStats.CR != None): statVals = statVals + "<td class='" + ghShared.percOfRangeColor( self.percentStats.CR) + "'><span>" + str( self.stats.CR) + "<br />(" + ("%.0f" % float( self.percentStats.CR)) + "%)</span></td>" elif (self.percentStats.CR != None): statVals = statVals + "<td>?</td>" else: statVals = statVals + "<td></td>" if (self.percentStats.CD != None or formatStyle == 0): statHeads = statHeads + "<td class='header'><span>CD</span></td>" if (self.stats.CD != None and self.percentStats.CD != None): statVals = statVals + "<td class='" + ghShared.percOfRangeColor( self.percentStats.CD) + "'><span>" + str( self.stats.CD) + "<br />(" + ("%.0f" % float( self.percentStats.CD)) + "%)</span></td>" elif (self.percentStats.CD != None): statVals = statVals + "<td>?</td>" else: statVals = statVals + "<td></td>" if (self.percentStats.DR != None or formatStyle == 0): statHeads = statHeads + "<td class='header'><span>DR</span></td>" if (self.stats.DR != None and self.percentStats.DR != None): statVals = statVals + "<td class='" + ghShared.percOfRangeColor( self.percentStats.DR) + "'><span>" + str( self.stats.DR) + "<br />(" + ("%.0f" % float( self.percentStats.DR)) + "%)</span></td>" elif (self.percentStats.DR != None): statVals = statVals + "<td>?</td>" else: statVals = statVals + "<td></td>" if (self.percentStats.FL != None or formatStyle == 0): statHeads = statHeads + "<td class='header'><span>FL</span></td>" if (self.stats.FL != None and self.percentStats.FL != None): statVals = statVals + "<td class='" + ghShared.percOfRangeColor( self.percentStats.FL) + "'><span>" + str( self.stats.FL) + "<br />(" + ("%.0f" % float( self.percentStats.FL)) + "%)</span></td>" elif (self.percentStats.FL != None): statVals = statVals + "<td>?</td>" else: statVals = statVals + "<td></td>" if (self.percentStats.HR != None or formatStyle == 0): statHeads = statHeads + "<td class='header'><span>HR</span></td>" if (self.stats.HR != None and self.percentStats.HR != None): statVals = statVals + "<td class='" + ghShared.percOfRangeColor( self.percentStats.HR) + "'><span>" + str( self.stats.HR) + "<br />(" + ("%.0f" % float( self.percentStats.HR)) + "%)</span></td>" elif (self.percentStats.HR != None): statVals = statVals + "<td>?</td>" else: statVals = statVals + "<td></td>" if (self.percentStats.MA != None or formatStyle == 0): statHeads = statHeads + "<td class='header'><span>MA</span></td>" if (self.stats.MA != None and self.percentStats.MA != None): statVals = statVals + "<td class='" + ghShared.percOfRangeColor( self.percentStats.MA) + "'><span>" + str( self.stats.MA) + "<br />(" + ("%.0f" % float( self.percentStats.MA)) + "%)</span></td>" elif (self.percentStats.MA != None): statVals = statVals + "<td>?</td>" else: statVals = statVals + "<td></td>" if (self.percentStats.PE != None or formatStyle == 0): statHeads = statHeads + "<td class='header'><span>PE</span></td>" if (self.stats.PE != None and self.percentStats.PE != None): statVals = statVals + "<td class='" + ghShared.percOfRangeColor( self.percentStats.PE) + "'><span>" + str( self.stats.PE) + "<br />(" + ("%.0f" % float( self.percentStats.PE)) + "%)</span></td>" elif (self.percentStats.PE != None): statVals = statVals + "<td>?</td>" else: statVals = statVals + "<td></td>" if (self.percentStats.OQ != None or formatStyle == 0): statHeads = statHeads + "<td class='header'><span>OQ</span></td>" if (self.stats.OQ != None and self.percentStats.OQ != None): statVals = statVals + "<td class='" + ghShared.percOfRangeColor( self.percentStats.OQ) + "'><span>" + str( self.stats.OQ) + "<br />(" + ("%.0f" % float( self.percentStats.OQ)) + "%)</span></td>" elif (self.percentStats.OQ != None): statVals = statVals + "<td>?</td>" else: statVals = statVals + "<td></td>" if (self.percentStats.SR != None or formatStyle == 0): statHeads = statHeads + "<td class='header'><span>SR</span></td>" if (self.stats.SR != None and self.percentStats.SR != None): statVals = statVals + "<td class='" + ghShared.percOfRangeColor( self.percentStats.SR) + "'><span>" + str( self.stats.SR) + "<br />(" + ("%.0f" % float( self.percentStats.SR)) + "%)</span></td>" elif (self.percentStats.SR != None): statVals = statVals + "<td>?</td>" else: statVals = statVals + "<td></td>" if (self.percentStats.UT != None or formatStyle == 0): statHeads = statHeads + "<td class='header'><span>UT</span></td>" if (self.stats.UT != None and self.percentStats.UT != None): statVals = statVals + "<td class='" + ghShared.percOfRangeColor( self.percentStats.UT) + "'><span>" + str( self.stats.UT) + "<br />(" + ("%.0f" % float( self.percentStats.UT)) + "%)</span></td>" elif (self.percentStats.UT != None): statVals = statVals + "<td>?</td>" else: statVals = statVals + "<td></td>" # construct resource container if self.overallScore != None and self.overallScore > 0: titleStr = ' title="' + str("%.0f" % (float(self.overallScore))) + '"' if formatStyle == 2: result += ' <div id="cont_' + self.spawnName + '" class="boxBorderHidden" style="' + resBoxStyle + '"' + titleStr + ' onmouseover="$(this).removeClass(\'boxBorderHidden\');$(this).addClass(\'listSelected\');" onmouseout="$(this).removeClass(\'listSelected\');$(this).addClass(\'boxBorderHidden\');">' else: result += ' <div id="cont_' + self.spawnName + '" class="resourceBox" style="' + resBoxStyle + '"' + titleStr + '>' if self.overallScore != None and self.overallScore > 0: result += ' <div class="compareInfo"><span>Quality: ' + str( "%.0f" % (float(self.overallScore))) + '</span></div>' # resource title row if formatStyle == 0: result += ' <div style="text-align:left;"><div class="inlineBlock" style="width:55%;text-align:left;float:left;"><span style="font-size: 12px;font-weight: bold;"><a href="' + ghShared.BASE_SCRIPT_URL + 'resource.py/' + str( self.spawnGalaxy ) + '/' + self.spawnName + '" class="nameLink">' + self.spawnName + '</a></span>' elif formatStyle == 2: result += ' <div style="margin-bottom:4px;text-align:left;"><span style="font-size: 12px;"><a href="' + ghShared.BASE_SCRIPT_URL + 'resource.py/' + str( self.spawnGalaxy ) + '/' + self.spawnName + '" class="nameLink">' + self.spawnName + '</a></span>' else: result += ' <div style="margin-bottom:4px;text-align:left;"><span style="font-size: 12px;font-weight: bold;"><a href="' + ghShared.BASE_SCRIPT_URL + 'resource.py/' + str( self.spawnGalaxy ) + '/' + self.spawnName + '" class="nameLink">' + self.spawnName + '</a></span>' if (loggedIn): if formatStyle != 2 and reputation >= ghShared.MIN_REP_VALS[ 'EDIT_RESOURCE_STATS_TYPE']: result += ' <a alt="Edit Stats" style="cursor: pointer;" onclick="editStats(this, \'' + self.spawnName + '\');">[Edit]</a>' if formatStyle != 1 and reputation >= ghShared.MIN_REP_VALS[ 'REMOVE_RESOURCE']: if formatStyle == 2: result += ' <div style="width:100px;float:right;"><input type="checkbox" id="chkRemove_' + self.spawnName + '" />Remove</div>' else: result += ' <a alt="Mark Unavailable" style="cursor: pointer;" onclick="markUnavailable(this, \'' + self.spawnName + '\', ' + str( self.spawnGalaxy) + unPlanetStr + ');"> [X]</a>' # non-stat info if formatStyle == 0: result += ' <span style="color:#000033;"><a href="' + ghShared.BASE_SCRIPT_URL + 'resourceType.py/' + self.resourceType + '" title="View recent spawns of this type" class="nameLink">' + self.resourceTypeName + '</a></span></div>' result += ' <div class="inlineBlock" style="margin-top:2px;margin-right:4px;width:44%;text-align:right;float:right;">' + self.getPlanetBar( ) + '</div>' result += ' </div><div><div style="height:32px;float:left;"><img src="/images/resources/' + self.containerType + '.png"/></div>' elif formatStyle == 1: result += ' ' + ghShared.timeAgo( self.entered ) + ' ago by <a href="user.py?uid=' + self.enteredBy + '" class="nameLink">' + self.enteredBy + '</a>' result += ' </div>' result += ' <div>' result += ' <div style="height:32px;float:left;"><img src="/images/resources/' + self.containerType + '.png" /></div>' result += ' <div style="width:90px;float:left;"><a href="' + ghShared.BASE_SCRIPT_URL + 'resourceType.py/' + self.resourceType + '" title="View schematics and recent spawns of this type" class="nameLink">' + self.resourceTypeName + '</a></div>' else: result += '' # favorite indicator if loggedIn: if self.favorite > 0: result += ' <div class="inlineBlock" style="width:3%;float:left;"><a alt="Favorite" title="Favorite" style="cursor: pointer;" onclick="toggleFavorite(this, 1, \'' + str( self.spawnID) + '\', ' + str( self.spawnGalaxy ) + ');"><img src="/images/favorite16On.png" /></a></div>' else: result += ' <div class="inlineBlock" style="width:3%;float:left;"><a alt="Favorite" title="Favorite" style="cursor: pointer;" onclick="toggleFavorite(this, 1, \'' + str( self.spawnID) + '\', ' + str( self.spawnGalaxy ) + ');"><img src="/images/favorite16Off.png" /></a></div>' # stats information table if formatStyle == 0: result += ' <div style="width:275px;float:left;">' elif formatStyle == 1: result += ' <div style="float:left;">' else: result += '' if formatStyle != 2: result += ' <table class="resAttr"><tr>' + statHeads + '</tr><tr>' + statVals + '</tr>' result += ' </table></div></div>' if formatStyle == 0: # resource update information result += ' <div style="clear:both;">' # add waypoints indicator if self.maxWaypointConc != None: result += '<div style="float:right;"><a href="' + ghShared.BASE_SCRIPT_URL + 'resource.py/' + str( self.spawnGalaxy ) + '/' + self.spawnName + '"><img src="/images/waypointMarker.png" alt="waypoint marker" title="waypoint(s) available (best is ' + str( self.maxWaypointConc) + '%)" width="20" /></a></div>' # entered result += ' <div class="inlineBlock" style="width:33%;float:right;"><img src="/images/circleBlue16.png" alt="Entered" title="Entered" /><span style="vertical-align:4px;">' + ghShared.timeAgo( self.entered ) + ' ago by <a href="/user.py?uid=' + self.enteredBy + '">' + self.enteredBy + '</a></span></div>' # verified result += ' <div class="inlineBlock" style="width:33%;float:right;">' if (self.verified != None): result += ' <img src="/images/checkGreen16.png" alt="Verified" title="Verified" /><span style="vertical-align:4px;">' + ghShared.timeAgo( self.verified ) + ' ago by <a href="/user.py?uid=' + self.verifiedBy + '">' + self.verifiedBy + '</a></span>' else: if (self.unavailable == None and loggedIn and reputation >= ghShared.MIN_REP_VALS['VERIFY_RESOURCE']): result += ' <span id="cont_verify_' + self.spawnName + '"><img src="/images/checkGrey16.png" alt="Not Verified" title="Not Verified" /><span style="vertical-align:4px;"><a alt="Verify Resource" style="cursor: pointer;" onclick="quickAdd(null, \'' + self.spawnName + '\');">[Verify]</a></span></span>' # unavailable result += ' </div><div class="inlineBlock" style="width:32%;float:right;">' if (self.unavailable != None): result += ' <img src="/images/xRed16.png" alt="Unavailable" title="Unavailable" /><span style="vertical-align:4px;">' + ghShared.timeAgo( self.unavailable ) + ' ago by <a href="/user.py?uid=' + self.unavailableBy + '">' + self.unavailableBy + '</a></span>' result += ' </div></div>' else: result += ' <div style="width: 248px;clear:both;margin-left:64px;">' + self.getPlanetBar( ) + '</div>' else: if (self.unavailable == None and loggedIn and reputation >= ghShared.MIN_REP_VALS['VERIFY_RESOURCE'] and ghShared.timeAgo(self.verified).find('minute') == -1): result += ' <div id="cont_verify_' + self.spawnName + '" style="width:100px;float:right;"><input type="checkbox" id="chkVerify_' + self.spawnName + '" />Verify</div>' result += ' </div>' return result
currentUser = sess if (useCookies == 0): linkappend = 'gh_sid=' + sid conn = dbShared.ghConn() cursor = conn.cursor() cursor.execute('SELECT userID, emailAddress, themeName FROM tUsers WHERE userID="' + currentUser + '"') row = cursor.fetchone() if (row != None): email = row[1] uiTheme = row[2] cursor.close() conn.close() else: disableStr = ' disabled="disabled"' if (uiTheme == ''): uiTheme = 'crafter' convertGI = ghShared.convertText(inGameInfo, "js") tmpStat = dbShared.friendStatus(uid, currentUser) joinedStr = 'Joined ' + ghShared.timeAgo(created) + ' ago' pictureName = dbShared.getUserAttr(currentUser, 'pictureName') print 'Content-type: text/html\n' env = Environment(loader=FileSystemLoader('templates')) env.globals['BASE_SCRIPT_URL'] = ghShared.BASE_SCRIPT_URL env.globals['MOBILE_PLATFORM'] = ghShared.getMobilePlatform(os.environ['HTTP_USER_AGENT']) template = env.get_template('user.html') print template.render(uiTheme=uiTheme, loggedin=logged_state, currentUser=currentUser, loginResult=loginResult, linkappend=linkappend, url=url, pictureName=pictureName, imgNum=ghShared.imgNum, galaxyList=ghLists.getGalaxyList(), themeList=ghLists.getThemeList(), uid=uid, convertGI=convertGI, sid=sid, avatarResult=avatarResult, email=email, donorBadge=donorBadge, joinedStr=joinedStr, userPictureName=userPictureName, tmpStat=tmpStat, userTitle=userTitle, friendCountStr=friendCountStr, chart1URL=chart1URL, chart2URL=chart2URL, chart3URL=chart3URL, chart4URL=chart4URL, chart5URL=chart5URL, chart6URL=chart6URL, userAbilities=abilities, resScore=resScore, mapScore=mapScore, reputation=reputation, resColor=resColor, mapColor=mapColor, repColor=repColor, siteAlertCheckStr=siteAlertCheckStr, emailAlertCheckStr=emailAlertCheckStr, mobileAlertCheckStr=mobileAlertCheckStr)
def test_timeAgoDays(self): daysago = datetime.now() - timedelta(4) result = ghShared.timeAgo(daysago) self.assertEqual(result, "4 days")
def getMobileHTML(self, editable): result = '' statHeads = "" statVals = "" titleStr = "" # prepare stat value table contents if (self.stats.ER != None and self.percentStats.ER != None): statVals = statVals + "<span class='"+ghShared.percOfRangeColor(self.percentStats.ER)+"'> ER: " + str(self.stats.ER) + "(" + ("%.0f" % float(self.percentStats.ER)) + "%)</span>" if (self.stats.CR != None and self.percentStats.CR != None): statVals = statVals + "<span class='"+ghShared.percOfRangeColor(self.percentStats.CR)+"'> CR: " + str(self.stats.CR) + "(" + ("%.0f" % float(self.percentStats.CR)) + "%)</span>" if (self.stats.CD != None and self.percentStats.CD != None): statVals = statVals + "<span class='"+ghShared.percOfRangeColor(self.percentStats.CD)+"'> CD: " + str(self.stats.CD) + "(" + ("%.0f" % float(self.percentStats.CD)) + "%)</span>" if (self.stats.DR != None and self.percentStats.DR != None): statVals = statVals + "<span class='"+ghShared.percOfRangeColor(self.percentStats.DR)+"'> DR: " + str(self.stats.DR) + "(" + ("%.0f" % float(self.percentStats.DR)) + "%)</span>" if (self.stats.FL != None and self.percentStats.FL != None): statVals = statVals + "<span class='"+ghShared.percOfRangeColor(self.percentStats.FL)+"'> FL: " + str(self.stats.FL) + "(" + ("%.0f" % float(self.percentStats.FL)) + "%)</span>" if (self.stats.HR != None and self.percentStats.HR != None): statVals = statVals + "<span class='"+ghShared.percOfRangeColor(self.percentStats.HR)+"'> HR: " + str(self.stats.HR) + "(" + ("%.0f" % float(self.percentStats.HR)) + "%)</span>" if (self.stats.MA != None and self.percentStats.MA != None): statVals = statVals + "<span class='"+ghShared.percOfRangeColor(self.percentStats.MA)+"'> MA: " + str(self.stats.MA) + "(" + ("%.0f" % float(self.percentStats.MA)) + "%)</span>" if (self.stats.PE != None and self.percentStats.PE != None): statVals = statVals + "<span class='"+ghShared.percOfRangeColor(self.percentStats.PE)+"'> PE: " + str(self.stats.PE) + "(" + ("%.0f" % float(self.percentStats.PE)) + "%)</span>" if (self.stats.OQ != None and self.percentStats.OQ != None): statVals = statVals + "<span class='"+ghShared.percOfRangeColor(self.percentStats.OQ)+"'> OQ: " + str(self.stats.OQ) + "(" + ("%.0f" % float(self.percentStats.OQ)) + "%)</span>" if (self.stats.SR != None and self.percentStats.SR != None): statVals = statVals + "<span class='"+ghShared.percOfRangeColor(self.percentStats.SR)+"'> SR: " + str(self.stats.SR) + "(" + ("%.0f" % float(self.percentStats.SR)) + "%)</span>" if (self.stats.UT != None and self.percentStats.UT != None): statVals = statVals + "<span class='"+ghShared.percOfRangeColor(self.percentStats.UT)+"'>" + str(self.stats.UT) + "(" + ("%.0f" % float(self.percentStats.UT)) + "%)</span>" # construct resource container if self.overallScore != None and self.overallScore > 0: titleStr = ' title="' + str("%.0f" % (float(self.overallScore))) + '"' result += ' <a href="' + ghShared.BASE_SCRIPT_URL + 'resource.py/'+str(self.spawnGalaxy)+'/'+self.spawnName+'" class="nameLink">' result += ' <div id="cont_'+self.spawnName+'" class="control"' + titleStr + ' style="text-align:left;">' # resource title row result += ' <div style="margin-bottom:4px;">' result += ' '+self.resourceTypeName+' ('+self.spawnName + ')' # non-stat info result += ' entered '+ghShared.timeAgo(self.entered)+' ago by '+self.enteredBy if (editable > 0): result += ' <span title="Mark Unavailable" style="cursor: pointer;float:right;" onclick="markUnavailable(this, \''+self.spawnName+'\', '+str(self.spawnGalaxy)+',\'all\');"> [X]</span>' result += ' </div>' # stats information result += ' <div>' result += statVals result += ' </div></div></a>' return result
def getHTML(self, editable, formatStyle, resBoxMargin): result = '' unPlanetStr = ",'all'" statHeads = "" statVals = "" titleStr = "" # style 0 is wide format if formatStyle == 0: resBoxStyle = "margin-left:" + resBoxMargin + ";min-width:500px;" # style 2 is survey tool format elif formatStyle == 2: resBoxStyle = "padding-left:" + resBoxMargin + ";" else: # other is compact style resBoxStyle = "" # prepare stat value table contents if (self.percentStats.ER != None or formatStyle == 0): statHeads = statHeads + "<td class='header'><span>ER</span></td>" if (self.stats.ER != None and self.percentStats.ER != None): statVals = statVals + "<td class='"+ghShared.percOfRangeColor(self.percentStats.ER)+"'><span>" + str(self.stats.ER) + "<br />(" + ("%.0f" % float(self.percentStats.ER)) + "%)</span></td>" elif (self.percentStats.ER != None): statVals = statVals + "<td>?</td>" else: statVals = statVals + "<td></td>" if (self.percentStats.CR != None or formatStyle == 0): statHeads = statHeads + "<td class='header'><span>CR</span></td>" if (self.stats.CR != None and self.percentStats.CR != None): statVals = statVals + "<td class='"+ghShared.percOfRangeColor(self.percentStats.CR)+"'><span>" + str(self.stats.CR) + "<br />(" + ("%.0f" % float(self.percentStats.CR)) + "%)</span></td>" elif (self.percentStats.CR != None): statVals = statVals + "<td>?</td>" else: statVals = statVals + "<td></td>" if (self.percentStats.CD != None or formatStyle == 0): statHeads = statHeads + "<td class='header'><span>CD</span></td>" if (self.stats.CD != None and self.percentStats.CD != None): statVals = statVals + "<td class='"+ghShared.percOfRangeColor(self.percentStats.CD)+"'><span>" + str(self.stats.CD) + "<br />(" + ("%.0f" % float(self.percentStats.CD)) + "%)</span></td>" elif (self.percentStats.CD != None): statVals = statVals + "<td>?</td>" else: statVals = statVals + "<td></td>" if (self.percentStats.DR != None or formatStyle == 0): statHeads = statHeads + "<td class='header'><span>DR</span></td>" if (self.stats.DR != None and self.percentStats.DR != None): statVals = statVals + "<td class='"+ghShared.percOfRangeColor(self.percentStats.DR)+"'><span>" + str(self.stats.DR) + "<br />(" + ("%.0f" % float(self.percentStats.DR)) + "%)</span></td>" elif (self.percentStats.DR != None): statVals = statVals + "<td>?</td>" else: statVals = statVals + "<td></td>" if (self.percentStats.FL != None or formatStyle == 0): statHeads = statHeads + "<td class='header'><span>FL</span></td>" if (self.stats.FL != None and self.percentStats.FL != None): statVals = statVals + "<td class='"+ghShared.percOfRangeColor(self.percentStats.FL)+"'><span>" + str(self.stats.FL) + "<br />(" + ("%.0f" % float(self.percentStats.FL)) + "%)</span></td>" elif (self.percentStats.FL != None): statVals = statVals + "<td>?</td>" else: statVals = statVals + "<td></td>" if (self.percentStats.HR != None or formatStyle == 0): statHeads = statHeads + "<td class='header'><span>HR</span></td>" if (self.stats.HR != None and self.percentStats.HR != None): statVals = statVals + "<td class='"+ghShared.percOfRangeColor(self.percentStats.HR)+"'><span>" + str(self.stats.HR) + "<br />(" + ("%.0f" % float(self.percentStats.HR)) + "%)</span></td>" elif (self.percentStats.HR != None): statVals = statVals + "<td>?</td>" else: statVals = statVals + "<td></td>" if (self.percentStats.MA != None or formatStyle == 0): statHeads = statHeads + "<td class='header'><span>MA</span></td>" if (self.stats.MA != None and self.percentStats.MA != None): statVals = statVals + "<td class='"+ghShared.percOfRangeColor(self.percentStats.MA)+"'><span>" + str(self.stats.MA) + "<br />(" + ("%.0f" % float(self.percentStats.MA)) + "%)</span></td>" elif (self.percentStats.MA != None): statVals = statVals + "<td>?</td>" else: statVals = statVals + "<td></td>" if (self.percentStats.PE != None or formatStyle == 0): statHeads = statHeads + "<td class='header'><span>PE</span></td>" if (self.stats.PE != None and self.percentStats.PE != None): statVals = statVals + "<td class='"+ghShared.percOfRangeColor(self.percentStats.PE)+"'><span>" + str(self.stats.PE) + "<br />(" + ("%.0f" % float(self.percentStats.PE)) + "%)</span></td>" elif (self.percentStats.PE != None): statVals = statVals + "<td>?</td>" else: statVals = statVals + "<td></td>" if (self.percentStats.OQ != None or formatStyle == 0): statHeads = statHeads + "<td class='header'><span>OQ</span></td>" if (self.stats.OQ != None and self.percentStats.OQ != None): statVals = statVals + "<td class='"+ghShared.percOfRangeColor(self.percentStats.OQ)+"'><span>" + str(self.stats.OQ) + "<br />(" + ("%.0f" % float(self.percentStats.OQ)) + "%)</span></td>" elif (self.percentStats.OQ != None): statVals = statVals + "<td>?</td>" else: statVals = statVals + "<td></td>" if (self.percentStats.SR != None or formatStyle == 0): statHeads = statHeads + "<td class='header'><span>SR</span></td>" if (self.stats.SR != None and self.percentStats.SR != None): statVals = statVals + "<td class='"+ghShared.percOfRangeColor(self.percentStats.SR)+"'><span>" + str(self.stats.SR) + "<br />(" + ("%.0f" % float(self.percentStats.SR)) + "%)</span></td>" elif (self.percentStats.SR != None): statVals = statVals + "<td>?</td>" else: statVals = statVals + "<td></td>" if (self.percentStats.UT != None or formatStyle == 0): statHeads = statHeads + "<td class='header'><span>UT</span></td>" if (self.stats.UT != None and self.percentStats.UT != None): statVals = statVals + "<td class='"+ghShared.percOfRangeColor(self.percentStats.UT)+"'><span>" + str(self.stats.UT) + "<br />(" + ("%.0f" % float(self.percentStats.UT)) + "%)</span></td>" elif (self.percentStats.UT != None): statVals = statVals + "<td>?</td>" else: statVals = statVals + "<td></td>" # construct resource container if self.overallScore != None and self.overallScore > 0: titleStr = ' title="' + str("%.0f" % (float(self.overallScore))) + '"' if formatStyle == 2: result += ' <div id="cont_'+self.spawnName+'" class="boxBorderHidden" style="' + resBoxStyle + '"' + titleStr + ' onmouseover="$(this).removeClass(\'boxBorderHidden\');$(this).addClass(\'listSelected\');" onmouseout="$(this).removeClass(\'listSelected\');$(this).addClass(\'boxBorderHidden\');">' else: result += ' <div id="cont_'+self.spawnName+'" class="resourceBox" style="' + resBoxStyle + '"' + titleStr + '>' if self.overallScore != None and self.overallScore > 0: result += ' <div class="compareInfo"><span>Quality: ' + str("%.0f" % (float(self.overallScore))) + '</span></div>' # resource title row if formatStyle == 0: result += ' <div style="text-align:left;"><div class="inlineBlock" style="width:55%;text-align:left;float:left;"><span style="font-size: 12px;font-weight: bold;"><a href="' + ghShared.BASE_SCRIPT_URL + 'resource.py/'+str(self.spawnGalaxy)+'/'+self.spawnName+'" class="nameLink">'+self.spawnName+'</a></span>' elif formatStyle == 2: result += ' <div style="margin-bottom:4px;text-align:left;"><span style="font-size: 12px;"><a href="' + ghShared.BASE_SCRIPT_URL + 'resource.py/'+str(self.spawnGalaxy)+'/'+self.spawnName+'" class="nameLink">'+self.spawnName+'</a></span>' else: result += ' <div style="margin-bottom:4px;text-align:left;"><span style="font-size: 12px;font-weight: bold;"><a href="' + ghShared.BASE_SCRIPT_URL + 'resource.py/'+str(self.spawnGalaxy)+'/'+self.spawnName+'" class="nameLink">'+self.spawnName+'</a></span>' if (editable > 0): if formatStyle != 2: result += ' <a alt="Edit Stats" style="cursor: pointer;" onclick="editStats(this, \''+self.spawnName+'\');">[Edit]</a>' if formatStyle != 1: if formatStyle == 2: result += ' <div style="width:100px;float:right;"><input type="checkbox" id="chkRemove_' + self.spawnName + '" />Remove</div>' else: result += ' <a alt="Mark Unavailable" style="cursor: pointer;" onclick="markUnavailable(this, \''+self.spawnName+'\', '+str(self.spawnGalaxy)+unPlanetStr+');"> [X]</a>' # non-stat info if formatStyle == 0: result += ' <span style="color:#000033;"><a href="' + ghShared.BASE_SCRIPT_URL + 'resourceType.py/'+self.resourceType+'" title="View recent spawns of this type" class="nameLink">'+self.resourceTypeName+'</a></span></div>' result += ' <div class="inlineBlock" style="margin-top:2px;margin-right:4px;width:44%;text-align:right;float:right;">'+self.getPlanetBar()+'</div>' result += ' </div><div><div style="height:32px;float:left;"><img src="/images/resources/'+self.containerType+'.png"/></div>' elif formatStyle == 1: result += ' '+ghShared.timeAgo(self.entered)+' ago by <a href="user.py?uid='+self.enteredBy+'" class="nameLink">'+self.enteredBy+'</a>' result += ' </div>' result += ' <div>' result += ' <div style="height:32px;float:left;"><img src="/images/resources/'+self.containerType+'.png" /></div>' result += ' <div style="width:90px;float:left;"><a href="' + ghShared.BASE_SCRIPT_URL + 'resourceType.py/'+self.resourceType+'" title="View schematics and recent spawns of this type" class="nameLink">'+self.resourceTypeName+'</a></div>' else: result += '' # favorite indicator if editable > 0: if self.favorite > 0: result += ' <div class="inlineBlock" style="width:3%;float:left;"><a alt="Favorite" title="Favorite" style="cursor: pointer;" onclick="toggleFavorite(this, \''+str(self.spawnID)+'\');"><img src="/images/favorite16On.png" /></a></div>' else: result += ' <div class="inlineBlock" style="width:3%;float:left;"><a alt="Favorite" title="Favorite" style="cursor: pointer;" onclick="toggleFavorite(this, \''+str(self.spawnID)+'\');"><img src="/images/favorite16Off.png" /></a></div>' # stats information table if formatStyle == 0: result += ' <div style="width:275px;float:left;">' elif formatStyle == 1: result += ' <div style="float:left;">' else: result += '' if formatStyle != 2: result += ' <table class="resAttr"><tr>' + statHeads + '</tr><tr>' + statVals + '</tr>' result += ' </table></div></div>' if formatStyle == 0: # resource update information result += ' <div style="clear:both;">' # add waypoints indicator if self.maxWaypointConc != None: result += '<div style="float:right;"><a href="' + ghShared.BASE_SCRIPT_URL + 'resource.py/'+str(self.spawnGalaxy)+'/'+self.spawnName+'"><img src="/images/waypointMarker.png" alt="waypoint marker" title="waypoint(s) available (best is ' + str(self.maxWaypointConc) + '%)" width="20" /></a></div>' # entered result += ' <div class="inlineBlock" style="width:33%;float:right;"><img src="/images/circleBlue16.png" alt="Entered" title="Entered" /><span style="vertical-align:4px;">' + ghShared.timeAgo(self.entered)+' ago by <a href="/user.py?uid='+self.enteredBy+'">'+self.enteredBy+'</a></span></div>' # verified result += ' <div class="inlineBlock" style="width:33%;float:right;">' if (self.verified != None): result += ' <img src="/images/checkGreen16.png" alt="Verified" title="Verified" /><span style="vertical-align:4px;">' + ghShared.timeAgo(self.verified) + ' ago by <a href="/user.py?uid='+self.verifiedBy+'">'+self.verifiedBy+'</a></span>' else: if (self.unavailable == None and editable > 0): result += ' <span id="cont_verify_'+self.spawnName+'"><img src="/images/checkGrey16.png" alt="Not Verified" title="Not Verified" /><span style="vertical-align:4px;"><a alt="Verify Resource" style="cursor: pointer;" onclick="quickAdd(null, \''+self.spawnName+'\');">[Verify]</a></span></span>' # unavailable result += ' </div><div class="inlineBlock" style="width:32%;float:right;">' if (self.unavailable != None): result += ' <img src="/images/xRed16.png" alt="Unavailable" title="Unavailable" /><span style="vertical-align:4px;">' + ghShared.timeAgo(self.unavailable) + ' ago by <a href="/user.py?uid='+self.unavailableBy+'">'+self.unavailableBy+'</a></span>' result += ' </div>' else: result += ' <div style="width: 180px;clear:both;margin-left:64px;">'+self.getPlanetBar()+'</div>' else: if (self.unavailable == None and editable > 0 and ghShared.timeAgo(self.verified).find('minute') == -1): result += ' <div id="cont_verify_'+self.spawnName+'" style="width:100px;float:right;"><input type="checkbox" id="chkVerify_' + self.spawnName + '" />Verify</div>' result += ' </div>' return result
sess = dbSession.getSession(sid, 2592000) if (sess != ''): logged_state = 1 currentUser = sess if (useCookies == 0): linkappend = 'gh_sid=' + sid conn = dbShared.ghConn() cursor = conn.cursor() cursor.execute('SELECT userID, emailAddress, themeName FROM tUsers WHERE userID="' + currentUser + '"') row = cursor.fetchone() if (row != None): email = row[1] uiTheme = row[2] cursor.close() conn.close() else: disableStr = ' disabled="disabled"' if (uiTheme == ''): uiTheme = 'crafter' convertGI = ghShared.convertText(inGameInfo, "js") tmpStat = dbShared.friendStatus(uid, currentUser) joinedStr = 'Joined ' + ghShared.timeAgo(created) + ' ago' pictureName = dbShared.getUserAttr(currentUser, 'pictureName') print 'Content-type: text/html\n' env = Environment(loader=FileSystemLoader('templates')) env.globals['BASE_SCRIPT_URL'] = ghShared.BASE_SCRIPT_URL template = env.get_template('user.html') print template.render(uiTheme=uiTheme, loggedin=logged_state, currentUser=currentUser, loginResult=loginResult, linkappend=linkappend, url=url, pictureName=pictureName, imgNum=ghShared.imgNum, galaxyList=ghLists.getGalaxyList(), themeList=ghLists.getThemeList(), uid=uid, convertGI=convertGI, sid=sid, avatarResult=avatarResult, email=email, donorBadge=donorBadge, joinedStr=joinedStr, userPictureName=userPictureName, tmpStat=tmpStat, userTitle=userTitle, friendCountStr=friendCountStr, chart1URL=ghCharts.getChartURL('bhs', '200x150', 'a', 'creature_resources', 0, 'user', galaxy), chart2URL=ghCharts.getChartURL('bhs', '200x150', 'a', 'inorganic', 0, 'user', galaxy), chart3URL=ghCharts.getChartURL('bhs', '200x150', 'a', 'flora_resources', 0, 'user', galaxy), chart4URL=ghCharts.getChartURL('bhs', '200x150', 'removed', 'all', 0, 'user', galaxy), chart5URL=ghCharts.getChartURL('bhs', '200x150', 'planet', 'all', 0, 'user', galaxy), chart6URL=ghCharts.getChartURL('bhs', '200x150', 'verified', 'all', 0, 'user', galaxy))
tSpawn = doc.createTextNode(spawnID) eSpawn.appendChild(tSpawn) eRoot.appendChild(eSpawn) eOldName = doc.createElement("oldSpawnName") tOldName = doc.createTextNode(row[1]) eOldName.appendChild(tOldName) eRoot.appendChild(eOldName) eType = doc.createElement("resourceType") tType = doc.createTextNode(row[2]) eType.appendChild(tType) eRoot.appendChild(eType) eAge = doc.createElement("resAge") tAge = doc.createTextNode(ghShared.timeAgo(row[3])) eAge.appendChild(tAge) eRoot.appendChild(eAge) result = "found" else: result = "new" cursor.close() conn.close() else: result = "Error: could not connect to database" eText = doc.createElement("resultText") tText = doc.createTextNode(result) eText.appendChild(tText) eRoot.appendChild(eText)
tSpawn = doc.createTextNode(spawnID) eSpawn.appendChild(tSpawn) eRoot.appendChild(eSpawn) eOldName = doc.createElement("oldSpawnName") tOldName = doc.createTextNode(row[1]) eOldName.appendChild(tOldName) eRoot.appendChild(eOldName) eType = doc.createElement("resourceType") tType = doc.createTextNode(row[2]) eType.appendChild(tType) eRoot.appendChild(eType) eAge = doc.createElement("resAge") tAge = doc.createTextNode(ghShared.timeAgo(row[3])) eAge.appendChild(tAge) eRoot.appendChild(eAge) result = "found" else: result = "new" cursor.close() conn.close() else: result = "Error: could not connect to database" eText = doc.createElement("resultText") tText = doc.createTextNode(result) eText.appendChild(tText) eRoot.appendChild(eText)
if (uname == None): result = "no login name sent\n" else: newPass = randomString() crypt_pass = hashlib.sha1(uname + newPass).hexdigest() conn = dbShared.ghConn() cursor = conn.cursor() cursor.execute("SELECT emailAddress, lastReset FROM tUsers WHERE userID='" + uname + "';") row = cursor.fetchone() if row == None: result = "bad username" else: email = row[0] lastReset = row[1] if (lastReset == None or ghShared.timeAgo(lastReset).find("minute") == -1): message = mailer.Message() message.From = "*****@*****.**" message.To = email message.Subject = "Galaxy Harvester password reset" message.Body = "Hello " + uname + ",\n\nYour password for galaxyharvester.net has been reset to:\n\n" + newPass + "\n\n go to http://galaxyharvester.net to login.\n" mailer = mailer.Mailer(mailInfo.MAIL_HOST) mailer.login(mailInfo.MAIL_USER, mailInfo.MAIL_PASS) mailer.send(message) cursor.execute('UPDATE tUsers SET userPassword="******", lastReset=NOW() WHERE userID="' + uname + '";') result = 'email sent' else: result = 'You can only reset your password 1 time per hour.' cursor.close()
cursor = conn.cursor() cursor.execute( "SELECT userID, lastReset FROM tUsers WHERE emailAddress='" + email + "';") row = cursor.fetchone() if row == None: result = "no account with that e-mail" else: uname = row[0] lastReset = row[1] newPass = randomString() crypt_pass = hashlib.sha1(dbInfo.DB_KEY3 + newPass).hexdigest() if (lastReset == None or ghShared.timeAgo(lastReset).find("minute") == -1): message = mailer.Message() message.From = "*****@*****.**" message.To = email message.Subject = "Galaxy Harvester password reset" message.Body = "Hello " + uname + ",\n\nYour password for galaxyharvester.net has been reset to:\n\n" + newPass + "\n\n go to http://galaxyharvester.net to login.\n" mailer = mailer.Mailer(mailInfo.MAIL_HOST) mailer.login(mailInfo.MAIL_USER, mailInfo.MAIL_PASS) mailer.send(message) cursor.execute('UPDATE tUsers SET userPassword="******", lastReset=NOW() WHERE userID="' + uname + '";') result = 'email sent' else: result = 'You can only reset your password 1 time per hour.' cursor.close()
def main(): # Get current url try: url = os.environ['REQUEST_URI'] except KeyError: url = '' uiTheme = '' form = cgi.FieldStorage() # Get Cookies useCookies = 1 cookies = Cookie.SimpleCookie() try: cookies.load(os.environ['HTTP_COOKIE']) except KeyError: useCookies = 0 if useCookies: try: currentUser = cookies['userID'].value except KeyError: currentUser = '' try: loginResult = cookies['loginAttempt'].value except KeyError: loginResult = 'success' try: sid = cookies['gh_sid'].value except KeyError: sid = form.getfirst('gh_sid', '') try: uiTheme = cookies['uiTheme'].value except KeyError: uiTheme = '' try: avatarResult = cookies['avatarAttempt'].value except KeyError: avatarResult = '' try: galaxy = cookies['galaxy'].value except KeyError: galaxy = ghShared.DEFAULT_GALAXY else: currentUser = '' loginResult = form.getfirst('loginAttempt', '') avatarResult = form.getfirst('avatarAttempt', '') sid = form.getfirst('gh_sid', '') galaxy = form.getfirst('galaxy', ghShared.DEFAULT_GALAXY) # escape input to prevent sql injection sid = dbShared.dbInsertSafe(sid) # Get a session logged_state = 0 linkappend = '' disableStr = '' created = datetime.fromtimestamp(time.time()) inGameInfo = '' pictureName = '' userPictureName = '' friendCountStr = '' donateTotal = '' userTitle = '' donorBadge = '' email = '' defaultAlertTypes = 0 sharedInventory = 0 sharedRecipes = 0 siteAlertCheckStr = '' emailAlertCheckStr = '' mobileAlertCheckStr = '' reputation = 0 resScore = 0 mapScore = 0 repColor = 'grey' resColor = 'grey' mapColor = 'grey' abilities = [] if loginResult == None: loginResult = 'success' sess = dbSession.getSession(sid) if (sess != ''): logged_state = 1 currentUser = sess if (useCookies == 0): linkappend = 'gh_sid=' + sid conn = dbShared.ghConn() cursor = conn.cursor() cursor.execute( 'SELECT userID, emailAddress, themeName FROM tUsers WHERE userID="' + currentUser + '"') row = cursor.fetchone() if (row != None): email = row[1] uiTheme = row[2] cursor.close() conn.close() else: disableStr = ' disabled="disabled"' if (uiTheme == ''): uiTheme = 'crafter' path = [] uid = '' template = 'user.html' userPage = 'root' if os.environ.has_key('PATH_INFO'): path = os.environ['PATH_INFO'].split('/')[1:] path = [p for p in path if p != ''] # get user attributes if len(path) > 0: uid = dbShared.dbInsertSafe(path[0]) if len(path) > 1: userPage = path[1] if userPage == 'inventory': template = 'inventory.html' else: created = dbShared.getUserAttr(uid, 'created') inGameInfo = dbShared.getUserAttr(uid, 'inGameInfo') userPictureName = dbShared.getUserAttr(uid, 'pictureName') defaultAlerts = dbShared.getUserAttr(uid, 'defaultAlertTypes') if defaultAlerts > 0: if defaultAlerts % 2 == 1: siteAlertCheckStr = ' checked="checked"' if defaultAlerts >= 4: mobileAlertCheckStr = ' checked="checked"' if defaultAlerts != 1 and defaultAlerts != 4 and defaultAlerts != 5: emailAlertCheckStr = ' checked="checked"' sharedInventory = dbShared.getUserAttr(uid, 'sharedInventory') sharedRecipes = dbShared.getUserAttr(uid, 'sharedRecipes') donateTotal = dbShared.getUserDonated(uid) userTitle = dbShared.getUserTitle(uid) userStats = dbShared.getUserStats(uid, galaxy).split(',') resScore = int(userStats[0]) mapScore = int(userStats[1]) reputation = int(userStats[2]) if resScore != None: if resScore > 2000: resColor = '#ffcc00' elif resScore > 500: resColor = '#3366ff' elif resScore > 25: resColor = '#009933' if mapScore != None: if mapScore > 400: mapColor = '#ffcc00' elif mapScore > 100: mapColor = '#3366ff' elif mapScore > 5: mapColor = '#009933' if reputation != None: if reputation > 100: repColor = '#ffcc00' elif reputation > 50: repColor = '#3366ff' elif reputation > 10: repColor = '#009933' elif reputation < 0: repColor = '#800000' if userPictureName == '': userPictureName = 'default.jpg' if donateTotal != '': donorBadge = '<img src="/images/coinIcon.png" width="16" title="This user has donated to the site" alt="coin" />' # get friend count conn = dbShared.ghConn() cursor = conn.cursor() cursor.execute( 'SELECT Count(uf1.added) FROM tUserFriends uf1 INNER JOIN tUserFriends uf2 ON uf1.friendID=uf2.userID AND uf1.userID=uf2.friendID WHERE uf1.userID="' + uid + '"') row = cursor.fetchone() if (row != None): friendCountStr = '(' + str(row[0]) + ')' cursor.close() conn.close() # Load list of unlocked abilities for k, v in ghShared.ABILITY_DESCR.iteritems(): if reputation >= ghShared.MIN_REP_VALS[ k] and ghShared.MIN_REP_VALS[k] != -99: a = userAbility(k, v, True) a.minReputation = ghShared.MIN_REP_VALS[k] abilities.append(a) convertGI = ghShared.convertText(inGameInfo, "js") tmpStat = dbShared.friendStatus(uid, currentUser) joinedStr = 'Joined ' + ghShared.timeAgo(created) + ' ago' pictureName = dbShared.getUserAttr(currentUser, 'pictureName') print 'Content-type: text/html\n' env = Environment(loader=FileSystemLoader('templates')) env.globals['BASE_SCRIPT_URL'] = ghShared.BASE_SCRIPT_URL env.globals['MOBILE_PLATFORM'] = ghShared.getMobilePlatform( os.environ['HTTP_USER_AGENT']) template = env.get_template(template) if userPage == 'inventory': print template.render( uiTheme=uiTheme, loggedin=logged_state, currentUser=currentUser, loginResult=loginResult, linkappend=linkappend, url=url, pictureName=pictureName, imgNum=ghShared.imgNum, galaxyList=ghLists.getGalaxyList(), professionList=ghLists.getProfessionList(galaxy), resourceGroupList=ghLists.getResourceGroupList(), resourceTypeList=ghLists.getResourceTypeList(galaxy), uid=uid, editable=(uid == currentUser and logged_state == 1)) else: print template.render(uiTheme=uiTheme, loggedin=logged_state, currentUser=currentUser, loginResult=loginResult, linkappend=linkappend, url=url, pictureName=pictureName, imgNum=ghShared.imgNum, galaxyList=ghLists.getGalaxyList(), themeList=ghLists.getThemeList(), uid=uid, convertGI=convertGI, sid=sid, avatarResult=avatarResult, email=email, donorBadge=donorBadge, joinedStr=joinedStr, userPictureName=userPictureName, tmpStat=tmpStat, userTitle=userTitle, friendCountStr=friendCountStr, userAbilities=abilities, resScore=resScore, mapScore=mapScore, reputation=reputation, resColor=resColor, mapColor=mapColor, repColor=repColor, siteAlertCheckStr=siteAlertCheckStr, emailAlertCheckStr=emailAlertCheckStr, mobileAlertCheckStr=mobileAlertCheckStr, sharedInventory=sharedInventory, sharedRecipes=sharedRecipes)
def test_timeAgoMinutes(self): minutesago = datetime.now() - timedelta(0, 2760) result = ghShared.timeAgo(minutesago) self.assertEqual(result, "46 minutes")