def weather_command(self, args): town = args #ask the temperature from the weather.py module temp = weather.temperature(town) #Reply depending of temperature() output if temp == "Not Found": return "Sorry, I don't know what town you are talking about!" elif temp == "Error": return "It seems like there was an error finding your temperature!" else: return "The current temperature in " + town + " is: " + temp + " C!"
def initScene(): print 'Loading...' # heightmap h = continent(4,5,0.465,8) # penesulas # h = continent(7,7,0.0,8) # mountainous # h = continent(13,13,0.0,8) # good plains # h = continent(24,65,0.0,8) # sahara h *= SCALE summer, winter = temperature(h, 10, 60) precip = precipitation(h, 10, 60) dh = slope(h) r, g, b = vegetation(h, dh, summer, winter, precip) # h[h == 0] = - 0.7 # pylab.figure() # pylab.contour(h,25) # pylab.axis('scaled') # pylab.xlim([0, h.shape[0]-1]) # pylab.ylim([0, h.shape[0]-1]) # pylab.show() # h[h < 0] = 0.0 n = h.shape[0] dh = (numpy.arange(n) / float(n-1) - 0.5) / 2.0 dh = dh ** 2 * n * SCALE for i in xrange(n): h[:,i] -= dh h[i,:] -= dh print 'Finished.' # build OpenGL list gllist = glGenLists(1) glNewList(gllist, GL_COMPILE) for i in xrange(1, n): glBegin(GL_QUAD_STRIP) for j in xrange(n): glColor3f(r[j,i-1], g[j,i-1], b[j,i-1]) glVertex3f((i-1) * SCALE, j * SCALE, h[j,i-1]) glColor3f(r[j,i], g[j,i], b[j,i]) glVertex3f(i * SCALE, j * SCALE, h[j,i]) glEnd() glEndList() glViewport(0, 0, 1200, 800) glShadeModel(GL_SMOOTH) # glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) glEnable(GL_DEPTH_TEST) # atmosphere fog glClearColor(0.22, 0.45, 0.9, 1.0) glFogi(GL_FOG_MODE, GL_EXP) glFogfv(GL_FOG_COLOR, [0.22, 0.45, 0.9, 1.0]) glFogf(GL_FOG_DENSITY, 0.025) glEnable(GL_FOG) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(45.0, 1.5, 0.1, 1000.0) glMatrixMode(GL_MODELVIEW) return gllist, h, dh
def testSanityTwo(self): """Fahrenheit(Celsius(n))==n for all n""" for tempF in range(-459, 10000): tempC = temperature(fahrenheit=tempF).celsius() result = temperature(celsius=tempC).fahrenheit() self.assertAlmostEqual(tempF, result, SIGNIFICANT_PLACES)
def testSanityOne(self): """Celsius(Fahrenheit(n))==n for all n""" for tempC in range(-273, 6000): tempF = temperature(celsius=tempC).fahrenheit() result = temperature(fahrenheit=tempF).celsius() self.assertAlmostEqual(tempC, result, SIGNIFICANT_PLACES)
def testToCelsiusKnownValues(self): """converting from Fahrenheit should give known back our known inputs""" for tempC, tempF in self.knownValues: result = temperature(fahrenheit=tempF).celsius() self.assertAlmostEqual(tempC, result, SIGNIFICANT_PLACES)
def testToFahrenheitKnownValues(self): """converting to Fahrenheit should give known result with known input""" for tempC, tempF in self.knownValues: result = temperature(celsius=tempC).fahrenheit() self.assertAlmostEqual(tempF, result, SIGNIFICANT_PLACES)
from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * from continent import continent, slope from weather import temperature, precipitation from vegetation import vegetation # heightmap h = continent(4,5,0.465,8) # penesulas # h = continent(7,7,0.0,8) # mountainous # h = continent(13,13,0.0,8) # good plains # h = continent(24,65,0.0,8) # sahara h *= 10.0 summer, winter = temperature(h, 10, 60) precip = precipitation(h, 10, 60) dh = slope(h) r, g, b, t = vegetation(h, dh, summer, winter, precip) color = zeros(h.shape + (3,)) color[:,:,0] = r color[:,:,1] = g color[:,:,2] = b pylab.figure() pylab.imshow(color) pylab.axis('scaled') pylab.xlim([0, h.shape[0]-1]) pylab.ylim([0, h.shape[0]-1])
def reply(text, chat_id): temp = weather.temperature(text) bot.sendMessage(chat_id, 'Current weather in {} now is {}'.format(text, temp))