コード例 #1
0
ファイル: me.py プロジェクト: nicolasH/meteofranceParser
	def get(self):
		self.response.headers['Content-Type'] = 'text/html'
		userID = users.get_current_user().user_id()
		title="Les prévisions météo de vos villes."
		title="<title>"+title+"</title>"
		self.response.out.write(u"<html><head>"+weather.head+title+"</head><body>")
		self.response.out.write(u'<div class="content"><h1> Vos Pr&eacute;visions:</h1></div>')

		myCities = db.GqlQuery("SELECT * FROM MyCities WHERE userID = :1",userID)

		opener = URLOpener.URLOpener()
			
		for mine in myCities:
			content = memcache.get(mine.cityKey)
			if content is not None:
				self.response.out.write(content)
			else:
				cityUrl = urlFromCityKey(mine.cityKey)
				fullPage = opener.open(url=cityUrl)#(dico["domain"]+dico["suffix"]))
				dico={}
				list=[]
				if mine.cityKey[:2]=="fr":
					dico["domain"] = domainFrance
					dico["suffix"] = suffixFrance + mine.cityKey[3:]
					list = weather.getWeatherContentHTML_france(dico,fullPage.content)
				if mine.cityKey[:2]=="mo":
					dico["domain"] = domainMonde
					dico["suffix"] = suffixMonde + mine.cityKey[3:]
					list = weather.getWeatherContentHTML_monde(dico,fullPage.content)
	
				outText = u''.join(list)
				text = outText.encode("iso-8859-1")
				text2= db.Text(text, encoding="UTF-8")
				memcache.set(mine.cityKey,text2,3600)
				self.response.out.write(text2)
		self.response.out.write(weather.foot)
		self.response.out.write("""<div class="footer">Vous pouvez choisir quelles ville(s) apparaissent sur cette page <a href="/me">sur votre page d'accueil</a></div>""")
		self.response.out.write(main_.extraCredits)
		self.response.out.write(main_.trackingScript)
		self.response.out.write(u'<body></html>')
		return

			
		return
コード例 #2
0
ファイル: me.py プロジェクト: nicolasH/meteofranceParser
	def get(self):
		self.response.headers['Content-Type'] = 'text/html; charset=UTF-8'
		
		city_asked = cgi.escape(self.request.path[7:])
		city_code = cityCodeFromString(city_asked)
		if(len(city_code)==0):
			self.response.out.write("sorry, unrecognized city.")
			return
		#self.response.out.write("city code = "+city_code)
		content = memcache.get(city_code)
		
		regexTitle=re.compile("<h1>([^<]*)</h1>.*")
		
		if(content is not None):
			rez = regexTitle.search(content)
			title = "<title>"+rez.groups()[0]+"</title>"
			self.response.out.write(u"<html><head>"+weather.head+title+"</head><body>")
			self.response.out.write(content)
			self.response.out.write(weather.foot)
                        if users.get_current_user() is not None:
                                self.response.out.write('<div class="nav"><a href="/me">Aller a vos pages</a></div>')
                        else:
                                self.response.out.write('<div class="nav">Vous pouvez <a href="/me">creer un compte</a> et y enregistrer vos villes favorites.</div>')
			self.response.out.write(main_.extraCredits)
			self.response.out.write(main_.trackingScript)
			self.response.out.write(u'<body></html>')
			return

		dico = {}
		
		if city_code[0:3]== "fr_":
			dico["domain"] = domainFrance
			dico["suffix"] = suffixFrance + city_code[3:9]

		if city_code[0:3]== "mo_":
			dico["domain"] = domainMonde
			dico["suffix"] = suffixMonde + city_code[3:8]
		opener = URLOpener.URLOpener()
		fullPage = opener.open(dico["domain"]+dico["suffix"])
		list =[]
		if("PREVISIONS_PORTLET" in dico["suffix"]):
			#France web page layout is very different
			list = weather.getWeatherContentHTML_france(dico,fullPage.content)
		else:
			#Monde web page layout is very different
			list = weather.getWeatherContentHTML_monde(dico,fullPage.content)
		
		outText = u''.join(list)
		text = outText.encode("iso-8859-1")
		text2= db.Text(text, encoding="UTF-8")
		
		rez = regexTitle.search(text2)
		title = "<title>"+rez.groups()[0]+"</title>"
		
		memcache.set(city_code,text2,3600)
		
		self.response.out.write(u"<html><head>"+weather.head+title+"</head><body>")
		self.response.out.write(text2)		
		self.response.out.write(weather.foot)
		if users.get_current_user() is not None:
			self.response.out.write('<div class="nav"><a href="/me">Aller a vos pages</a></div>')
		else:
			self.response.out.write('<div class="nav">Vous pouvez <a href="/me">creer un compte</a> et y enregistrer vos villes favorites.</div>')
		self.response.out.write(main_.extraCredits)
		self.response.out.write(main_.trackingScript)
			
		self.response.out.write(u'<body></html>')
		return